mail[Wesnoth-commits] r28439 - in /trunk/src/gui/dialogs: editor_resize_map.cpp helper.hpp mp_create_game.cpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by kailoran on August 10, 2008 - 17:34:
Author: ilor
Date: Sun Aug 10 17:34:28 2008
New Revision: 28439

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28439&view=rev
Log:
add gui/dialogs/helper.hpp with a template callback helper, convert  two 
dialogs to use it

Added:
    trunk/src/gui/dialogs/helper.hpp   (with props)
Modified:
    trunk/src/gui/dialogs/editor_resize_map.cpp
    trunk/src/gui/dialogs/mp_create_game.cpp

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=28439&r1=28438&r2=28439&view=diff
==============================================================================
--- trunk/src/gui/dialogs/editor_resize_map.cpp (original)
+++ trunk/src/gui/dialogs/editor_resize_map.cpp Sun Aug 10 17:34:28 2008
@@ -16,6 +16,7 @@
 
 #include "foreach.hpp"
 #include "gui/dialogs/field.hpp"
+#include "gui/dialogs/helper.hpp"
 #include "gui/widgets/button.hpp"
 #include "gui/widgets/label.hpp"
 #include "gui/widgets/listbox.hpp"
@@ -109,9 +110,9 @@
                std::string name = name_prefix + lexical_cast<std::string>(i);
                direction_buttons_[i] = 
dynamic_cast<ttoggle_button*>(window.find_widget(name, false));
                VALIDATE(direction_buttons_[i], missing_widget(name));        
  
-               
direction_buttons_[i]->set_callback_state_change(callback_expand_direction_changed);
+               direction_buttons_[i]->set_callback_state_change(
+                       dialog_callback<teditor_resize_map, 
&teditor_resize_map::update_expand_direction>);
        }
-       
        window.recalculate_size();
 }
 

Added: trunk/src/gui/dialogs/helper.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/helper.hpp?rev=28439&view=auto
==============================================================================
--- trunk/src/gui/dialogs/helper.hpp (added)
+++ trunk/src/gui/dialogs/helper.hpp Sun Aug 10 17:34:28 2008
@@ -1,0 +1,37 @@
+/* $Id$ */
+/*
+   copyright (c) 2008 by mark de wever <koraq@xxxxxxxxx>
+   part of the battle for wesnoth project http://www.wesnoth.org/
+
+   this program is free software; you can redistribute it and/or modify
+   it under the terms of the gnu general public license version 2
+   or at your option any later version.
+   this program is distributed in the hope that it will be useful,
+   but without any warranty.
+
+   see the copying file for more details.
+*/
+
+#ifndef GUI_DIALOGS_HELPER_HPP_INCLUDED
+#define GUI_DIALOGS_HELPER_HPP_INCLUDED
+
+namespace gui2 {
+
+/**
+ * Template for dialog callbacks. Example usage:
+ * widget->set_callback(dialog_callback<my_dialog_class, 
&my_dialog_class::member_function>);
+ */
+template <class D, void (D::*fptr)(twindow&)>
+void dialog_callback(twidget* caller)
+{
+       D* dialog = dynamic_cast<D*>(caller->dialog());
+       assert(dialog);
+       twindow* window = dynamic_cast<twindow*>(caller->get_window());
+       assert(window);
+       (dialog->*fptr)(*window);
+}
+
+} // namespace gui2
+
+#endif
+

Propchange: trunk/src/gui/dialogs/helper.hpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: trunk/src/gui/dialogs/helper.hpp
------------------------------------------------------------------------------
    svn:keywords = 'Author Date Id Revision'

Modified: trunk/src/gui/dialogs/mp_create_game.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/mp_create_game.cpp?rev=28439&r1=28438&r2=28439&view=diff
==============================================================================
--- trunk/src/gui/dialogs/mp_create_game.cpp (original)
+++ trunk/src/gui/dialogs/mp_create_game.cpp Sun Aug 10 17:34:28 2008
@@ -21,6 +21,7 @@
 #include "gettext.hpp"
 #include "gui/dialogs/dialog.hpp"
 #include "gui/dialogs/field.hpp"
+#include "gui/dialogs/helper.hpp"
 #include "gui/widgets/listbox.hpp"
 #include "gui/widgets/minimap.hpp"
 #include "gui/widgets/widget.hpp"
@@ -40,33 +41,13 @@
 
 namespace gui2 {
 
-static void callback_use_map_settings(twidget* caller)
-{
-       tmp_create_game* dialog = 
dynamic_cast<tmp_create_game*>(caller->dialog());
-       assert(dialog);
-       twindow* window = dynamic_cast<twindow*>(caller->get_window());
-       assert(window);
-
-       dialog->update_map_settings(*window);
-}
-
-static void callback_select_list_item(twidget* caller)
-{
-       tmp_create_game* dialog = 
dynamic_cast<tmp_create_game*>(caller->dialog());
-       assert(dialog);
-       twindow* window = dynamic_cast<twindow*>(caller->get_window());
-       assert(window);
-
-       dialog->update_map(*window);
-}
-
 tmp_create_game::tmp_create_game(const config& cfg) :
        cfg_(cfg),
        scenario_(NULL),
        use_map_settings_(register_bool("use_map_settings", false, 
                preferences::use_map_settings, 
                preferences::set_use_map_settings,
-               callback_use_map_settings)),
+               dialog_callback<tmp_create_game, 
&tmp_create_game::update_map_settings>)),
        fog_(register_bool("fog", false, 
                        preferences::fog, 
                        preferences::set_fog)),
@@ -103,7 +84,7 @@
        tlistbox* list = 
dynamic_cast<tlistbox*>(window.find_widget("map_list", false));
        VALIDATE(list, missing_widget("map_list"));
 
-       list->set_callback_value_change(callback_select_list_item);
+       list->set_callback_value_change(dialog_callback<tmp_create_game, 
&tmp_create_game::update_map>);
 
        // Load option (might turn it into a button later).
        std::map<std::string, t_string> item;




Related Messages


Powered by MHonArc, Updated Sun Aug 10 17:41:53 2008