wesnoth-cvs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-cvs-commits] wesnoth ./changelog data/themes/default.cfg src...


From: Yann Dirson
Subject: [Wesnoth-cvs-commits] wesnoth ./changelog data/themes/default.cfg src...
Date: Sun, 05 Dec 2004 17:20:20 -0500

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     Yann Dirson <address@hidden>    04/12/05 22:14:04

Modified files:
        .              : changelog 
        data/themes    : default.cfg 
        src            : theme.cpp 

Log message:
        implemented ref= to specify explicit reference rect in relative 
positionning of theme elements (still one problem with finding an id in 
grand-children of [resolution] blocks); converted most of the 1024x768 theme to 
use them

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/changelog.diff?tr1=1.405&tr2=1.406&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/data/themes/default.cfg.diff?tr1=1.69&tr2=1.70&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/theme.cpp.diff?tr1=1.22&tr2=1.23&r1=text&r2=text

Patches:
Index: wesnoth/changelog
diff -u wesnoth/changelog:1.405 wesnoth/changelog:1.406
--- wesnoth/changelog:1.405     Sun Dec  5 19:28:46 2004
+++ wesnoth/changelog   Sun Dec  5 22:14:04 2004
@@ -1,4 +1,5 @@
 CVS HEAD:
+ * added support for specifying a reference rectangle when using 
relative-positionning syntax in themes
  * updated translation:
    * russian
  * fixed missing Deathblade in multiplayer
Index: wesnoth/data/themes/default.cfg
diff -u wesnoth/data/themes/default.cfg:1.69 
wesnoth/data/themes/default.cfg:1.70
--- wesnoth/data/themes/default.cfg:1.69        Tue Nov 30 00:38:21 2004
+++ wesnoth/data/themes/default.cfg     Sun Dec  5 22:14:04 2004
@@ -13,22 +13,59 @@
 width=1024
 height=768
 
+       [screen]
+       id=screen
+       rect=0,0,1024,768
+       [/screen]
+
+       [panel]
+       id=top-panel
+       image=misc/top-bg.png
+       ref=screen
+       rect==,=,=,+26
+       xanchor=top
+       yanchor=fixed
+       [/panel]
+
        [main_map]
-       rect=0,26,882,768
+       rect==,+0,882,768
        xanchor=left
        yanchor=top
        [/main_map]
 
+       # rightside panel
+       [panel]
+       id=top-right-panel
+       image=misc/rightside.png
+       rect=+0,=-1,1024,+284
+       xanchor=right
+       yanchor=fixed
+       [/panel]
+       [panel]
+       image=misc/rightside-bg.png
+       rect==,+0,=,+421
+       xanchor=right
+       yanchor=top
+       [/panel]
+       [panel]
+       image=misc/rightside-bottom.png
+       rect==,+0,=,768
+       xanchor=right
+       yanchor=bottom
+       [/panel]
+
        [menu]
        title= _ "Menu"
        image=lite
        
items=objectives,statistics,unitlist,separator,statustable,save,load,preferences,chatlog,help,quit
-       rect=3,1,+100,+21
+       ref=top-panel
+       rect==+3,=+1,+100,=-4
        xanchor=fixed
        yanchor=fixed
        [/menu]
 
        [menu]
+       id=actions-menu
        title= _ "Actions"
        image=lite
        
items=undo,redo,cycle,speak,recruit,recall,showenemymoves,bestenemymoves,delayshroud,updateshroud,endturn
@@ -41,39 +78,12 @@
        is_context_menu=true
        
items=undo,redo,describeunit,renameunit,createunit,changeside,labelterrain,speak,continue,recruit,recall,delayshroud,updateshroud,cycle,endturn
        [/menu]
-
-       # top panel
-       [panel]
-       image=misc/top-bg.png
-       rect=0,0,1024,26
-       xanchor=top
-       yanchor=fixed
-       [/panel]
-
-       # rightside panel
-       [panel]
-       image=misc/rightside.png
-       rect=882,25,1024,309
-       xanchor=right
-       yanchor=fixed
-       [/panel]
        [mini_map]
