00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #define GETTEXT_DOMAIN "wesnoth-editor"
00017
00018 #include "gui/dialogs/editor_settings.hpp"
00019
00020 #include "editor/editor_preferences.hpp"
00021 #include "editor/editor_display.hpp"
00022 #include "gui/dialogs/field.hpp"
00023 #include "gui/dialogs/helper.hpp"
00024 #include "gui/widgets/button.hpp"
00025 #include "gui/widgets/label.hpp"
00026 #include "gui/widgets/slider.hpp"
00027 #include "gui/widgets/settings.hpp"
00028 #include "gui/widgets/toggle_button.hpp"
00029 #include "gettext.hpp"
00030 #include "image.hpp"
00031
00032 #include <boost/bind.hpp>
00033
00034 namespace gui2 {
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
00075
00076
00077 REGISTER_DIALOG(editor_settings)
00078
00079 teditor_settings::teditor_settings(editor::editor_display* display
00080 , const std::vector<time_of_day>& tods)
00081 : tods_(tods)
00082 , current_tod_(0)
00083 , current_tod_label_(NULL)
00084 , current_tod_image_(NULL)
00085 , custom_tod_toggle_(NULL)
00086 , custom_tod_auto_refresh_(NULL)
00087 , custom_tod_toggle_field_(register_bool("custom_tod_toggle", true))
00088 , custom_tod_red_field_(register_integer("custom_tod_red"
00089 , true
00090 , &preferences::editor::tod_r
00091 , &preferences::editor::set_tod_r))
00092 , custom_tod_green_field_(register_integer("custom_tod_green"
00093 , true
00094 , &preferences::editor::tod_g
00095 , &preferences::editor::set_tod_g))
00096 , custom_tod_blue_field_(register_integer("custom_tod_blue"
00097 , true
00098 , &preferences::editor::tod_b
00099 , &preferences::editor::set_tod_b))
00100 , display_(display)
00101 , can_update_display_(false)
00102 {
00103 register_bool("use_mdi"
00104 , true
00105 , &preferences::editor::use_mdi
00106 , &preferences::editor::set_use_mdi);
00107 }
00108
00109 void teditor_settings::do_next_tod(twindow& window)
00110 {
00111 current_tod_++;
00112 current_tod_ %= tods_.size();
00113 custom_tod_toggle_->set_value(false);
00114 update_selected_tod_info(window);
00115 }
00116
00117 const time_of_day& teditor_settings::get_selected_tod() const
00118 {
00119 assert(static_cast<size_t>(current_tod_) < tods_.size());
00120 return tods_[current_tod_];
00121 }
00122
00123 void teditor_settings::update_tod_display(twindow& window)
00124 {
00125 image::set_color_adjustment(
00126 custom_tod_red_field_->get_widget_value(window)
00127 , custom_tod_green_field_->get_widget_value(window)
00128 , custom_tod_blue_field_->get_widget_value(window));
00129
00130
00131
00132
00133 window.undraw();
00134
00135 if(display_) {
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 display_->invalidate_all();
00147
00148 display_->draw();
00149 }
00150
00151
00152 window.set_dirty(true);
00153 }
00154
00155 void teditor_settings::slider_update_callback(twindow& window)
00156 {
00157 if (custom_tod_auto_refresh_->get_value()) {
00158 update_tod_display(window);
00159 }
00160 }
00161
00162 void teditor_settings::update_selected_tod_info(twindow& window)
00163 {
00164 bool custom = custom_tod_toggle_->get_value();
00165 if (custom) {
00166 current_tod_label_->set_label(_("Custom setting"));
00167 } else {
00168 std::stringstream ss;
00169 ss << (current_tod_ + 1);
00170 ss << "/" << tods_.size();
00171 ss << ": " << get_selected_tod().name;
00172 current_tod_label_->set_label(ss.str());
00173
00174
00175
00176
00177
00178
00179
00180 custom_tod_red_field_->set_widget_value(
00181 window
00182 , get_selected_tod().color.r);
00183 custom_tod_green_field_->set_widget_value(
00184 window
00185 , get_selected_tod().color.g);
00186 custom_tod_blue_field_->set_widget_value(
00187 window
00188 , get_selected_tod().color.b);
00189 }
00190 custom_tod_red_field_->widget()->set_active(custom);
00191 custom_tod_green_field_->widget()->set_active(custom);
00192 custom_tod_blue_field_->widget()->set_active(custom);
00193 current_tod_label_->set_active(!custom);
00194
00195 if(can_update_display_) {
00196 update_tod_display(window);
00197 window.invalidate_layout();
00198 }
00199 }
00200
00201 void teditor_settings::pre_show(CVideo& , twindow& window)
00202 {
00203 assert(!tods_.empty());
00204 current_tod_label_ = find_widget<tlabel>(
00205 &window, "current_tod", false, true);
00206 current_tod_image_ = find_widget<tlabel>(
00207 &window, "current_tod_image", false, true);
00208 custom_tod_toggle_ = find_widget<ttoggle_button>(
00209 &window, "custom_tod_toggle", false, true);
00210 custom_tod_auto_refresh_ = find_widget<ttoggle_button>(
00211 &window, "custom_tod_auto_refresh", false, true);
00212
00213 tbutton& next_tod_button = find_widget<tbutton>(
00214 &window, "next_tod", false);
00215 connect_signal_mouse_left_click(next_tod_button, boost::bind(
00216 &teditor_settings::do_next_tod
00217 , this
00218 , boost::ref(window)));
00219
00220
00221 tbutton& apply_button = find_widget<tbutton>(
00222 &window, "apply", false);
00223 connect_signal_mouse_left_click(apply_button, boost::bind(
00224 &teditor_settings::update_tod_display
00225 , this
00226 , boost::ref(window)));
00227
00228 custom_tod_toggle_->set_callback_state_change(
00229 dialog_callback<teditor_settings
00230 , &teditor_settings::update_selected_tod_info>);
00231
00232 connect_signal_notify_modified(*(custom_tod_red_field_->widget())
00233 , boost::bind(
00234 &teditor_settings::slider_update_callback
00235 , this
00236 , boost::ref(window)));
00237
00238 connect_signal_notify_modified(*(custom_tod_green_field_->widget())
00239 , boost::bind(
00240 &teditor_settings::slider_update_callback
00241 , this
00242 , boost::ref(window)));
00243
00244 connect_signal_notify_modified(*(custom_tod_blue_field_->widget())
00245 , boost::bind(
00246 &teditor_settings::slider_update_callback
00247 , this
00248 , boost::ref(window)));
00249
00250 for (size_t i = 0; i < tods_.size(); ++i) {
00251
00252 time_of_day& tod = tods_[i];
00253 const int r = custom_tod_red_field_->get_widget_value(window);
00254 const int g = custom_tod_green_field_->get_widget_value(window);
00255 const int b = custom_tod_blue_field_->get_widget_value(window);
00256 if (tod.color.r == r && tod.color.g == g && tod.color.b == b) {
00257 current_tod_ = i;
00258 custom_tod_toggle_->set_value(false);
00259 update_selected_tod_info(window);
00260 can_update_display_ = true;
00261 return;
00262 }
00263 }
00264
00265
00266 custom_tod_toggle_->set_value(true);
00267
00268 update_selected_tod_info(window);
00269
00270 can_update_display_ = true;
00271 }
00272
00273 void teditor_settings::post_show(twindow& window)
00274 {
00275 update_tod_display(window);
00276
00277 can_update_display_ = false;
00278 }
00279
00280
00281 }
00282