Author: mordante
Date: Sun Sep 21 11:25:36 2008
New Revision: 29609

URL: http://svn.gna.org/viewcvs/wesnoth?rev=29609&view=rev
Log:
Fix some bugs with the grid flags.

The flags did an uncorrect test on the flags, now properly uses a mask.
Also added better detection for invalid flags. Avoided grow and
alignment both to be set (leading to invalid flags) and removed all
occurances in the configs.

Modified:
    trunk/data/gui/default/window/language_selection.cfg
    trunk/data/gui/default/window/message.cfg
    trunk/data/gui/default/window/mp_method_selection.cfg
    trunk/data/gui/default/window/mp_server_list.cfg
    trunk/src/gui/widgets/grid.cpp
    trunk/src/gui/widgets/grid.hpp
    trunk/src/gui/widgets/window_builder.cpp

Modified: trunk/data/gui/default/window/language_selection.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/gui/default/window/language_selection.cfg?rev=29609&r1=29608&r2=29609&view=diff
==============================================================================
--- trunk/data/gui/default/window/language_selection.cfg (original)
+++ trunk/data/gui/default/window/language_selection.cfg Sun Sep 21 11:25:36 
2008
@@ -63,7 +63,6 @@
 
                                        border = "all"
                                        border_size = 5
-                                       horizontal_alignment = "right"
 
                                        [listbox]
                                                id = "language_list"

Modified: trunk/data/gui/default/window/message.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/gui/default/window/message.cfg?rev=29609&r1=29608&r2=29609&view=diff
==============================================================================
--- trunk/data/gui/default/window/message.cfg (original)
+++ trunk/data/gui/default/window/message.cfg Sun Sep 21 11:25:36 2008
@@ -184,7 +184,6 @@
 
                                                                                
                border = "all"
                                                                                
                border_size = 5
-                                                                               
                horizontal_alignment = "left"
 
                                                                                
                [label]
                                                                                
                        id = "message"
@@ -267,7 +266,6 @@
 
                                                                                
                border = "all"
                                                                                
                border_size = 5
-                                                                               
                horizontal_alignment = "left"
 
                                                                                
                [label]
                                                                                
                        id = "message"

Modified: trunk/data/gui/default/window/mp_method_selection.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/gui/default/window/mp_method_selection.cfg?rev=29609&r1=29608&r2=29609&view=diff
==============================================================================
--- trunk/data/gui/default/window/mp_method_selection.cfg (original)
+++ trunk/data/gui/default/window/mp_method_selection.cfg Sun Sep 21 11:25:36 
2008
@@ -97,7 +97,6 @@
 
                                        border = "all"
                                        border_size = 5
-                                       horizontal_alignment = "right"
 
                                        [listbox]
                                                id = "method_list"

Modified: trunk/data/gui/default/window/mp_server_list.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/gui/default/window/mp_server_list.cfg?rev=29609&r1=29608&r2=29609&view=diff
==============================================================================
--- trunk/data/gui/default/window/mp_server_list.cfg (original)
+++ trunk/data/gui/default/window/mp_server_list.cfg Sun Sep 21 11:25:36 2008
@@ -123,7 +123,6 @@
 
                                                                                
                        border = "all"
                                                                                
                        border_size = 5
-                                                                               
                        horizontal_alignment = "left"
 
                                                                                
                        [label]
                                                                                
                                id = "name"
@@ -139,8 +138,6 @@
 
                                                                                
                        border = "all"
                                                                                
                        border_size = 5
-                                                                               
                        horizontal_alignment = "left"
-
 
                                                                                
                        [label]
                                                                                
                                id = "address"

Modified: trunk/src/gui/widgets/grid.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/grid.cpp?rev=29609&r1=29608&r2=29609&view=diff
==============================================================================
--- trunk/src/gui/widgets/grid.cpp (original)
+++ trunk/src/gui/widgets/grid.cpp Sun Sep 21 11:25:36 2008
@@ -84,6 +84,8 @@
                const unsigned col, const unsigned flags, const unsigned 
border_size) 
 {
        assert(row < rows_ && col < cols_);
+       assert(flags & VERTICAL_MASK);
+       assert(flags & HORIZONTAL_MASK);
 
        tchild& cell = child(row, col);
 
@@ -738,7 +740,7 @@
        }
 
        const tpoint maximum_size = widget()->get_maximum_size();
-       if((flags_ & (HORIZONTAL_GROW_SEND_TO_CLIENT | 
VERTICAL_GROW_SEND_TO_CLIENT))
+       if((flags_ & (HORIZONTAL_MASK | VERTICAL_MASK))
                        == (HORIZONTAL_GROW_SEND_TO_CLIENT | 
VERTICAL_GROW_SEND_TO_CLIENT)) {
 
                if(maximum_size == tpoint(0,0) || size <= maximum_size) {
@@ -757,7 +759,9 @@
                std::min(size.y, best_size.y));
        tpoint widget_orig = orig;
 
-       if(flags_ & VERTICAL_GROW_SEND_TO_CLIENT) {
+       const unsigned v_flag = flags_ & VERTICAL_MASK;
+
+       if(v_flag == VERTICAL_GROW_SEND_TO_CLIENT) {
                if(maximum_size.y) {
                        widget_size.y = std::min(size.y, maximum_size.y);
                } else {
@@ -766,27 +770,30 @@
                DBG_G << "Grid cell: vertical growing from " 
                        << best_size.y << " to " << widget_size.y << ".\n";
 
-       } else if((flags_ & VERTICAL_ALIGN_TOP) == VERTICAL_ALIGN_TOP) {
+       } else if(v_flag == VERTICAL_ALIGN_TOP) {
                // Do nothing.
                
                DBG_G << "Grid cell: vertically aligned at the top.\n";
 
-       } else if((flags_ & VERTICAL_ALIGN_CENTER) == VERTICAL_ALIGN_CENTER) {
+       } else if(v_flag == VERTICAL_ALIGN_CENTER) {
                
                widget_orig.y += (size.y - widget_size.y) / 2;
                DBG_G << "Grid cell: vertically centred.\n";
 
-       } else if((flags_ & VERTICAL_ALIGN_BOTTOM) == VERTICAL_ALIGN_BOTTOM) {
+       } else if(v_flag == VERTICAL_ALIGN_BOTTOM) {
 
                widget_orig.y += (size.y - widget_size.y);
                DBG_G << "Grid cell: vertically aligned at the bottom.\n";
 
        } else {
-               ERR_G << "Grid cell: No vertical alignment specified.\n";
+               ERR_G << "Grid cell: Invalid vertical alignment '" 
+                       << v_flag << "' specified.\n";
                assert(false);
        }
-       
-       if(flags_ & HORIZONTAL_GROW_SEND_TO_CLIENT) {
+
+       const unsigned h_flag = flags_ & HORIZONTAL_MASK;
+
+       if(h_flag == HORIZONTAL_GROW_SEND_TO_CLIENT) {
                if(maximum_size.x) {
                        widget_size.x = std::min(size.x, maximum_size.x);
                } else {
@@ -795,22 +802,23 @@
                DBG_G << "Grid cell: horizontal growing from " 
                        << best_size.x << " to " << widget_size.x << ".\n";
 
-       } else if((flags_ & HORIZONTAL_ALIGN_LEFT) == HORIZONTAL_ALIGN_LEFT) {
+       } else if(h_flag == HORIZONTAL_ALIGN_LEFT) {
                // Do nothing.
                DBG_G << "Grid cell: horizontally aligned at the left.\n";
 
-       } else if((flags_ & HORIZONTAL_ALIGN_CENTER) == 
HORIZONTAL_ALIGN_CENTER) {
+       } else if(h_flag == HORIZONTAL_ALIGN_CENTER) {
                
                widget_orig.x += (size.x - widget_size.x) / 2;
                DBG_G << "Grid cell: horizontally centred.\n";
 
-       } else if((flags_ & HORIZONTAL_ALIGN_RIGHT) == HORIZONTAL_ALIGN_RIGHT) {
+       } else if(h_flag == HORIZONTAL_ALIGN_RIGHT) {
 
                widget_orig.x += (size.x - widget_size.x);
                DBG_G << "Grid cell: horizontally aligned at the right.\n";
 
        } else {
-               ERR_G << "Grid cell: No horizontal alignment specified.\n";
+               ERR_G << "Grid cell: No horizontal alignment '"
+                       << h_flag << "' specified.\n";
                assert(false);
        }
 

Modified: trunk/src/gui/widgets/grid.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/grid.hpp?rev=29609&r1=29608&r2=29609&view=diff
==============================================================================
--- trunk/src/gui/widgets/grid.hpp (original)
+++ trunk/src/gui/widgets/grid.hpp Sun Sep 21 11:25:36 2008
@@ -41,11 +41,13 @@
        static const unsigned VERTICAL_ALIGN_TOP             = 2 << 0;   
        static const unsigned VERTICAL_ALIGN_CENTER          = 3 << 0;   
        static const unsigned VERTICAL_ALIGN_BOTTOM          = 4 << 0;   
+       static const unsigned VERTICAL_MASK                  = 7 << 0;   
 
        static const unsigned HORIZONTAL_GROW_SEND_TO_CLIENT = 1 << 3;
        static const unsigned HORIZONTAL_ALIGN_LEFT          = 2 << 3;   
        static const unsigned HORIZONTAL_ALIGN_CENTER        = 3 << 3;   
        static const unsigned HORIZONTAL_ALIGN_RIGHT         = 4 << 3;   
+       static const unsigned HORIZONTAL_MASK                = 7 << 3;   
 
        static const unsigned BORDER_TOP                     = 1 << 6;
        static const unsigned BORDER_BOTTOM                  = 1 << 7;

Modified: trunk/src/gui/widgets/window_builder.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/window_builder.cpp?rev=29609&r1=29608&r2=29609&view=diff
==============================================================================
--- trunk/src/gui/widgets/window_builder.cpp (original)
+++ trunk/src/gui/widgets/window_builder.cpp Sun Sep 21 11:25:36 2008
@@ -116,17 +116,30 @@
 {
        unsigned flags = 0;
 
-       // Read the flags. FIXME document.
-       flags |= get_v_align(cfg["vertical_alignment"]);
-       flags |= get_h_align(cfg["horizontal_alignment"]);
+       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_G_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_G_P << "horizontal_grow and horizontal_alignment "
+                               "can't be combined, alignment is ignored.\n";
+               }
+       } else {
+               flags |= h_flags;
        }
 
        return flags;
@@ -407,10 +420,12 @@
  *
  *     vertical_alignment (v_align = "")
  *                                     The vertical alignment of the widget in
- *                                     the grid cell.
+ *                                     the grid cell. (This value is ignored if
+ *                                     vertical_grow is true.)
  *     horizontal_alignment (h_align = "")
  *                                     The horizontal alignment of the widget 
in
- *                                     the grid cell.
+ *                                     the grid cell.(This value is ignored if
+ *                                     horizontal_grow is true.)
  *    
  *     vertical_grow (bool = false)    Does the widget grow in vertical
  *                                     direction when the grid cell grows in 
the


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

Reply via email to