+       ref=top-right-panel
        rect==+10,=+7,=-7,175
        xanchor=right
        yanchor=fixed
        [/mini_map]
-       [panel]
-       image=misc/rightside-bg.png
-       rect=882,309,1024,730
-       xanchor=right
-       yanchor=top
-       [/panel]
-       [panel]
-       image=misc/rightside-bottom.png
-       rect==,730,0,768
-       xanchor=right
-       yanchor=bottom
-       [/panel]
 
        [menu]
        title= _ "End Turn"
@@ -84,36 +94,43 @@
        [/menu]
 
        [panel]
+       id=turn-panel
        image=misc/status-bg.png
-       rect=210,2,+95,+19
+       ref=actions-menu
+       rect=+5,=+1,+95,+19
        xanchor=proportional
        yanchor=fixed
        [/panel]
        [panel]
+       id=gold-panel
        image=misc/status-bg.png
        rect=+5,=,+95,=
        xanchor=proportional
        yanchor=fixed
        [/panel]
        [panel]
+       id=villages-panel
        image=misc/status-bg.png
        rect=+5,=,+85,=
        xanchor=proportional
        yanchor=fixed
        [/panel]
        [panel]
+       id=units-panel
        image=misc/status-bg.png
        rect=+5,=,+85,=
        xanchor=proportional
        yanchor=fixed
        [/panel]
        [panel]
+       id=upkeep-panel
        image=misc/status-bg.png
        rect=+5,=,+85,=
        xanchor=proportional
        yanchor=fixed
        [/panel]
        [panel]
+       id=income-panel
        image=misc/status-bg.png
        rect=+5,=,+85,=
        xanchor=proportional
@@ -136,43 +153,48 @@
        yanchor=fixed
        [/label]
 
-       # gold icon
        [label]
+       id=gold-icon
        icon=misc/gold.png
        text= _ "gold"
-       rect=315,3,+16,+16
+       ref=gold-panel
+       rect==+5,=+1,+16,+16
        xanchor=proportional
        yanchor=fixed
        [/label]
-       # villages icon
        [label]
+       id=villages-icon
        icon=misc/villages.png
        text= _ "villages"
-       rect=415,3,+16,+16
+       ref=villages-panel
+       rect==+5,=+1,+16,+16
        xanchor=proportional
        yanchor=fixed
        [/label]
-       # units icon
        [label]
+       id=units-icon
        icon=misc/units.png
        text= _ "units"
-       rect=505,3,+16,+16
+       ref=units-panel
+       rect==+5,=+1,+16,+16
        xanchor=proportional
        yanchor=fixed
        [/label]
-       # upkeep icon
        [label]
+       id=upkeep-icon
        icon=misc/upkeep.png
        text= _ "upkeep"
-       rect=595,3,+32,+16
+       ref=upkeep-panel
+       rect==+5,=+1,+32,+16
        xanchor=proportional
        yanchor=fixed
        [/label]
-       # income icon
        [label]
+       id=income-icon
        icon=misc/income.png
        text= _ "income"
-       rect=685,3,+32,+16
+       ref=income-panel
+       rect==+5,=+1,+32,+16
        xanchor=proportional
        yanchor=fixed
        [/label]
@@ -185,16 +207,10 @@
                yanchor=fixed
                [/time_of_day]
 
-               [observers]
-               font_size=12
-               rect=1004,3,+16,+16
-               xanchor=proportional
-               yanchor=fixed
-               [/observers]
-
                #put the side playing indicator next to the turn indicator
                [side_playing]
-               rect=213,4,+15,+16
+               ref=turn-panel
+               rect==+3,=+2,+15,+16
                xanchor=proportional
                yanchor=fixed
                [/side_playing]
@@ -202,7 +218,7 @@
                # the game status
                [turn]
                font_size=12
-               rect=232,4,+68,+16
+               rect=+4,=,+68,+16
                xanchor=proportional
                yanchor=fixed
                prefix=
