Author: alink
Date: Wed Mar 25 01:24:53 2009
New Revision: 34111
URL: http://svn.gna.org/viewcvs/wesnoth?rev=34111&view=rev
Log:
Scan the base frame image to find the in_hex status instead of using a WML key.
Code is working but not activated yet, to continue to test the 1.6.1 version
Could also replace the in_hex key in 1.6.1, but it's more (too much?) new code
Modified:
trunk/src/image.cpp
trunk/src/image.hpp
trunk/src/sdl_utils.cpp
trunk/src/sdl_utils.hpp
trunk/src/unit_animation.cpp
Modified: trunk/src/image.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/image.cpp?rev=34111&r1=34110&r2=34111&view=diff
==============================================================================
--- trunk/src/image.cpp (original)
+++ trunk/src/image.cpp Wed Mar 25 01:24:53 2009
@@ -921,6 +921,19 @@
return res;
}
+bool is_in_hex(const locator& i_locator)
+{
+ const surface mask(get_image(game_config::terrain_mask_image,
UNSCALED));
+ const surface image(get_image(i_locator, UNSCALED));
+
+ bool res = in_mask_surface(image, mask);
+ //std::cout << "in_hex : " << i_locator.get_filename()
+ // << " " << (res ? "yes" : "no") << "\n";
+
+ return res;
+}
+
+
surface reverse_image(const surface& surf)
{
if(surf == NULL) {
Modified: trunk/src/image.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/image.hpp?rev=34111&r1=34110&r2=34111&view=diff
==============================================================================
--- trunk/src/image.hpp (original)
+++ trunk/src/image.hpp Wed Mar 25 01:24:53 2009
@@ -257,6 +257,10 @@
///SDL_FreeSurface()
surface get_image(const locator& i_locator, TYPE type=UNSCALED);
+ ///function to check if an image fit into an hex
+ ///return false if the image has not the standard size.
+ bool is_in_hex(const locator& i_locator);
+
///function to reverse an image. The image MUST have originally been
returned from
///an image:: function. Returned images have the same semantics as for
get_image()
///and must be freed using SDL_FreeSurface()
Modified: trunk/src/sdl_utils.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/sdl_utils.cpp?rev=34111&r1=34110&r2=34111&view=diff
==============================================================================
--- trunk/src/sdl_utils.cpp (original)
+++ trunk/src/sdl_utils.cpp Wed Mar 25 01:24:53 2009
@@ -992,6 +992,50 @@
//return create_optimized_surface(nsurf);
}
+bool in_mask_surface(surface const &surf, surface const &mask)
+{
+ if(surf == NULL || mask == NULL) {
+ return false;
+ }
+
+ if (surf->w != surf->w || surf->h != mask->h ) {
+ // not same size, consider it doesn't fit
+ return false;
+ }
+
+ surface nsurf = make_neutral_surface(surf);
+ surface nmask(make_neutral_surface(mask));
+
+ if(nsurf == NULL || nmask == NULL) {
+ std::cerr << "could not make neutral surface...\n";
+ return NULL;
+ }
+
+ {
+ surface_lock lock(nsurf);
+ surface_lock mlock(nmask);
+
+ Uint32* mbeg = mlock.pixels();
+ Uint32* mend = mbeg + nmask->w*nmask->h;
+ Uint32* beg = lock.pixels();
+ // no need for 'end', because both surfaces have same size
+
+ while(mbeg != mend) {
+ Uint8 malpha = (*mbeg) >> 24;
+ if(malpha == 0) {
+ Uint8 alpha = (*beg) >> 24;
+ if (alpha)
+ return false;
+ }
+ ++mbeg;
+ ++beg;
+ }
+ }
+
+ return true;
+}
+
+
surface blur_surface(surface const &surf, int depth, bool optimize)
{
if(surf == NULL) {
Modified: trunk/src/sdl_utils.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/sdl_utils.hpp?rev=34111&r1=34110&r2=34111&view=diff
==============================================================================
--- trunk/src/sdl_utils.hpp (original)
+++ trunk/src/sdl_utils.hpp Wed Mar 25 01:24:53 2009
@@ -232,6 +232,9 @@
/** Applies a mask on a surface. */
surface mask_surface(surface const &surf, surface const &mask);
+/** Check if a surface fit into a mask */
+bool in_mask_surface(surface const &surf, surface const &mask);
+
/** Cross-fades a surface. */
surface blur_surface(surface const &surf, int depth = 1, bool optimize=true);
Modified: trunk/src/unit_animation.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_animation.cpp?rev=34111&r1=34110&r2=34111&view=diff
==============================================================================
--- trunk/src/unit_animation.cpp (original)
+++ trunk/src/unit_animation.cpp Wed Mar 25 01:24:53 2009
@@ -309,13 +309,17 @@
animation_base.back().event_.clear();
}
}
+
+ const std::string& default_image_in_hex = cfg["in_hex"];
+ //const std::string& default_image_in_hex = is_in_hex(default_image) ?
"yes" : "no";
+
if( animation_base.empty() )
-
animation_base.push_back(unit_animation(0,frame_builder().image(default_image).duration(1).in_hex(cfg["in_hex"]),"",unit_animation::DEFAULT_ANIM));
+
animation_base.push_back(unit_animation(0,frame_builder().image(default_image).duration(1).in_hex(default_image_in_hex),"",unit_animation::DEFAULT_ANIM));
//the default standing anim when disbabled use the main in_hex key
-
animations.push_back(unit_animation(0,frame_builder().image(default_image).duration(1).in_hex(cfg["in_hex"]),"_disabled_",0));
+
animations.push_back(unit_animation(0,frame_builder().image(default_image).duration(1).in_hex(default_image_in_hex),"_disabled_",0));
animations.push_back(unit_animation(0,frame_builder().image(default_image).duration(1).
-
blend("0.0~0.3:100,0.3~0.0:200",display::rgb(255,255,255)).in_hex(cfg["in_hex"]),"_disabled_selected_",0));
+
blend("0.0~0.3:100,0.3~0.0:200",display::rgb(255,255,255)).in_hex(default_image_in_hex),"_disabled_selected_",0));
for(itor = animation_base.begin() ; itor != animation_base.end() ;
itor++ ) {
unit_animation tmp_anim = *itor;
// provide all default anims
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits