gui/dialogs/editor_settings.cpp

Go to the documentation of this file.
00001 /* $Id: editor_settings.cpp 53594 2012-03-21 08:29:52Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2008 - 2012 by Mark de Wever <koraq@xs4all.nl>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
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 /*WIKI
00037  * @page = GUIWindowDefinitionWML
00038  * @order = 2_editor_settings
00039  *
00040  * == Editor settings ==
00041  *
00042  * This shows the dialog to set the editor settings.
00043  *
00044  * @begin{table}{dialog_widgets}
00045  *
00046  * current_tod & & label & m &
00047  *         Displays the currently selected time of day(ToD) mask. $
00048  *
00049  * current_tod_image & & label & m &
00050  *         The image for the ToD mask. $
00051  *
00052  * next_tod & & button & m &
00053  *         Selects the next ToD mask. $
00054  *
00055  * custom_tod_toggle & & toggle_button & m &
00056  *         Allow to set the ToD mask by selecting the color components
00057  *         manually. $
00058  *
00059  * custom_tod_red & & slider & m &
00060  *         Sets the red component of the custom ToD mask. $
00061  *
00062  * custom_tod_green & & slider & m &
00063  *         Sets the green component of the custom ToD mask. $
00064  *
00065  * custom_tod_blue & & slider & m &
00066  *         Sets the blue component of the custom ToD mask. $
00067  *
00068  * custom_tod_auto_refresh & & toggle_button & m &
00069  *         Directly update the ToD mask when a component slider is moved. $
00070  *
00071  * use_mdi & & boolean & m &
00072  *         Sets whether the user interface should be an MDI interface or not. $
00073  *
00074  * @end{table}
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     // Prevent a floating slice of window appearing alone over the
00131     // theme UI sidebar after redrawing tiles and before we have a
00132     // chance to redraw the rest of this window.
00133     window.undraw();
00134 
00135     if(display_) {
00136         // NOTE: We only really want to re-render the gamemap tiles here.
00137         // Redrawing everything is a significantly more expensive task.
00138         // At this time, tiles are the only elements on which ToD tint is
00139         // meant to have a visible effect. This is very strongly tied to
00140         // the image caching mechanism.
00141         //
00142         // If this ceases to be the case in the future, you'll need to call
00143         // redraw_everything() instead.
00144 
00145         // invalidate all tiles so they are redrawn with the new ToD tint next
00146         display_->invalidate_all();
00147         // redraw tiles
00148         display_->draw();
00149     }
00150 
00151     // Redraw this window again.
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          * @todo Implement the showing of the ToD icon.
00175          *
00176          * Note at the moment the icon is a label widget, should become an
00177          * image widget.
00178          */
00179         //current_tod_image_->set_icon_name(get_selected_tod().image);
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& /*video*/, 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     /* custom tod */
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 } // namespace gui2
00282 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Thu May 24 2012 01:02:42 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs