Author: sapient
Date: Sun Apr 15 04:10:41 2007
New Revision: 16849

URL: http://svn.gna.org/viewcvs/wesnoth?rev=16849&view=rev
Log:
get rid of the old widget.align hack and provide a utility method 
dialog::add_option()

Modified:
    trunk/src/construct_dialog.cpp
    trunk/src/construct_dialog.hpp
    trunk/src/menu_events.cpp
    trunk/src/show_dialog.cpp
    trunk/src/show_dialog.hpp
    trunk/src/upload_log.cpp
    trunk/src/widgets/widget.cpp
    trunk/src/widgets/widget.hpp

Modified: trunk/src/construct_dialog.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/construct_dialog.cpp?rev=16849&r1=16848&r2=16849&view=diff
==============================================================================
--- trunk/src/construct_dialog.cpp (original)
+++ trunk/src/construct_dialog.cpp Sun Apr 15 04:10:41 2007
@@ -214,6 +214,12 @@
        add_button(btn, loc);
 }
 
+void dialog::add_option(const std::string& label, bool checked, 
BUTTON_LOCATION loc)
+{
+       gui::dialog_button *btn = new dialog_button(disp_.video(), label, 
button::TYPE_CHECK);
+       btn->set_check(checked);
+       add_button(btn, loc);
+}
 
 void dialog::set_textbox(const std::string& text_widget_label,
                                const std::string& text_widget_text,

Modified: trunk/src/construct_dialog.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/construct_dialog.hpp?rev=16849&r1=16848&r2=16849&view=diff
==============================================================================
--- trunk/src/construct_dialog.hpp (original)
+++ trunk/src/construct_dialog.hpp Sun Apr 15 04:10:41 2007
@@ -183,6 +183,7 @@
                                const unsigned int text_box_width = 
font::relative_size(350));
        void add_button(dialog_button *const btn, BUTTON_LOCATION loc);
        void add_button(dialog_button_info btn_info, BUTTON_LOCATION 
loc=BUTTON_EXTRA);
+       void add_option(const std::string& label, bool checked=false, 
BUTTON_LOCATION loc=BUTTON_CHECKBOX);
 
        //Specific preparations
        //layout - determines dialog measurements based on all components

Modified: trunk/src/menu_events.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/menu_events.cpp?rev=16849&r1=16848&r2=16849&view=diff
==============================================================================
--- trunk/src/menu_events.cpp (original)
+++ trunk/src/menu_events.cpp Sun Apr 15 04:10:41 2007
@@ -1344,48 +1344,30 @@
                if(map_.on_board(mousehandler.get_last_hex()) == false) {
                        return;
                }
+               gui::dialog d(*gui_, _("Place Label"), "", gui::OK_CANCEL);
                const terrain_label* old_label = 
