Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #define GETTEXT_DOMAIN "wesnoth-lib"
00017
00018 #include "gui/dialogs/debug_clock.hpp"
00019
00020 #include "gui/dialogs/dialog.hpp"
00021 #include "gui/widgets/integer_selector.hpp"
00022 #include "gui/widgets/window.hpp"
00023 #include "gui/widgets/settings.hpp"
00024 #include "gui/widgets/progress_bar.hpp"
00025
00026 #include <boost/bind.hpp>
00027
00028 #include <ctime>
00029
00030 namespace gui2 {
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 REGISTER_DIALOG(debug_clock)
00075
00076 void tdebug_clock::pre_show(CVideo& , twindow& window)
00077 {
00078 hour_percentage_ = find_widget<tprogress_bar>(
00079 &window
00080 , "hour_percentage"
00081 , false
00082 , false);
00083 minute_percentage_ = find_widget<tprogress_bar>(
00084 &window
00085 , "minute_percentage"
00086 , false
00087 , false);
00088 second_percentage_ = find_widget<tprogress_bar>(
00089 &window
00090 , "second_percentage"
00091 , false
00092 , false);
00093
00094 hour_ = find_widget<tinteger_selector_>(&window, "hour", false, false);
00095 if(hour_) {
00096 dynamic_cast<tcontrol*>(hour_)->set_active(false);
00097 }
00098 minute_ = find_widget<tinteger_selector_>(&window, "minute", false, false);
00099 if(minute_) {
00100 dynamic_cast<tcontrol*>(minute_)->set_active(false);
00101 }
00102 second_ = find_widget<tinteger_selector_>(&window, "second", false, false);
00103 if(second_) {
00104 dynamic_cast<tcontrol*>(second_)->set_active(false);
00105 }
00106
00107 clock_ = find_widget<tcontrol>(&window, "clock", false, false);
00108
00109 window_ = &window;
00110
00111 signal_ = boost::bind(&tdebug_clock::update_time, this, false);
00112 window.connect_signal<event::DRAW>(
00113 signal_
00114 , event::tdispatcher::front_child);
00115
00116 time_.set_current_time();
00117 update_time(true);
00118 }
00119
00120 void tdebug_clock::post_show(CVideo& )
00121 {
00122 window_->disconnect_signal<event::DRAW>(signal_);
00123 }
00124
00125 void tdebug_clock::update_time(const bool force)
00126 {
00127 if(!time_.step() && !force) {
00128 return;
00129 }
00130
00131 if(hour_percentage_) {
00132 hour_percentage_->set_percentage(time_.hour / 0.24);
00133 }
00134 if(minute_percentage_) {
00135 minute_percentage_->set_percentage(time_.minute / 0.60);
00136 }
00137 if(second_percentage_) {
00138 second_percentage_->set_percentage(time_.second / 0.60);
00139 }
00140
00141 const int hour_stamp = time_.hour * 3600 + time_.minute * 60 + time_.second;
00142 const int minute_stamp = time_.minute * 60 + time_.second;
00143 const int second_stamp = time_.second;
00144
00145 if(hour_) {
00146 hour_->set_value(hour_stamp);
00147 }
00148 if(minute_) {
00149 minute_->set_value(minute_stamp);
00150 }
00151 if(second_) {
00152 second_->set_value(second_stamp);
00153 }
00154
00155 if(clock_) {
00156 foreach(tcanvas& canvas, clock_->canvas()) {
00157 canvas.set_variable("hour", variant(hour_stamp));
00158 canvas.set_variable("minute", variant(minute_stamp));
00159 canvas.set_variable("second", variant(second_stamp));
00160 }
00161 clock_->set_dirty();
00162 }
00163 }
00164
00165 tdebug_clock::ttime::ttime()
00166 : hour(0)
00167 , minute(0)
00168 , second(0)
00169 , millisecond(0)
00170 {
00171 }
00172
00173 void tdebug_clock::ttime::set_current_time()
00174 {
00175 time_t now = time(NULL);
00176 tm *stamp = localtime(&now);
00177
00178 hour = stamp->tm_hour;
00179 minute = stamp->tm_min;
00180 second = stamp->tm_sec;
00181 millisecond = 0;
00182 }
00183
00184 bool tdebug_clock::ttime::step(const unsigned milliseconds)
00185 {
00186 millisecond += milliseconds;
00187
00188 if(millisecond < 1000) return false;
00189
00190 millisecond -= 1000;
00191 ++second;
00192
00193 if(second < 60) return true;
00194
00195 second -= 60;
00196 ++minute;
00197
00198 if(minute < 60) return true;
00199
00200 minute -= 60;
00201 ++hour;
00202
00203 if(hour < 24) return true;
00204
00205 hour -= 24;
00206
00207 return true;
00208 }
00209
00210 }
00211