Author: mog
Date: Mon Apr 28 18:54:29 2008
New Revision: 26213

URL: http://svn.gna.org/viewcvs/wesnoth?rev=26213&view=rev
Log:
Add support for centering multihex terrain images using the center=(x,y) 
attribute.

Modified:
    trunk/src/builder.cpp
    trunk/src/builder.hpp
    trunk/src/image.cpp
    trunk/src/image.hpp

Modified: trunk/src/builder.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/builder.cpp?rev=26213&r1=26212&r2=26213&view=diff
==============================================================================
--- trunk/src/builder.cpp (original)
+++ trunk/src/builder.cpp Mon Apr 28 18:54:29 2008
@@ -48,12 +48,14 @@
  */
 static const int BASE_Y_INTERVAL = 100000;
 
-terrain_builder::rule_image::rule_image(int layer, int x, int y, bool 
global_image) :
+terrain_builder::rule_image::rule_image(int layer, int x, int y, bool 
global_image, int cx, int cy) :
        layer(layer),
        basex(x),
        basey(y),
        variants(),
-       global_image(global_image)
+       global_image(global_image),
+       center_x(cx),
+       center_y(cy)
 {}
 
 terrain_builder::tile::tile() :
@@ -306,7 +308,7 @@
                                                time = 100;
                                        }
                                        if(image->global_image) {
-                                               
image_vector.push_back(animated<image::locator>::frame_description(time,image::locator("terrain/"
 + str + ".png",constraint->second.loc)));
+                                               
image_vector.push_back(animated<image::locator>::frame_description(time,image::locator("terrain/"
 + str + ".png",constraint->second.loc, image->center_x, image->center_y)));
                                        } else {
                                                
image_vector.push_back(animated<image::locator>::frame_description(time,image::locator("terrain/"
 + str + ".png")));
                                        }
@@ -535,8 +537,17 @@
                        }
                }
 
-               images.push_back(rule_image(layer, basex - dx, basey - dy, 
global));
-
+               int center_x = -1, center_y = -1;
+               if( !(**img)["center"].empty()) {
+                       std::vector<std::string> center = 
utils::split((**img)["center"]);
+
+                       if(center.size() >= 2) {
+                               center_x = atoi(center[0].c_str());
+                               center_y = atoi(center[1].c_str());
+                       }
+               }
+
+               images.push_back(rule_image(layer, basex - dx, basey - dy, 
global, center_x, center_y));
 
                // Adds the main (default) variant of the image, if present
                images.back().variants.insert(std::pair<std::string, 
rule_image_variant>("", rule_image_variant(name,"")));

