Add a gfx effect shadow_image() to create a dark, blurry shadow of a surface.

And use it for floatings labels. This fix the recent bug of having
colored shadows when using color markup there, and it allows new
optimization of this (combine blur, darkening and alpha change, and
reuse the foreground text)

No visible change.
This commit is contained in:
Ali El Gariani 2008-07-01 13:00:17 +00:00
parent ad221ad063
commit 7bdfb9bb65
3 changed files with 41 additions and 5 deletions

View File

@ -880,12 +880,8 @@ surface floating_label::create_surface()
}
else {
// background is blurred shadow of the text
// we don't parse markup here to guarantee a black shadow
// FIXME: using color mark-up will cause colored shadow
surface background = font::render_text(text_, font_size_, font::BLACK_COLOUR, 0, true);
//TODO add a little extra space for the blur of letters with a lower part
background = blur_alpha_surface(background, 2, false);
background = adjust_surface_alpha(background, ftofxp(4.0), false);
surface background = shadow_image(foreground, false);
if (background == NULL) {
ERR_FT << "could not create floating label's shadow" << std::endl;

View File

@ -635,6 +635,44 @@ surface darken_image(surface const &surf, bool optimize)
return optimize ? create_optimized_surface(nsurf) : nsurf;
}
surface shadow_image(surface const &surf, bool optimize)
{
if(surf == NULL)
return NULL;
// we blur it, and reuse the neutral surface created by the blur function (optimized = false)
surface nsurf (blur_alpha_surface(surf, 2, false));
if(nsurf == NULL) {
std::cerr << "failed to blur the shadow surface\n";
return NULL;
}
{
surface_lock lock(nsurf);
Uint32* beg = lock.pixels();
Uint32* end = beg + nsurf->w*surf->h;
while(beg != end) {
Uint8 alpha = (*beg) >> 24;
if(alpha) {
// increase alpha and color in black (RGB=0)
// with some stupid optimization for handling maximum values
if (alpha < 255/4)
*beg = (alpha*4) << 24;
else
*beg = 0xFF000000; // we hit the maximum
}
++beg;
}
}
return optimize ? create_optimized_surface(nsurf) : nsurf;
}
surface recolor_image(surface surf, const std::map<Uint32, Uint32>& map_rgb, bool optimize){
if(map_rgb.size()){
if(surf == NULL)

View File

@ -170,6 +170,8 @@ surface scale_surface_blended(surface const &surf, int w, int h, bool optimize=t
surface adjust_surface_colour(surface const &surf, int r, int g, int b, bool optimize=true);
surface greyscale_image(surface const &surf, bool optimize=true);
surface darken_image(surface const &surf, bool optimize=true);
/** create an heavy shadow of the image, by blurring, increasing alpha and darkening */
surface shadow_image(surface const &surf, bool optimize=true);
surface recolor_image(surface surf, const std::map<Uint32, Uint32>& map_rgb, bool optimize=true);
surface brighten_image(surface const &surf, fixed_t amount, bool optimize=true);