Author: mordante
Date: Sun Mar 13 08:49:35 2011
New Revision: 48877

URL: http://svn.gna.org/viewcvs/wesnoth?rev=48877&view=rev
Log:
Update tedit_label to use register_xxx.

Modified:
    trunk/src/gui/dialogs/edit_label.cpp
    trunk/src/gui/dialogs/edit_label.hpp
    trunk/src/menu_events.cpp
    trunk/src/tests/gui/test_gui2.cpp

Modified: trunk/src/gui/dialogs/edit_label.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/edit_label.cpp?rev=48877&r1=48876&r2=48877&view=diff
==============================================================================
--- trunk/src/gui/dialogs/edit_label.cpp (original)
+++ trunk/src/gui/dialogs/edit_label.cpp Sun Mar 13 08:49:35 2011
@@ -17,10 +17,7 @@
 
 #include "gui/dialogs/edit_label.hpp"
 
-#include "gui/dialogs/field.hpp"
-#include "gui/widgets/toggle_button.hpp"
 #include "gui/widgets/settings.hpp"
-#include "gui/widgets/window.hpp"
 
 namespace gui2 {
 
@@ -41,37 +38,19 @@
  *         Input field for the map label. $
  *
  * team_only_toggle & & toggle_button & m &
- *         Checkbox for whether to make the label visible to the player's team 
only or not. $
+ *         Checkbox for whether to make the label visible to the player's team
+ *         only or not. $
  *
  * @end{table}
  */
 
 REGISTER_DIALOG(edit_label)
 
-tedit_label::tedit_label(const std::string& label, bool team_only)
-       : team_only_(team_only)
-       , label_(label)
-       , label_field_(register_text("label", false))
+tedit_label::tedit_label(std::string& label, bool& team_only)
 {
-}
-
-void tedit_label::pre_show(CVideo& /*video*/, twindow& window)
-{
-       assert(label_field_);
-
-       find_widget<ttoggle_button>(&window, "team_only_toggle", 
false).set_value(team_only_);
-       label_field_->set_widget_value(window, label_);
-
-       window.keyboard_capture(label_field_->widget(window));
-}
-
-void tedit_label::post_show(twindow& window)
-{
-       if(get_retval() != twindow::OK) {
-               return;
-       }
-
-       label_ = label_field_->get_widget_value(window);
+       register_text2("label", true, label, true);
+       register_bool2("team_only_toggle", true, team_only);
 }
 
 }
+

Modified: trunk/src/gui/dialogs/edit_label.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/edit_label.hpp?rev=48877&r1=48876&r2=48877&view=diff
==============================================================================
--- trunk/src/gui/dialogs/edit_label.hpp (original)
+++ trunk/src/gui/dialogs/edit_label.hpp Sun Mar 13 08:49:35 2011
@@ -17,48 +17,35 @@
 #define GUI_DIALOGS_EDIT_LABEL_HPP_INCLUDED
 
 #include "gui/dialogs/dialog.hpp"
-#include "gui/dialogs/field-fwd.hpp"
-
-#include <vector>
 
 namespace gui2 {
 
 class tedit_label : public tdialog
 {
 public:
-       tedit_label(const std::string& label, bool team_only = true);
+       /**
+        * Constructor.
+        *
+        * @param label [in]          The initial value of the label.
+        * @param label [out]         The label text the user entered if the 
dialog
+        *                            returns @ref twindow::OK undefined 
otherise.
+        * @param team_only [in]      The initial value of the team only toggle.
+        * @param team_only [out]     The final value of the team only toggle 
if the
+        *                            dialog returns @ref twindow::OK undefined
+        *                            otherise.
+        */
+       tedit_label(std::string& label, bool& team_only);
 
-       const std::string& label() const {
-               return label_;
-       }
-
-       void set_label(const std::string& label) {
-               label_ = label;
-       }
-
-       /** Whether only the current team should be able to see the label. */
-       bool team_only() const {
-               return team_only_;
-       }
-
-       void set_team_only(bool team_only) {
-               team_only_ = team_only;
+       /** The excute function see @ref tdialog for more information. */
+       static bool execute(std::string& label, bool& team_only, CVideo& video)
+       {
+               return tedit_label(label, team_only).show(video);
        }
 
 private:
-       bool team_only_;
-       std::string label_;
-
-       tfield_text* label_field_;
 
        /** Inherited from tdialog, implemented by REGISTER_DIALOG. */
        virtual const std::string& window_id() const;
-
-       /** Inherited from tdialog. */
-       void pre_show(CVideo& video, twindow& window);
-
-       /** Inherited from tdialog. */
-       void post_show(twindow& window);
 };
 
 }

Modified: trunk/src/menu_events.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/menu_events.cpp?rev=48877&r1=48876&r2=48877&view=diff
==============================================================================
--- trunk/src/menu_events.cpp (original)
+++ trunk/src/menu_events.cpp Sun Mar 13 08:49:35 2011
@@ -1620,23 +1620,19 @@
 
        const terrain_label* old_label = gui_->labels().get_label(loc);
        std::string label = old_label ? old_label->text() : "";
-       gui2::tedit_label d(label, team_only);
-       d.show(gui_->video());
-
-       if(d.get_retval() != gui2::twindow::CANCEL) {
+
+       if(gui2::tedit_label::execute(label, team_only, gui_->video())) {
                std::string team_name;
                SDL_Color color = font::LABEL_COLOR;
 
-               label = d.label();
-
-               if (d.team_only()) {
+               if (team_only) {
                        team_name = gui_->labels().team_name();
                } else {
                        color = 
int_to_color(team::get_side_rgb(gui_->viewing_side()));
                }
                const std::string& old_team_name = old_label ? 
old_label->team_name() : "";
                // remove the old label if we changed the team_name
-               if (d.team_only() == (old_team_name == "")) {
+               if (team_only == (old_team_name == "")) {
                        const terrain_label* old = 
gui_->labels().set_label(loc, "", old_team_name, color);
                        if (old) recorder.add_label(old);
                }

Modified: trunk/src/tests/gui/test_gui2.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/tests/gui/test_gui2.cpp?rev=48877&r1=48876&r2=48877&view=diff
==============================================================================
--- trunk/src/tests/gui/test_gui2.cpp (original)
+++ trunk/src/tests/gui/test_gui2.cpp Sun Mar 13 08:49:35 2011
@@ -464,7 +464,9 @@
 {
        static gui2::tedit_label* create()
        {
-               return new gui2::tedit_label("Label text to modify", false);
+               static std::string label = "Label text to modify";
+               static bool team_only = false;
+               return new gui2::tedit_label(label, team_only);
        }
 };
 


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

Reply via email to