Modified: trunk/src/builder.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/builder.hpp?rev=26213&r1=26212&r2=26213&view=diff
==============================================================================
--- trunk/src/builder.hpp (original)
+++ trunk/src/builder.hpp Mon Apr 28 18:54:29 2008
@@ -169,7 +169,7 @@
         * The rule_image structure represents one such image.
         */
        struct rule_image {
-               rule_image(int layer, int x, int y, bool global_image=false);
+               rule_image(int layer, int x, int y, bool global_image=false, 
int center_x=-1, int center_y=-1);
 
                /** The layer of the image for horizontal layering */
                int layer;
@@ -186,6 +186,10 @@
                 * [terrain_graphics] tag, set to false if it was defined as a
                 * child of a [tile] tag */
                bool global_image;
+
+               /** The position where the center of the image base should be
+                */
+               int center_x, center_y;
        };
 
        /**

Modified: trunk/src/image.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/image.cpp?rev=26213&r1=26212&r2=26213&view=diff
==============================================================================
--- trunk/src/image.cpp (original)
+++ trunk/src/image.cpp Mon Apr 28 18:54:29 2008
@@ -186,6 +186,12 @@
        init_index();
 }
 
+    locator::locator(const std::string &filename, const gamemap::location 
&loc, int center_x, int center_y, const std::string& modifications) :
+        val_(filename, loc, center_x, center_y, modifications)
+{
+       init_index();
+}
+
 locator& locator::operator=(const locator &a)
 {
        index_ = a.index_;
@@ -196,7 +202,8 @@
 
 locator::value::value(const locator::value& a) :
   type_(a.type_), filename_(a.filename_), loc_(a.loc_),
-  modifications_(a.modifications_)
+  modifications_(a.modifications_), 
+  center_x_(a.center_x_), center_y_(a.center_y_)
 {
 }
 
@@ -228,6 +235,11 @@
 locator::value::value(const std::string& filename, const gamemap::location& 
loc, const std::string& modifications) :
   type_(SUB_FILE), filename_(filename), loc_(loc), 
modifications_(modifications)
 {
+}
+
+locator::value::value(const std::string& filename, const gamemap::location& 
loc, int center_x, int center_y, const std::string& modifications) :
+  type_(SUB_FILE), filename_(filename), loc_(loc), 
modifications_(modifications), center_x_(center_x), center_y_(center_y)
+{      
 }
 
 bool locator::value::operator==(const value& a) const
@@ -237,7 +249,8 @@
        } else if(type_ == FILE) {
                return filename_ == a.filename_;
        } else if(type_ == SUB_FILE) {
-         return filename_ == a.filename_ && loc_ == a.loc_ && modifications_ 
== a.modifications_;
+         return filename_ == a.filename_ && loc_ == a.loc_ && modifications_ 
== a.modifications_ 
+          && center_x_ == a.center_x_ && center_y_ == a.center_y_;
        } else {
                return false;
        }
@@ -254,6 +267,11 @@
                        return filename_ < a.filename_;
                if(loc_ != a.loc_)
                        return loc_ < a.loc_;
+        if(center_x_ != a.center_x_)
+            return center_x_ < a.center_x_;
+        if(center_y_ != a.center_y_)
+            return center_y_ < a.center_y_;
+
                return(modifications_ < a.modifications_);
        } else {
                return false;
@@ -298,7 +316,19 @@
                return surface(NULL);
 
        surface surf=mother_surface;
-       if(val_.loc_.x>-1 && val_.loc_.y>-1){
+       if(val_.loc_.x>-1 && val_.loc_.y>-1 && val_.center_x_>-1 && 
val_.center_y_>-1){
+               int offset_x = mother_surface->w/2 - val_.center_x_;
+               int offset_y = mother_surface->h/2 - val_.center_y_;
+               SDL_Rect srcrect = {
+                       ((tile_size*3) / 4) * val_.loc_.x + offset_x,
+                       tile_size * val_.loc_.y + (tile_size/2) * (val_.loc_.x 
% 2) + offset_y,
+                       tile_size, tile_size
+               };
+
+               surface tmp(cut_surface(mother_surface, srcrect));
+               surf=mask_surface(tmp, mask);
+       }
+       else if(val_.loc_.x>-1 && val_.loc_.y>-1 ){
          SDL_Rect srcrect = {
            ((tile_size*3) / 4) * val_.loc_.x,
            tile_size * val_.loc_.y + (tile_size/2) * (val_.loc_.x % 2),
@@ -308,6 +338,7 @@
          surface tmp(cut_surface(mother_surface, srcrect));
          surf=mask_surface(tmp, mask);
        }
+
 
        if(val_.modifications_.size()){
                bool xflip = false;

Modified: trunk/src/image.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/image.hpp?rev=26213&r1=26212&r2=26213&view=diff
==============================================================================
--- trunk/src/image.hpp (original)
+++ trunk/src/image.hpp Mon Apr 28 18:54:29 2008
@@ -67,6 +67,7 @@
                        value(const std::string& filename);
                     value(const std::string& filename, const std::string& 
modifications);
                        value(const std::string& filename, const 
gamemap::location& loc, const std::string& modifications);
+                       value(const std::string& filename, const 
gamemap::location& loc, int center_x, int center_y, const std::string& 
modifications);
 
                        bool operator==(const value& a) const;
                        bool operator<(const value& a) const;
@@ -75,6 +76,8 @@
                        std::string filename_;
                        gamemap::location loc_;
                        std::string modifications_;
+                       int center_x_;
+                       int center_y_;
                };
 
                // Constructing locators is somewhat slow, accessing image
@@ -88,6 +91,7 @@
                locator(const std::string& filename);
                locator(const std::string& filename, const std::string& 
modifications);
                locator(const std::string& filename, const gamemap::location& 
loc, const std::string& modifications="");
+               locator(const std::string& filename, const gamemap::location& 
loc, int center_x, int center_y, const std::string& modifications="");
 
                locator& operator=(const locator &a);
                bool operator==(const locator &a) const { return index_ == 
a.index_; }


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

Reply via email to