@@ -210,7 +226,8 @@
                [/turn]
                [gold]
                font_size=12
-               rect=335,4,+65,+16
+               ref=gold-icon
+               rect=+4,=,+65,+16
                xanchor=proportional
                yanchor=fixed
                prefix=
@@ -218,7 +235,8 @@
                [/gold]
                [villages]
                font_size=12
-               rect=435,4,+55,+16
+               ref=villages-icon
+               rect=+4,=,+55,+16
                xanchor=proportional
                yanchor=fixed
                prefix=
@@ -226,7 +244,8 @@
                [/villages]
                [num_units]
                font_size=12
-               rect=525,4,+55,+16
+               ref=units-icon
+               rect=+4,=,+55,+16
                xanchor=proportional
                yanchor=fixed
                prefix=
@@ -234,7 +253,8 @@
                [/num_units]
                [upkeep]
                font_size=12
-               rect=630,4,+40,+16
+               ref=upkeep-icon
+               rect=+4,=,+40,+16
                xanchor=proportional
                yanchor=fixed
                prefix=
@@ -242,7 +262,8 @@
                [/upkeep]
                [income]
                font_size=12
-               rect=720,4,+40,+16
+               ref=income-icon
+               rect=+4,=,+40,+16
                xanchor=proportional
                yanchor=fixed
                prefix=
@@ -250,17 +271,26 @@
                [/income]
                [terrain]
                font_size=12
-               rect=770,4,+120,+16
+               rect=+5,=,+120,+16
                xanchor=proportional
                yanchor=fixed
                [/terrain]
                [position]
+               id=position-text
                font_size=12
-               rect=895,4,+105,+16
+               rect=+5,=,+105,+16
                xanchor=proportional
                yanchor=fixed
                [/position]
 
+               [observers]
+               font_size=12
+               ref=position-text
+               rect=+4,=-1,+16,+16
+               xanchor=proportional
+               yanchor=fixed
+               [/observers]
+
                #unit stats here
                [unit_image]
                rect=891,235,+72,+72
@@ -343,18 +373,50 @@
                yanchor=fixed
                [/unit_weapons]
        [/status]
+
+       [dummy]
+               id=dummy2
+       [/dummy]
 [/resolution]
 
 [resolution]
 width=800
 height=600
 
+       # top panel
+       [panel]
+       image=misc/top-bg.png
+       rect=0,0,1024,26
+       xanchor=top
+       yanchor=fixed
+       [/panel]
+
        [main_map]
        rect=0,26,882,768
        xanchor=left
        yanchor=top
        [/main_map]
 
+       # rightside panel
+       [panel]
+       image=misc/rightside.png
+       rect=882,25,1024,309
+       xanchor=right
+       yanchor=fixed
+       [/panel]
+       [panel]
+       image=misc/rightside-bg.png
+       rect=882,309,1024,730
+       xanchor=right
+       yanchor=top
+       [/panel]
+       [panel]
+       image=misc/rightside-bottom.png
+       rect=882,730,0,768
+       xanchor=right
+       yanchor=bottom
+       [/panel]
+
        [menu]
        title= _ "Menu"
        image=lite
@@ -377,39 +439,11 @@
        is_context_menu=true
        
items=undo,redo,describeunit,renameunit,createunit,changeside,labelterrain,speak,continue,recruit,recall,delayshroud,updateshroud,cycle,endturn
        [/menu]
-
-       # top panel
-       [panel]
-       image=misc/top-bg.png
-       rect=0,0,1024,26
-       xanchor=top
-       yanchor=fixed
-       [/panel]
-
-       # rightside panel
-       [panel]
-       image=misc/rightside.png
-       rect=882,25,1024,309
-       xanchor=right
-       yanchor=fixed
-       [/panel]
        [mini_map]
        rect=892,32,1017,175
        xanchor=right
        yanchor=fixed
        [/mini_map]
