Author: shadowmaster
Date: Sat Aug 30 18:37:29 2008
New Revision: 29122
URL: http://svn.gna.org/viewcvs/wesnoth?rev=29122&view=rev
Log:
* Implement ~SECTION(x,y,w,h) imagepath function (feature / bug #12067).
There are some issues with this implementation - namely X and Y are
restricted positive because of limitations of the used cut_surface()
function- it cuts the width and height of the slice. This is not
possible to be overridden since the implementation uses memcpy
internappy. I need to write a cut_surface_ex() helper later.
Modified:
trunk/src/image.cpp
Modified: trunk/src/image.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/image.cpp?rev=29122&r1=29121&r2=29122&view=diff
==============================================================================
--- trunk/src/image.cpp (original)
+++ trunk/src/image.cpp Sat Aug 30 18:37:29 2008
@@ -355,6 +355,9 @@
bool xflip = false;
bool yflip = false;
bool greyscale = false;
+ bool slice = false;
+ SDL_Rect slice_rect = { 0,0,0,0 };
+
std::map<Uint32, Uint32> recolor_map;
std::vector<std::string> modlist =
utils::paranthetical_split(val_.modifications_,'~');
for(std::vector<std::string>::const_iterator i=modlist.begin();
@@ -410,6 +413,7 @@
}
}
}
+
if("FL" == function){ // Flip layer
if(field.empty() || field.find("horiz")
!= std::string::npos) {
xflip = !xflip;
@@ -418,12 +422,46 @@
yflip = !yflip;
}
}
- if("GS" == function){ // Flip layer
+
+ if("GS" == function){ // Grayscale image
greyscale=true;
}
+
+ if("SECTION" == function){ // Slice image
+ std::vector<std::string> const&
slice_params = utils::split(field, ',', utils::STRIP_SPACES);
+ if(slice_params.empty() != true) {
+ slice = true;
+ slice_rect.x =
lexical_cast_default<Sint16, const std::string&>(slice_params[0]);
+ if(slice_params.size() > 1)
+ slice_rect.y =
lexical_cast_default<Sint16, const std::string&>(slice_params[1]);
+ if(slice_params.size() > 2)
+ slice_rect.w =
lexical_cast_default<Uint16, const std::string&>(slice_params[2]);
+ if(slice_params.size() > 3)
+ slice_rect.h =
lexical_cast_default<Uint16, const std::string&>(slice_params[3]);
+ }
+ }
}
}
surf = recolor_image(surf,recolor_map);
+ if(slice) {
+ // yummy, a slice of surface! this needs to get done
+ // before any other geometric transformations
+ if(slice_rect.w == 0) {
+ slice_rect.w = surf->w;
+ }
+ if(slice_rect.h == 0) {
+ slice_rect.h = surf->h;
+ }
+ if(slice_rect.x < 0) {
+ ERR_DP << "start X coordinate of SECTION
function is negative - truncating to zero\n";
+ slice_rect.x = 0;
+ }
+ if(slice_rect.y < 0) {
+ ERR_DP << "start Y coordinate of SECTION
function is negative - truncating to zero\n";
+ slice_rect.y = 0;
+ }
+ surf = cut_surface(surf, slice_rect);
+ }
if(xflip) {
surf = flip_surface(surf);
}
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits