mail[Wesnoth-commits] r36572 - in /trunk: po/wesnoth-lib/ src/ src/gui/auxiliary/ src/gui/auxiliary/window_builder/


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

Header


Content

Posted by koraq on July 04, 2009 - 23:20:
Author: mordante
Date: Sat Jul  4 12:27:19 2009
New Revision: 36572

URL: http://svn.gna.org/viewcvs/wesnoth?rev=36572&view=rev
Log:
Move the window_builder helper functions to their own file.

Added:
    trunk/src/gui/auxiliary/window_builder/helper.cpp   (with props)
    trunk/src/gui/auxiliary/window_builder/helper.hpp   (with props)
Modified:
    trunk/po/wesnoth-lib/POTFILES.in
    trunk/src/CMakeLists.txt
    trunk/src/Makefile.am
    trunk/src/SConscript
    trunk/src/gui/auxiliary/window_builder.cpp
    trunk/src/gui/auxiliary/window_builder/button.cpp
    trunk/src/gui/auxiliary/window_builder/toggle_panel.cpp

Modified: trunk/po/wesnoth-lib/POTFILES.in
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/po/wesnoth-lib/POTFILES.in?rev=36572&r1=36571&r2=36572&view=diff
==============================================================================
--- trunk/po/wesnoth-lib/POTFILES.in (original)
+++ trunk/po/wesnoth-lib/POTFILES.in Sat Jul  4 12:27:19 2009
@@ -8,6 +8,7 @@
 src/gui/auxiliary/log.cpp
 src/gui/auxiliary/window_builder/button.cpp
 src/gui/auxiliary/window_builder/control.cpp
+src/gui/auxiliary/window_builder/helper.cpp
 src/gui/auxiliary/window_builder/image.cpp
 src/gui/auxiliary/window_builder/label.cpp
 src/gui/auxiliary/window_builder/minimap.cpp

Modified: trunk/src/CMakeLists.txt
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/CMakeLists.txt?rev=36572&r1=36571&r2=36572&view=diff
==============================================================================
--- trunk/src/CMakeLists.txt (original)
+++ trunk/src/CMakeLists.txt Sat Jul  4 12:27:19 2009
@@ -266,6 +266,7 @@
     gui/auxiliary/log.cpp
     gui/auxiliary/window_builder/button.cpp
     gui/auxiliary/window_builder/control.cpp
+    gui/auxiliary/window_builder/helper.cpp
     gui/auxiliary/window_builder/image.cpp
     gui/auxiliary/window_builder/label.cpp
     gui/auxiliary/window_builder/minimap.cpp

Modified: trunk/src/Makefile.am
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/Makefile.am?rev=36572&r1=36571&r2=36572&view=diff
==============================================================================
--- trunk/src/Makefile.am (original)
+++ trunk/src/Makefile.am Sat Jul  4 12:27:19 2009
@@ -91,6 +91,7 @@
        gui/auxiliary/log.cpp \
        gui/auxiliary/window_builder/button.cpp \
        gui/auxiliary/window_builder/control.cpp \
+       gui/auxiliary/window_builder/helper.cpp \
        gui/auxiliary/window_builder/image.cpp \
        gui/auxiliary/window_builder/label.cpp \
        gui/auxiliary/window_builder/minimap.cpp \

Modified: trunk/src/SConscript
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/SConscript?rev=36572&r1=36571&r2=36572&view=diff
==============================================================================
--- trunk/src/SConscript (original)
+++ trunk/src/SConscript Sat Jul  4 12:27:19 2009
@@ -247,6 +247,7 @@
     gui/auxiliary/log.cpp
     gui/auxiliary/window_builder/button.cpp
     gui/auxiliary/window_builder/control.cpp
+    gui/auxiliary/window_builder/helper.cpp
     gui/auxiliary/window_builder/image.cpp
     gui/auxiliary/window_builder/label.cpp
     gui/auxiliary/window_builder/minimap.cpp

Modified: trunk/src/gui/auxiliary/window_builder.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/auxiliary/window_builder.cpp?rev=36572&r1=36571&r2=36572&view=diff
==============================================================================
--- trunk/src/gui/auxiliary/window_builder.cpp (original)
+++ trunk/src/gui/auxiliary/window_builder.cpp Sat Jul  4 12:27:19 2009
@@ -21,6 +21,7 @@
 #include "gettext.hpp"
 #include "gui/auxiliary/log.hpp"
 #include "gui/auxiliary/window_builder/button.hpp"
+#include "gui/auxiliary/window_builder/helper.hpp"
 #include "gui/auxiliary/window_builder/image.hpp"
 #include "gui/auxiliary/window_builder/label.hpp"
 #include "gui/auxiliary/window_builder/minimap.hpp"
@@ -49,114 +50,12 @@
 #include "gui/widgets/vertical_scrollbar.hpp"
 #include "gui/widgets/window.hpp"
 
+// The widgets builders and helpers are partly in this namespace.
+using namespace gui2::implementation;
+
 namespace gui2 {
 
 namespace {
-
-unsigned get_v_align(const std::string& v_align)
-{
-       if(v_align == "top") {
-               return tgrid::VERTICAL_ALIGN_TOP;
-       } else if(v_align == "bottom") {
-               return tgrid::VERTICAL_ALIGN_BOTTOM;
-       } else {
-               if(!v_align.empty() && v_align != "center") {
-                       ERR_GUI_E << "Invalid vertical alignment '"
-                               << v_align << "' falling back to 'center'.\n";
-               }
-               return tgrid::VERTICAL_ALIGN_CENTER;
-       }
-}
-
-unsigned get_h_align(const std::string& h_align)
-{
-       if(h_align == "left") {
-               return tgrid::HORIZONTAL_ALIGN_LEFT;
-       } else if(h_align == "right") {
-               return tgrid::HORIZONTAL_ALIGN_RIGHT;
-       } else {
-               if(!h_align.empty() && h_align != "center") {
-                       ERR_GUI_E << "Invalid horizontal alignment '"
-                               << h_align << "' falling back to 'center'.\n";
-               }
-               return tgrid::HORIZONTAL_ALIGN_CENTER;
-       }
-}
-
-unsigned get_border(const std::vector<std::string>& border)
-{
-       if(std::find(border.begin(), border.end(), std::string("all")) != 
border.end()) {
-               return tgrid::BORDER_TOP
-                       | tgrid::BORDER_BOTTOM | tgrid::BORDER_LEFT | 
tgrid::BORDER_RIGHT;
-       } else {
-               if(std::find(border.begin(), border.end(), 
std::string("top")) != border.end()) {
-                       return tgrid::BORDER_TOP;
-               }
-               if(std::find(border.begin(), border.end(), 
std::string("bottom")) != border.end()) {
-                       return tgrid::BORDER_BOTTOM;
-               }
-               if(std::find(border.begin(), border.end(), 
std::string("left")) != border.end()) {
-                       return tgrid::BORDER_LEFT;
-               }
-               if(std::find(border.begin(), border.end(), 
std::string("right")) != border.end()) {
-                       return tgrid::BORDER_RIGHT;
-               }
-       }
-
-       return 0;
-}
-
-unsigned read_flags(const config& cfg)
-{
-       unsigned flags = 0;
-
-       const unsigned v_flags = get_v_align(cfg["vertical_alignment"]);
-       const unsigned h_flags = get_h_align(cfg["horizontal_alignment"]);
-       flags |= get_border( utils::split(cfg["border"]));
-
-       if(utils::string_bool(cfg["vertical_grow"])) {
-               flags |= tgrid::VERTICAL_GROW_SEND_TO_CLIENT;
-
-               if(! (cfg["vertical_alignment"]).empty()) {
-                       ERR_GUI_P << "vertical_grow and vertical_alignment "
-                               "can't be combined, alignment is ignored.\n";
-               }
-       } else {
-               flags |= v_flags;
-       }
-
-       if(utils::string_bool(cfg["horizontal_grow"])) {
-               flags |= tgrid::HORIZONTAL_GROW_SEND_TO_CLIENT;
-
-               if(! (cfg["horizontal_alignment"]).empty()) {
-                       ERR_GUI_P << "horizontal_grow and 
horizontal_alignment "
-                               "can't be combined, alignment is ignored.\n";
-               }
-       } else {
-               flags |= h_flags;
-       }
-
-       return flags;
-}
-
-tscrollbar_container::tscrollbar_mode
-               get_scrollbar_mode(const std::string& scrollbar_mode)
-{
-       if(scrollbar_mode == "always") {
-               return tscrollbar_container::always_visible;
-       } else if(scrollbar_mode == "never") {
-               return tscrollbar_container::always_invisible;
-       } else if(scrollbar_mode == "initial_auto"
-                       || (gui2::new_widgets && scrollbar_mode.empty())) {
-               return tscrollbar_container::auto_visible_first_run;
-       } else {
-               if(!scrollbar_mode.empty() && scrollbar_mode != "auto") {
-                       ERR_GUI_E << "Invalid scrollbar mode '"
-                               << scrollbar_mode << "' falling back to 
'auto'.\n";
-               }
-               return tscrollbar_container::auto_visible;
-       }
-}
 
 tbuilder_widget_ptr create_builder_widget(const config& cfg)
 {
@@ -169,8 +68,6 @@
                assert(false);
        }
 
-       // The widgets builders are partly in this namespace.
-       using namespace gui2::implementation;
 #define TRY(name) do { \
        if (const config &c = cfg.child(#name)) \
                return new tbuilder_##name(c); \
@@ -203,36 +100,6 @@
 }
 
 } // namespace
-
-/**
- * Returns the return value for a widget.
- *
- * If there's a valid retval_id that will be returned.
- * Else if there's a retval that's returned.
- * Else it falls back to the id.
- */
-/** @todo move to it's own header. */
-int get_retval(const std::string& retval_id,
-               const int retval, const std::string& id);
-int get_retval(const std::string& retval_id,
-               const int retval, const std::string& id)
-{
-       if(!retval_id.empty()) {
-               int result = twindow::get_retval_by_id(retval_id);
-               if(result) {
-                       return result;
-               } else {
-                       ERR_GUI_E << "Window builder: retval_id '"
-                                       << retval_id << "' is unknown.\n";
-               }
-       }
-
-       if(retval) {
-               return retval;
-       } else {
-               return twindow::get_retval_by_id(id);
-       }
-}
 
 /*WIKI
  * @page = GUIWidgetInstanceWML

Modified: trunk/src/gui/auxiliary/window_builder/button.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/auxiliary/window_builder/button.cpp?rev=36572&r1=36571&r2=36572&view=diff
==============================================================================
--- trunk/src/gui/auxiliary/window_builder/button.cpp (original)
+++ trunk/src/gui/auxiliary/window_builder/button.cpp Sat Jul  4 12:27:19 2009
@@ -18,13 +18,10 @@
 
 #include "config.hpp"
 #include "gui/auxiliary/log.hpp"
+#include "gui/auxiliary/window_builder/helper.hpp"
 #include "gui/widgets/button.hpp"
 
 namespace gui2 {
-
-/** @todo move to it's own header. */
-extern int get_retval(const std::string& retval_id,
-               const int retval, const std::string& id);
 
 namespace implementation {
 

Added: trunk/src/gui/auxiliary/window_builder/helper.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/auxiliary/window_builder/helper.cpp?rev=36572&view=auto
==============================================================================
--- trunk/src/gui/auxiliary/window_builder/helper.cpp (added)
+++ trunk/src/gui/auxiliary/window_builder/helper.cpp Sat Jul  4 12:27:19 2009
@@ -1,0 +1,166 @@
+/* $Id$ */
+/*
+   Copyright (C) 2008 - 2009 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.
+*/
+
+#define GETTEXT_DOMAIN "wesnoth-lib"
+
+#include "gui/auxiliary/window_builder/helper.hpp"
+
+#include "config.hpp"
+#include "gui/auxiliary/log.hpp"
+#include "gui/widgets/grid.hpp"
+#include "gui/widgets/window.hpp"
+
+namespace gui2 {
+
+namespace implementation {
+
+unsigned get_v_align(const std::string& v_align)
+{
+       if(v_align == "top") {
+               return tgrid::VERTICAL_ALIGN_TOP;
+       } else if(v_align == "bottom") {
+               return tgrid::VERTICAL_ALIGN_BOTTOM;
+       } else {
+               if(!v_align.empty() && v_align != "center") {
+                       ERR_GUI_E << "Invalid vertical alignment '"
+                               << v_align << "' falling back to 'center'.\n";
+               }
+               return tgrid::VERTICAL_ALIGN_CENTER;
+       }
+}
+
+unsigned get_h_align(const std::string& h_align)
+{
+       if(h_align == "left") {
+               return tgrid::HORIZONTAL_ALIGN_LEFT;
+       } else if(h_align == "right") {
+               return tgrid::HORIZONTAL_ALIGN_RIGHT;
+       } else {
+               if(!h_align.empty() && h_align != "center") {
+                       ERR_GUI_E << "Invalid horizontal alignment '"
+                               << h_align << "' falling back to 'center'.\n";
+               }
+               return tgrid::HORIZONTAL_ALIGN_CENTER;
+       }
+}
+
+unsigned get_border(const std::vector<std::string>& border)
+{
+       if(std::find(border.begin(), border.end(), std::string("all"))
+                               != border.end()) {
+
+               return tgrid::BORDER_TOP
+                       | tgrid::BORDER_BOTTOM | tgrid::BORDER_LEFT | 
tgrid::BORDER_RIGHT;
+       } else {
+               if(std::find(border.begin(), border.end(), std::string("top"))
+                               != border.end()) {
+
+                       return tgrid::BORDER_TOP;
+               }
+               if(std::find(border.begin(), border.end(), 
std::string("bottom"))
+                               != border.end()) {
+
+                       return tgrid::BORDER_BOTTOM;
+               }
+               if(std::find(border.begin(), border.end(), 
std::string("left"))
+                               != border.end()) {
+
+                       return tgrid::BORDER_LEFT;
+               }
+               if(std::find(border.begin(), border.end(), 
std::string("right"))
+                               != border.end()) {
+
+                       return tgrid::BORDER_RIGHT;
+               }
+       }
+
+       return 0;
+}
+
+unsigned read_flags(const config& cfg)
+{
+       unsigned flags = 0;
+
+       const unsigned v_flags = get_v_align(cfg["vertical_alignment"]);
+       const unsigned h_flags = get_h_align(cfg["horizontal_alignment"]);
+       flags |= get_border( utils::split(cfg["border"]));
+
+       if(utils::string_bool(cfg["vertical_grow"])) {
+               flags |= tgrid::VERTICAL_GROW_SEND_TO_CLIENT;
+
+               if(! (cfg["vertical_alignment"]).empty()) {
+                       ERR_GUI_P << "vertical_grow and vertical_alignment "
+                               "can't be combined, alignment is ignored.\n";
+               }
+       } else {
+               flags |= v_flags;
+       }
+
+       if(utils::string_bool(cfg["horizontal_grow"])) {
+               flags |= tgrid::HORIZONTAL_GROW_SEND_TO_CLIENT;
+
+               if(! (cfg["horizontal_alignment"]).empty()) {
+                       ERR_GUI_P << "horizontal_grow and 
horizontal_alignment "
+                               "can't be combined, alignment is ignored.\n";
+               }
+       } else {
+               flags |= h_flags;
+       }
+
+       return flags;
+}
+
+tscrollbar_container::tscrollbar_mode
+               get_scrollbar_mode(const std::string& scrollbar_mode)
+{
+       if(scrollbar_mode == "always") {
+               return tscrollbar_container::always_visible;
+       } else if(scrollbar_mode == "never") {
+               return tscrollbar_container::always_invisible;
+       } else if(scrollbar_mode == "initial_auto"
+                       || (gui2::new_widgets && scrollbar_mode.empty())) {
+               return tscrollbar_container::auto_visible_first_run;
+       } else {
+               if(!scrollbar_mode.empty() && scrollbar_mode != "auto") {
+                       ERR_GUI_E << "Invalid scrollbar mode '"
+                               << scrollbar_mode << "' falling back to 
'auto'.\n";
+               }
+               return tscrollbar_container::auto_visible;
+       }
+}
+
+int get_retval(const std::string& retval_id,
+               const int retval, const std::string& id)
+{
+       if(!retval_id.empty()) {
+               int result = twindow::get_retval_by_id(retval_id);
+               if(result) {
+                       return result;
+               } else {
+                       ERR_GUI_E << "Window builder: retval_id '"
+                                       << retval_id << "' is unknown.\n";
+               }
+       }
+
+       if(retval) {
+               return retval;
+       } else {
+               return twindow::get_retval_by_id(id);
+       }
+}
+
+} // namespace implementation
+
+} // namespace gui2
+

Propchange: trunk/src/gui/auxiliary/window_builder/helper.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: trunk/src/gui/auxiliary/window_builder/helper.cpp
------------------------------------------------------------------------------
    svn:keywords = 'Author Date Id Revision'

Added: trunk/src/gui/auxiliary/window_builder/helper.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/auxiliary/window_builder/helper.hpp?rev=36572&view=auto
==============================================================================
--- trunk/src/gui/auxiliary/window_builder/helper.hpp (added)
+++ trunk/src/gui/auxiliary/window_builder/helper.hpp Sat Jul  4 12:27:19 2009
@@ -1,0 +1,90 @@
+/* $Id$ */
+/*
+   Copyright (C) 2008 - 2009 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_AUXILIARY_WINDOW_BUILDER_HELPER_HPP_INCLUDED
+#define GUI_AUXILIARY_WINDOW_BUILDER_HELPER_HPP_INCLUDED
+
+#include "gui/widgets/scrollbar_container.hpp"
+
+#include <string>
+#include <vector>
+
+class config;
+
+namespace gui2 {
+
+namespace implementation {
+
+/**
+ * Returns the vertical alignement.
+ *
+ * @param v_align                 The string representing the alignement.
+ *
+ * @returns                       The alignment.
+ */
+unsigned get_v_align(const std::string& v_align);
+
+/**
+ * Returns the horizontal alignement.
+ *
+ * @param h_align                 The string representing the alignement.
+ *
+ * @returns                       The alignment.
+ */
+unsigned get_h_align(const std::string& h_align);
+
+/**
+ * Returns the border flags.
+ *
+ * @param border                  The string representing the border flags.
+ *
+ * @returns                       The border flags.
+ */
+unsigned get_border(const std::vector<std::string>& border);
+
+/**
+ * Returns the placement/resize flags.
+ *
+ * @param cfg                     The config to look for flags for.
+ *
+ * @returns                       The placement/resize flags.
+ */
+unsigned read_flags(const config& cfg);
+
+/**
+ * Returns the scrollbar mode flags.
+ *
+ * @param scrollbar_mode          The string representing the scrollbar_mode.
+ *
+ * @returns                       The scrollbar mode flags.
+ */
+tscrollbar_container::tscrollbar_mode
+               get_scrollbar_mode(const std::string& scrollbar_mode);
+
+/**
+ * Returns the return value for a widget.
+ *
+ * If there's a valid retval_id that will be returned.
+ * Else if there's a retval that's returned.
+ * Else it falls back to the id.
+ */
+int get_retval(const std::string& retval_id,
+               const int retval, const std::string& id);
+
+} // namespace implementation
+
+} // namespace gui2
+
+#endif
+

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

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

Modified: trunk/src/gui/auxiliary/window_builder/toggle_panel.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/auxiliary/window_builder/toggle_panel.cpp?rev=36572&r1=36571&r2=36572&view=diff
==============================================================================
--- trunk/src/gui/auxiliary/window_builder/toggle_panel.cpp (original)
+++ trunk/src/gui/auxiliary/window_builder/toggle_panel.cpp Sat Jul  4 
12:27:19 2009
@@ -19,14 +19,11 @@
 #include "config.hpp"
 #include "gettext.hpp"
 #include "gui/auxiliary/log.hpp"
+#include "gui/auxiliary/window_builder/helper.hpp"
 #include "gui/widgets/toggle_panel.hpp"
 #include "wml_exception.hpp"
 
 namespace gui2 {
-
-/** @todo move to it's own header. */
-extern int get_retval(const std::string& retval_id,
-               const int retval, const std::string& id);
 
 namespace implementation {
 




Related Messages


Powered by MHonArc, Updated Sun Jul 05 00:00:15 2009