gui_->labels().get_label(mousehandler.get_last_hex());
-
-               std::string label;
-
-               if (old_label)
-               {
-                       label = old_label->text();
+               if (old_label) {
+                       d.set_textbox(_("Label:"), old_label->text(), 
map_labels::get_max_chars());
                        team_only = !old_label->team_name().empty();
-               }
-
-               std::vector<gui::check_item> options;
-               if (has_team() || (old_label && team_only))
-               {
-                       gui::check_item team_only_chk = gui::check_item(_("Team 
only"),
-                                       team_only);
-                       team_only_chk.align = gui::LEFT_ALIGN;
-                       options.push_back(team_only_chk);
-               }
-               const int res = gui::show_dialog(*gui_,NULL,_("Place 
Label"),"",gui::OK_CANCEL,
-                                                                               
 NULL,NULL,_("Label:"),&label,
-                                                map_labels::get_max_chars(), 
NULL, &options);
-               if(res == 0) {
+               } else {
+                       d.set_textbox(_("Label:"), "", 
map_labels::get_max_chars());
+               }
+               if (has_team() || (old_label && team_only)) {
+                       d.add_option(_("Team only"), team_only, 
gui::dialog::BUTTON_CHECKBOX_LEFT);
+               }
+               if(!d.show()) {
                        std::string team_name;
                        SDL_Color colour = font::LABEL_COLOUR;
                        const std::string last_team_id = "9";
                        std::map<std::string, color_range>::iterator gp = 
game_config::team_rgb_range.find(last_team_id);
 
-
-
-
-                       if ((has_team() || (old_label && team_only)) && 
options.front().checked)
-                       {
+                       if ((has_team() || (old_label && team_only)) && 
d.option_checked()) {
                                team_name = gui_->labels().team_name();
-
-                       }
-                       else
-                       {
-                               colour = team::get_side_colour( 
gui_->viewing_team() + 1);
-                       }
-
-                       
gui_->labels().set_label(mousehandler.get_last_hex(),label,&recorder, 
team_name, colour);
-
+                       }
+                       else {
+                               colour = 
team::get_side_colour(gui_->viewing_team() + 1);
+                       }
+                       gui_->labels().set_label(mousehandler.get_last_hex(), 
d.textbox_text(), &recorder, team_name, colour);
                }
        }
 

Modified: trunk/src/show_dialog.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/show_dialog.cpp?rev=16849&r1=16848&r2=16849&view=diff
==============================================================================
--- trunk/src/show_dialog.cpp (original)
+++ trunk/src/show_dialog.cpp Sun Apr 15 04:10:41 2007
@@ -352,10 +352,8 @@
        }
        if(options) {
                for(unsigned int i=0; i < options->size(); ++i) {
-                       gui::dialog_button *btn = new 
gui::dialog_button(disp,(*options)[i].label,gui::button::TYPE_CHECK);
-                       gui::dialog::BUTTON_LOCATION loc = ((*options)[i].align 
== LEFT_ALIGN)? gui::dialog::BUTTON_CHECKBOX_LEFT : 
gui::dialog::BUTTON_CHECKBOX;
-                       btn->set_check((*options)[i].checked);
-                       d.add_button(btn, loc);
+                       check_item& item = (*options)[i];
+                       d.add_option(item.label, item.checked);
                }
        }
        if(action_buttons) {

Modified: trunk/src/show_dialog.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/show_dialog.hpp?rev=16849&r1=16848&r2=16849&view=diff
==============================================================================
--- trunk/src/show_dialog.hpp (original)
+++ trunk/src/show_dialog.hpp Sun Apr 15 04:10:41 2007
@@ -105,10 +105,9 @@
 enum DIALOG_TYPE { MESSAGE, OK_ONLY, YES_NO, OK_CANCEL, CANCEL_ONLY, 
CLOSE_ONLY, NULL_DIALOG };
 
 struct check_item {
-       check_item(const std::string& label, bool checked) : label(label), 
checked(checked), align(RIGHT_ALIGN) {}
+       check_item(const std::string& label, bool checked) : label(label), 
checked(checked) {}
        std::string label;
        bool checked;
-       ALIGN align;
 };
 
 //an interface for a 'preview pane'. A preview pane is shown beside a dialog 
created

Modified: trunk/src/upload_log.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/upload_log.cpp?rev=16849&r1=16848&r2=16849&view=diff
==============================================================================
--- trunk/src/upload_log.cpp (original)
+++ trunk/src/upload_log.cpp Sun Apr 15 04:10:41 2007
@@ -14,12 +14,12 @@
 
 #define GETTEXT_DOMAIN "wesnoth"
 
+#include "construct_dialog.hpp"
 #include "game_config.hpp"
 #include "gettext.hpp"
 #include "filesystem.hpp"
 #include "preferences.hpp"
 #include "serialization/parser.hpp"
-#include "show_dialog.hpp"
 #include "upload_log.hpp"
 #include "wesconfig.h"
 #include "wml_separators.hpp"
@@ -280,23 +280,15 @@
 
 void upload_log_dialog::show_beg_dialog(display& disp)
 {
-       std::vector<gui::check_item> options;
-       gui::check_item beg_check = gui::check_item(_("Enable summary uploads"),
-                                                                         
preferences::upload_log());
-       beg_check.align = gui::LEFT_ALIGN;
-       options.push_back(beg_check);
-
        std::string msg = std::string(_("Wesnoth relies on volunteers like 
yourself for feedback, especially beginners and new players.  Wesnoth keeps 
summaries of your games: you can help us improve game play by giving permission 
to send these summaries (anonymously) to wesnoth.org.\n"))
                + " \n`" + _("Summaries are stored here:")
                + " \n`~" + get_upload_dir() + "\n \n`"
                + _("You can view the results at:") + "\n`~"
                + "http://stats.wesnoth.org/?"; + preferences::upload_id() + "\n 
\n";
-
-
-       gui::show_dialog(disp, NULL,
-                                        _("Help us make Wesnoth better for 
you!"),
-                                        msg,
-                                        gui::OK_ONLY,
-                                        NULL, NULL, "", NULL, 0, NULL, 
&options);
-       preferences::set_upload_log(options.front().checked);
-}
+       gui::dialog d(disp, _("Help us make Wesnoth better for you!"), msg, 
gui::OK_ONLY);
+
+       d.add_option(_("Enable summary uploads"), 
+               preferences::upload_log(), gui::dialog::BUTTON_CHECKBOX_LEFT);
+       d.show();
+       preferences::set_upload_log(d.option_checked());
+}

Modified: trunk/src/widgets/widget.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/widgets/widget.cpp?rev=16849&r1=16848&r2=16849&view=diff
==============================================================================
--- trunk/src/widgets/widget.cpp (original)
+++ trunk/src/widgets/widget.cpp Sun Apr 15 04:10:41 2007
@@ -26,14 +26,14 @@
        : events::handler(), focus_(o.focus_), video_(o.video_), 
restorer_(o.restorer_), rect_(o.rect_),
           needs_restore_(o.needs_restore_), state_(o.state_), 
hidden_override_(o.hidden_override_),
          enabled_(o.enabled_), clip_(o.clip_), clip_rect_(o.clip_rect_), 
volatile_(o.volatile_),
-         help_text_(o.help_text_), help_string_(o.help_string_), 
align_(o.align_), id_(o.id_)
+         help_text_(o.help_text_), help_string_(o.help_string_), id_(o.id_)
 {
 }
 
 widget::widget(CVideo& video, const bool auto_join)
        : handler(auto_join), focus_(true), video_(&video), rect_(EmptyRect), 
needs_restore_(false),
          state_(UNINIT), hidden_override_(false), enabled_(true), clip_(false),
-         clip_rect_(EmptyRect), volatile_(false), help_string_(0), 
align_(RIGHT_ALIGN)
+         clip_rect_(EmptyRect), volatile_(false), help_string_(0)
 {
 }
 
@@ -97,20 +97,10 @@
        set_location(rect);
 }
 
-void widget::set_align(ALIGN a)
-{
-       align_ = a;
-}
-
 void widget::set_measurements(unsigned w, unsigned h)
 {
        SDL_Rect rect = { rect_.x, rect_.y, w, h };
        set_location(rect);
-}
-
-ALIGN widget::align() const
-{
-       return align_;
 }
 
 unsigned widget::width() const

Modified: trunk/src/widgets/widget.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/widgets/widget.hpp?rev=16849&r1=16848&r2=16849&view=diff
==============================================================================
--- trunk/src/widgets/widget.hpp (original)
+++ trunk/src/widgets/widget.hpp Sun Apr 15 04:10:41 2007
@@ -26,8 +26,6 @@
 
 namespace gui {
 
-enum ALIGN { LEFT_ALIGN, CENTER_ALIGN, RIGHT_ALIGN };
-
 class widget : public events::handler
 {
 public:
@@ -37,11 +35,9 @@
        void set_width(unsigned w);
        void set_height(unsigned h);
        void set_measurements(unsigned w, unsigned h);
-       void set_align(ALIGN a);
 
        unsigned width() const;
        unsigned height() const;
-       ALIGN align() const;
 
        //focus() may gain the focus if the currently focused handler doesn't 
require this event
        bool focus(const SDL_Event* event);
@@ -119,7 +115,6 @@
 
        std::string help_text_;
        int help_string_;
-       ALIGN align_; //limited support, use position
        std::string id_;
 
        friend class scrollpane;


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

Reply via email to