-       [panel]
-       image=misc/rightside-bg.png
-       rect=882,309,1024,730
-       xanchor=right
-       yanchor=top
-       [/panel]
-       [panel]
-       image=misc/rightside-bottom.png
-       rect=882,730,0,768
-       xanchor=right
-       yanchor=bottom
-       [/panel]
 
        [menu]
        title= _ "End Turn"
@@ -687,12 +721,42 @@
 width=320
 height=240
 
+       # top panel
+       [panel]
+       image=misc/top-bg.png
+       rect=0,0,1024,13
+       xanchor=top
+       yanchor=fixed
+       [/panel]
+
        [main_map]
        rect=0,13,946,768
        xanchor=left
        yanchor=top
        [/main_map]
 
+       # rightside panel
+       [panel]
+       image=misc/rightside.png
+       rect=946,25,1024,150
+       xanchor=right
+       yanchor=fixed
+       [/panel]
+       [panel]
+       image=misc/rightside-bg.png
+       rect=946,150,1024,768
+       xanchor=right
+       yanchor=top
+       [/panel]
+[comment]
+       [panel]
+       image=misc/rightside-bottom.png
+       rect=946,752,0,768
+       xanchor=right
+       yanchor=bottom
+       [/panel]
+[/comment]
+
        [menu]
        title= _ "Menu"
        image=lite
@@ -716,42 +780,12 @@
        
items=undo,redo,describeunit,renameunit,createunit,changeside,labelterrain,speak,continue,recruit,recall,delayshroud,updateshroud,cycle,endturn
        [/menu]
 
-       # top panel
-       [panel]
-       image=misc/top-bg.png
-       rect=0,0,1024,13
-       xanchor=top
-       yanchor=fixed
-       [/panel]
-
-       # rightside panel
-       [panel]
-       image=misc/rightside.png
-       rect=946,25,1024,150
-       xanchor=right
-       yanchor=fixed
-       [/panel]
        [mini_map]
        rect=951,28,1020,92
        xanchor=right
        yanchor=fixed
        [/mini_map]
 
-       [panel]
-       image=misc/rightside-bg.png
-       rect=946,150,1024,768
-       xanchor=right
-       yanchor=top
-       [/panel]
-[comment]
-       [panel]
-       image=misc/rightside-bottom.png
-       rect=946,752,0,768
-       xanchor=right
-       yanchor=bottom
-       [/panel]
-[/comment]
-
        [menu]
        title= _ "End Turn"
        items=endturn
Index: wesnoth/src/theme.cpp
diff -u wesnoth/src/theme.cpp:1.22 wesnoth/src/theme.cpp:1.23
--- wesnoth/src/theme.cpp:1.22  Tue Nov 30 00:11:23 2004
+++ wesnoth/src/theme.cpp       Sun Dec  5 22:14:04 2004
@@ -19,6 +19,9 @@
 
        const size_t DefaultFontSize = font::SIZE_NORMAL;
 
