Author: mordante
Date: Sat Mar 19 22:04:11 2011
New Revision: 48938

URL: http://svn.gna.org/viewcvs/wesnoth?rev=48938&view=rev
Log:
Polish teditor_resize_map.

- Updated comment.
- Use new register functions.

Modified:
    trunk/src/editor/editor_controller.cpp
    trunk/src/gui/dialogs/editor_resize_map.cpp
    trunk/src/gui/dialogs/editor_resize_map.hpp
    trunk/src/tests/gui/test_gui2.cpp

Modified: trunk/src/editor/editor_controller.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor/editor_controller.cpp?rev=48938&r1=48937&r2=48938&view=diff
==============================================================================
--- trunk/src/editor/editor_controller.cpp (original)
+++ trunk/src/editor/editor_controller.cpp Sat Mar 19 22:04:11 2011
@@ -560,25 +560,20 @@
 
 void editor_controller::resize_map_dialog()
 {
-       gui2::teditor_resize_map dialog;
-       dialog.set_map_width(get_map().w());
-       dialog.set_map_height(get_map().h());
-       dialog.set_old_map_width(get_map().w());
-       dialog.set_old_map_height(get_map().h());
-
-       dialog.show(gui().video());
-       int res = dialog.get_retval();
-       if(res == gui2::twindow::OK) {
-               int w = dialog.map_width();
-               int h = dialog.map_height();
+       int w = get_map().w();
+       int h = get_map().h();
+       gui2::teditor_resize_map::EXPAND_DIRECTION dir;
+       bool copy = false;
+       if(gui2::teditor_resize_map::execute(w, h, dir, copy, gui().video())) {
+
                if (w != get_map().w() || h != get_map().h()) {
                        t_translation::t_terrain fill = background_terrain_;
-                       if (dialog.copy_edge_terrain()) {
+                       if (copy) {
                                fill = t_translation::NONE_TERRAIN;
                        }
                        int x_offset = get_map().w() - w;
                        int y_offset = get_map().h() - h;
-                       switch (dialog.expand_direction()) {
+                       switch (dir) {
                                case 
gui2::teditor_resize_map::EXPAND_BOTTOM_RIGHT:
                                case gui2::teditor_resize_map::EXPAND_BOTTOM:
                                case 
gui2::teditor_resize_map::EXPAND_BOTTOM_LEFT:
@@ -597,7 +592,7 @@
                                        y_offset = 0;
                                        WRN_ED << "Unknown resize expand 
direction\n";
                        }
-                       switch (dialog.expand_direction()) {
+                       switch (dir) {
                                case 
gui2::teditor_resize_map::EXPAND_BOTTOM_RIGHT:
                                case gui2::teditor_resize_map::EXPAND_RIGHT:
                                case gui2::teditor_resize_map::EXPAND_TOP_RIGHT:

Modified: trunk/src/gui/dialogs/editor_resize_map.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/editor_resize_map.cpp?rev=48938&r1=48937&r2=48938&view=diff
==============================================================================
--- trunk/src/gui/dialogs/editor_resize_map.cpp (original)
+++ trunk/src/gui/dialogs/editor_resize_map.cpp Sat Mar 19 22:04:11 2011
@@ -18,7 +18,6 @@
 
 #include "gui/dialogs/field.hpp"
 #include "gui/dialogs/helper.hpp"
-#include "gui/widgets/label.hpp"
 #include "gui/widgets/toggle_button.hpp"
 #include "gui/widgets/settings.hpp"
 #include "gui/widgets/slider.hpp"
@@ -37,10 +36,10 @@
  *
  * @begin{table}{dialog_widgets}
  *
- * old_width & & label & m &
+ * old_width & & label & o &
  *         Shows the old width of the map. $
  *
- * old_height & & label & m &
+ * old_height & & label & o &
  *         Shows the old height of the map. $
  *
  * width & & slider & m &
@@ -89,78 +88,38 @@
 
 REGISTER_DIALOG(editor_resize_map)
 
-/**
- * @todo Test whether the slider can be changed to an interger selector.
- * Should be possible, since it's also done in the new map dialog.
- */
-teditor_resize_map::teditor_resize_map() :
-       map_width_(register_integer("width", false)),
-       map_height_(register_integer("height", false)),
-       height_(NULL),
-       width_(NULL),
-       copy_edge_terrain_(register_bool("copy_edge_terrain", false)),
-       old_width_(),
-       old_height_(),
-       expand_direction_(EXPAND_BOTTOM_RIGHT)
-{
-}
-
-void teditor_resize_map::set_map_width(int value)
-{
-       map_width_->set_cache_value(value);
-}
-
-int teditor_resize_map::map_width() const
-{
-       return map_width_->get_cache_value();
-}
-
-void teditor_resize_map::set_map_height(int value)
-{
-       map_height_->set_cache_value(value);
-}
-
-int teditor_resize_map::map_height() const
-{
-       return map_height_->get_cache_value();
-}
-
-void teditor_resize_map::set_old_map_width(int value)
-{
-       old_width_ = value;
-}
-
-void teditor_resize_map::set_old_map_height(int value)
-{
-       old_height_ = value;
-}
-
-bool teditor_resize_map::copy_edge_terrain() const
-{
-       return copy_edge_terrain_->get_cache_value();
+teditor_resize_map::teditor_resize_map(
+                         int& width
+                       , int& height
+                       , EXPAND_DIRECTION& expand_direction
+                       , bool& copy_edge_terrain)
+       : width_(register_integer("width", false, width))
+       , height_(register_integer("height", false, height))
+       , old_width_(width)
+       , old_height_(height)
+       , expand_direction_(expand_direction)
+{
+       register_bool("copy_edge_terrain", true, copy_edge_terrain);
+
+       register_label2("old_width", false, str_cast(width));
+       register_label2("old_height", false, str_cast(height));
 }
 
 void teditor_resize_map::pre_show(CVideo& /*video*/, twindow& window)
 {
-       tlabel& old_width = find_widget<tlabel>(&window, "old_width", false);
-       tlabel& old_height = find_widget<tlabel>(&window, "old_height", false);
-       height_ = find_widget<tslider>(&window, "height", false, true);
-       width_ = find_widget<tslider>(&window, "width", false, true);
-
-       connect_signal_notify_modified(*height_
+       tslider& height = find_widget<tslider>(&window, "height", false);
+       connect_signal_notify_modified(height
                        , boost::bind(
                                  &teditor_resize_map::update_expand_direction
                                , this
                                , boost::ref(window)));
 
-       connect_signal_notify_modified(*width_
+       tslider& width = find_widget<tslider>(&window, "width", false);
+       connect_signal_notify_modified(width
                        , boost::bind(
                                  &teditor_resize_map::update_expand_direction
                                , this
                                , boost::ref(window)));
-
-       old_width.set_label(lexical_cast<std::string>(old_width_));
-       old_height.set_label(lexical_cast<std::string>(old_height_));
 
        std::string name_prefix = "expand";
        for (int i = 0; i < 9; ++i) {
@@ -176,8 +135,11 @@
        update_expand_direction(window);
 }
 
-/** Convert a coordinate on a 3  by 3 grid to an index, return 9 for out of 
bounds */
-static int resize_grid_xy_to_idx(int x, int y)
+/**
+ * Convert a coordinate on a 3  by 3 grid to an index, return 9 for out of
+ * bounds
+ */
+static int resize_grid_xy_to_idx(const int x, const int y)
 {
        if (x < 0 || x > 2 || y < 0 || y > 2) {
                return 9;
@@ -189,7 +151,8 @@
 void teditor_resize_map::set_direction_icon(int index, std::string icon)
 {
        if (index < 9) {
-               
direction_buttons_[index]->set_icon_name("buttons/resize-direction-" + icon + 
".png");
+               direction_buttons_[index]->set_icon_name(
+                               "buttons/resize-direction-" + icon + ".png");
        }
 }
 
@@ -197,7 +160,9 @@
 {
        std::string name_prefix = "expand";
        for (int i = 0; i < 9; ++i) {
-               if (direction_buttons_[i]->get_value() && 
static_cast<int>(expand_direction_) != i) {
+               if (direction_buttons_[i]->get_value()
+                                       && static_cast<int>(expand_direction_) 
!= i) {
+
                        expand_direction_ = static_cast<EXPAND_DIRECTION>(i);
                        break;
                }
@@ -212,8 +177,8 @@
                set_direction_icon(i, "none");
        }
 
-       int xdiff = map_width_->get_widget_value(window) - old_width_ ;
-       int ydiff = map_height_->get_widget_value(window) - old_height_ ;
+       int xdiff = width_->get_widget_value(window) - old_width_ ;
+       int ydiff = height_->get_widget_value(window) - old_height_ ;
        int x = static_cast<int>(expand_direction_) % 3;
        int y = static_cast<int>(expand_direction_) / 3;
        set_direction_icon(expand_direction_, "center");

Modified: trunk/src/gui/dialogs/editor_resize_map.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/editor_resize_map.hpp?rev=48938&r1=48937&r2=48938&view=diff
==============================================================================
--- trunk/src/gui/dialogs/editor_resize_map.hpp (original)
+++ trunk/src/gui/dialogs/editor_resize_map.hpp Sat Mar 19 22:04:11 2011
@@ -16,30 +16,15 @@
 #ifndef GUI_DIALOGS_EDITOR_RESIZE_MAP_HPP_INCLUDED
 #define GUI_DIALOGS_EDITOR_RESIZE_MAP_HPP_INCLUDED
 
-#include "gui/auxiliary/notifier.hpp"
-#include "gui/auxiliary/notifiee.hpp"
 #include "gui/dialogs/dialog.hpp"
-
-#include <boost/function.hpp>
 
 namespace gui2 {
 
 class ttoggle_button;
-class tslider;
 
 class teditor_resize_map : public tdialog
 {
 public:
-       teditor_resize_map();
-
-       void set_map_width(int value);
-       int map_width() const;
-       void set_map_height(int value);
-       int map_height() const;
-       void set_old_map_width(int value);
-       void set_old_map_height(int value);
-       bool copy_edge_terrain() const;
-
        enum EXPAND_DIRECTION {
                EXPAND_BOTTOM_RIGHT,
                EXPAND_BOTTOM,
@@ -51,32 +36,85 @@
                EXPAND_TOP,
                EXPAND_TOP_LEFT
        };
-       EXPAND_DIRECTION expand_direction() { return expand_direction_; }
-       void set_expand_direction(EXPAND_DIRECTION direction) { 
expand_direction_ = direction; }
+
+       /**
+        * Constructor.
+        *
+        * @param width [in]          The initial width of the map.
+        * @param width [out]         The selected width of the map if the 
dialog
+        *                            returns @ref twindow::OK undefined 
otherwise.
+        *
+        * @param height [in]         The initial height of the map.
+        * @param height [out]        The selected height of the map if the 
dialog
+        *                            returns @ref twindow::OK undefined 
otherwise.
+        *
+        * @param expand_direction [out]
+        *                            The selected expand direction if the 
dialog
+        *                            returns  @ref twindow::OK undefined
+        *                            otherwise.
+        *
+        * @param copy_edge_terrain [in]
+        *                            The initial value of the copy edge toggle.
+        * @param copy_edge_terrain [out]
+        *                            The final value of the copy edge toggle if
+        *                            the dialog returns  @ref twindow::OK
+        *                            undefined otherwise.
+        */
+       teditor_resize_map(
+                         int& width
+                       , int& height
+                       , EXPAND_DIRECTION& expand_direction
+                       , bool& copy_edge_terrain);
+
+       /** The excute function see @ref tdialog for more information. */
+       static bool execute(
+                         int& width
+                       , int& height
+                       , EXPAND_DIRECTION& expand_direction
+                       , bool& copy_edge_terrain
+                       , CVideo& video)
+       {
+               return teditor_resize_map(
+                                 width
+                               , height
+                               , expand_direction
+                               , copy_edge_terrain).show(video);
+       }
+
+private:
+
+       /** The currently selected width. */
+       tfield_integer* width_;
+
+       /** The currently selected height. */
+       tfield_integer* height_;
+
+       /** The original width. */
+       int old_width_;
+
+       /** The original height. */
+       int old_height_;
+
+       /** The selected expansion direction. */
+       EXPAND_DIRECTION& expand_direction_;
+
+       /**
+        * The toggle buttons show the state of expand_direction_.
+        *
+        * Allows both so select a direction and visually show the effect of the
+        * selection.
+        */
+       ttoggle_button* direction_buttons_[9];
 
        void update_expand_direction(twindow& window);
 
-private:
        void set_direction_icon(int index, std::string icon);
-       /**
-        * NOTE the map sizes are stored in a text variable since there is no
-        * integer edit widget yet.
-        */
-       tfield_integer* map_width_;
-       tfield_integer* map_height_;
-       tslider* height_;
-       tslider* width_;
-       tfield_bool* copy_edge_terrain_;
-       ttoggle_button* direction_buttons_[9];
-       int old_width_;
-       int old_height_;
 
-       EXPAND_DIRECTION expand_direction_;
+       /** Inherited from tdialog */
+       void pre_show(CVideo& video, twindow& window);
 
        /** Inherited from tdialog, implemented by REGISTER_DIALOG. */
        virtual const std::string& window_id() const;
-
-       void pre_show(CVideo& video, twindow& window);
 };
 
 } // namespace gui2

Modified: trunk/src/tests/gui/test_gui2.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/tests/gui/test_gui2.cpp?rev=48938&r1=48937&r2=48938&view=diff
==============================================================================
--- trunk/src/tests/gui/test_gui2.cpp (original)
+++ trunk/src/tests/gui/test_gui2.cpp Sat Mar 19 22:04:11 2011
@@ -645,6 +645,24 @@
 };
 
 template<>
+struct twrapper<gui2::teditor_resize_map>
+{
+       static gui2::teditor_resize_map* create()
+       {
+               static int width = 0;
+               static int height = 0;
+               static gui2::teditor_resize_map::EXPAND_DIRECTION 
expand_direction =
+                               gui2::teditor_resize_map::EXPAND_TOP;
+               static bool copy = false;
+               return new gui2::teditor_resize_map(
+                                 width
+                               , height
+                               , expand_direction
+                               , copy);
+       }
+};
+
+template<>
 struct twrapper<gui2::teditor_settings>
 {
        static void dummy_callback(int, int, int) {}


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to