+       typedef struct { size_t x1,y1,x2,y2; } _rect;
+       _rect ref_rect = { 0, 0, 0, 0 };
+
        size_t compute(std::string expr, size_t ref1, size_t ref2=0 ) {
                size_t ref = 0;
                if (expr[0] == '=') {
@@ -31,27 +34,36 @@
                return ref + atoi(expr.c_str());
        }
 
-       SDL_Rect read_rect(const config& cfg) {
-               SDL_Rect rect;
+       _rect read_rect(const config& cfg) {
+               _rect rect;
                const std::vector<std::string> items = 
config::split(cfg["rect"].c_str());
                if(items.size() >= 1)
-                       rect.x = atoi(items[0].c_str());
+                       rect.x1 = atoi(items[0].c_str());
 
                if(items.size() >= 2)
-                       rect.y = atoi(items[1].c_str());
+                       rect.y1 = atoi(items[1].c_str());
 
                if(items.size() >= 3)
-                       rect.w = atoi(items[2].c_str()) - rect.x;
+                       rect.x2 = atoi(items[2].c_str());
 
                if(items.size() >= 4)
-                       rect.h = atoi(items[3].c_str()) - rect.y;
+                       rect.y2 = atoi(items[3].c_str());
 
                return rect;
        }
 
+       SDL_Rect read_sdl_rect(const config& cfg) {
+               SDL_Rect sdlrect;
+               const _rect rect = read_rect(cfg);
+               sdlrect.x = rect.x1;
+               sdlrect.y = rect.y1;
+               sdlrect.w = rect.x2 - rect.x1;
+               sdlrect.h = rect.y2 - rect.y1;
+
+               return sdlrect;
+       }
+
        std::string resolve_rect(const std::string& rect_str) {
-               typedef struct { size_t x1,y1,x2,y2; } _rect;
-               static _rect ref_rect = { 0, 0, 0, 0 };
                _rect rect;
                std::stringstream resolved;
                const std::vector<std::string> items = 
config::split(rect_str.c_str());
@@ -78,18 +90,58 @@
                return resolved.str();
        }
 
-       config& resolve_rects(const config& cfg) {
+       const config find_ref(const std::string& id, const config& resol_cfg) {
+               for(config::all_children_iterator i = resol_cfg.ordered_begin();
+                   i != resol_cfg.ordered_end(); i++) {
+                       //std::cerr << "Looking at " << *(*i).first << " " << 
(*(*i).second)["id"] << "\n";
+                       if ((*(*i).second)["id"] == id) {
+                               //std::cerr << "Found a " << *(*i).first << 
"\n";
+                               return *(*i).second;
+                       }
+                       // recursively look in children
+                       //std::cerr << "Looking in " << *(*i).first << " " << 
(*(*i).second)["id"] << "\n";
+                       const config c = find_ref(id, *(*i).second);
+                       if (!c["id"].empty()) {
+                               return c;
+                       }
+               }
+               // not found
+               return config();
+       }
+
+       config& resolve_rects(const config& cfg, config* resol_cfg = NULL, bool 
is_resolution = false) {
                config* newcfg = new config();
+
+               // recursively resolve children
                for(config::all_children_iterator i = cfg.ordered_begin(); i != 
cfg.ordered_end(); ++i) {
                        const std::pair<const std::string*,const config*>& 
value = *i;
-                       
newcfg->add_child(*value.first,resolve_rects(*value.second));
+                       newcfg->add_child(*value.first,
+                                         resolve_rects(*value.second,
+                                                       is_resolution ? newcfg 
: resol_cfg,
+                                                       
(*value.first=="resolution") ? true : false));
                }
 
+               // copy all key/values
                for(string_map::const_iterator j = cfg.values.begin(); j != 
cfg.values.end(); ++j) {
                        newcfg->values[j->first] = j->second;
                }
 
-               if (cfg["rect"] != "") {
+               // override default reference rect with "ref" parameter if any
+               if (!cfg["ref"].empty()) {
+                       //std::cerr << ">> Looking for " << cfg["ref"] << "\n";
+                       const config ref = find_ref (cfg["ref"], *resol_cfg);
+
+                       if (ref["id"].empty()) {
+                               std::cerr << "Reference to non-existent rect id 
\"" << cfg["ref"] << "\"\n";
+                       } else if (ref["rect"].empty()) {
+                               std::cerr << "Reference to id \"" << cfg["ref"] 
<<
+                                       "\" which does not have a \"rect\"\n";
+                       } else {
+                               ref_rect = read_rect(ref);
+                       }
+               }
+               // resolve the rect value to absolute coordinates
+               if (!cfg["rect"].empty()) {
                        newcfg->values["rect"] = resolve_rect(cfg["rect"]);
                }
 
@@ -103,7 +155,7 @@
 {}
 
 theme::object::object(const config& cfg)
-                   : loc_(read_rect(cfg)), relative_loc_(empty_rect),
+                   : loc_(read_sdl_rect(cfg)), relative_loc_(empty_rect),
                                     last_screen_(empty_rect),
                      xanchor_(read_anchor(cfg["xanchor"])),
                                         yanchor_(read_anchor(cfg["yanchor"]))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]