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

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

[Wesnoth-cvs-commits] wesnoth/src font.cpp font.hpp map_label.cpp sdl...


From: Philippe Plantier
Subject: [Wesnoth-cvs-commits] wesnoth/src font.cpp font.hpp map_label.cpp sdl...
Date: Sat, 30 Oct 2004 09:23:29 -0400

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     Philippe Plantier <address@hidden>      04/10/30 13:18:05

Modified files:
        src            : font.cpp font.hpp map_label.cpp sdl_utils.cpp 
                         sdl_utils.hpp 

Log message:
        Added shadows under labels, so they can be visible on each type of 
terrain, light or dark.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/font.cpp.diff?tr1=1.88&tr2=1.89&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/font.hpp.diff?tr1=1.44&tr2=1.45&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/map_label.cpp.diff?tr1=1.13&tr2=1.14&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/sdl_utils.cpp.diff?tr1=1.60&tr2=1.61&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/sdl_utils.hpp.diff?tr1=1.46&tr2=1.47&r1=text&r2=text

Patches:
Index: wesnoth/src/font.cpp
diff -u wesnoth/src/font.cpp:1.88 wesnoth/src/font.cpp:1.89
--- wesnoth/src/font.cpp:1.88   Sat Oct 30 11:50:30 2004
+++ wesnoth/src/font.cpp        Sat Oct 30 13:18:04 2004
@@ -1,4 +1,4 @@
-/* $Id: font.cpp,v 1.88 2004/10/30 11:50:30 gruikya Exp $ */
+/* $Id: font.cpp,v 1.89 2004/10/30 13:18:04 gruikya Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -733,11 +733,12 @@
 {
 public:
        floating_label(const std::string& text, int font_size, const SDL_Color& 
colour, const SDL_Color& bgcolour,
-               double xpos, double ypos, double xmove, double ymove, int 
lifetime, const SDL_Rect& clip_rect, font::ALIGN align,
-               int border_size, bool scroll_with_map)
-                 : surf_(NULL), buf_(NULL), foreground_(NULL), text_(text), 
font_size_(font_size), colour_(colour), bgcolour_(bgcolour), 
bgalpha_(bgcolour.unused), xpos_(xpos), ypos_(ypos),
-                   xmove_(xmove), ymove_(ymove), lifetime_(lifetime), 
clip_rect_(clip_rect),
-                       alpha_change_(-255/lifetime), visible_(true), 
align_(align), border_(border_size), scroll_(scroll_with_map)
+                       double xpos, double ypos, double xmove, double ymove, 
int lifetime, const SDL_Rect& clip_rect,
+                       font::ALIGN align, int border_size, bool 
scroll_with_map)
+               : surf_(NULL), buf_(NULL), foreground_(NULL), text_(text), 
font_size_(font_size), colour_(colour),
+               bgcolour_(bgcolour), bgalpha_(bgcolour.unused), xpos_(xpos), 
ypos_(ypos),
+               xmove_(xmove), ymove_(ymove), lifetime_(lifetime), 
clip_rect_(clip_rect),
+               alpha_change_(-255/lifetime), visible_(true), align_(align), 
border_(border_size), scroll_(scroll_with_map)
        {}
 
        void move(double xmove, double ymove);
@@ -801,15 +802,15 @@
 surface floating_label::create_surface()
 {
        if (surf_.null()) {
-               surf_ = font::render_text(get_font(font_size_), text_, colour_, 
0);
+               foreground_ = font::render_text(get_font(font_size_), text_, 
colour_, 0);
 
-               if(surf_ == NULL) {
+               if(foreground_ == NULL) {
                        return NULL;
                }
 
                //if the surface has to be created onto some kind of 
background, then do that here
                if(bgalpha_ != 0) {
-                       surface 
tmp(create_compatible_surface(surf_,surf_->w+border_*2,surf_->h+border_*2));
+                       surface 
tmp(create_compatible_surface(foreground_,foreground_->w+border_*2,foreground_->h+border_*2));
                        if(tmp == NULL) {
                                return NULL;
                        }
@@ -822,9 +823,15 @@
                                }
                        }
 
-                       foreground_.assign(surf_);
                        surf_.assign(tmp);
+               } else {
+                       surface background = 
font::render_text(get_font(font_size_), text_, font::BLACK_COLOUR, 0);
+                       background = blur_surface(background,4);
+                       background = adjust_surface_alpha(background, 4);
+
+                       surf_.assign(background);
                }
+
        }
 
        return surf_;
@@ -897,8 +904,8 @@
 
 namespace font {
 int add_floating_label(const std::string& text, int font_size, const 
SDL_Color& colour,
-                                          double xpos, double ypos, double 
xmove, double ymove, int lifetime, const SDL_Rect& clip_rect, ALIGN align,
-                                          const SDL_Color* bg_colour, int 
border_size, LABEL_SCROLL_MODE scroll_mode)
+               double xpos, double ypos, double xmove, double ymove, int 
lifetime, const SDL_Rect& clip_rect, ALIGN align,
+               const SDL_Color* bg_colour, int border_size, LABEL_SCROLL_MODE 
scroll_mode)
 {
        if(label_contexts.empty()) {
                return 0;
Index: wesnoth/src/font.hpp
diff -u wesnoth/src/font.hpp:1.44 wesnoth/src/font.hpp:1.45
--- wesnoth/src/font.hpp:1.44   Mon Oct  4 23:34:51 2004
+++ wesnoth/src/font.hpp        Sat Oct 30 13:18:04 2004
@@ -1,4 +1,4 @@
-/* $Id: font.hpp,v 1.44 2004/10/04 23:34:51 ydirson Exp $ */
+/* $Id: font.hpp,v 1.45 2004/10/30 13:18:04 gruikya Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -149,8 +149,10 @@
 ///
 /// @returns a handle to the label which can be used with other label functions
 int add_floating_label(const std::string& text, int font_size, const 
SDL_Color& colour,
-                                          double xpos, double ypos, double 
xmove, double ymove, int lifetime, const SDL_Rect& clip_rect, ALIGN 
alignment=CENTER_ALIGN,
-                                          const SDL_Color* bg_colour=NULL, int 
border_size=0, LABEL_SCROLL_MODE scroll_mode=ANCHOR_LABEL_SCREEN);
+               double xpos, double ypos, double xmove, double ymove, int 
lifetime,
+               const SDL_Rect& clip_rect, ALIGN alignment=CENTER_ALIGN,
+               const SDL_Color* bg_colour=NULL, int border_size=0, 
+               LABEL_SCROLL_MODE scroll_mode=ANCHOR_LABEL_SCREEN);
 
 /// moves the floating label given by 'handle' by (xmove,ymove)
 void move_floating_label(int handle, double xmove, double ymove);
Index: wesnoth/src/map_label.cpp
diff -u wesnoth/src/map_label.cpp:1.13 wesnoth/src/map_label.cpp:1.14
--- wesnoth/src/map_label.cpp:1.13      Wed Oct 27 19:28:07 2004
+++ wesnoth/src/map_label.cpp   Sat Oct 30 13:18:04 2004
@@ -80,11 +80,13 @@
 
        SDL_Color colour = font::NORMAL_COLOUR;
 
+#if 0
        if(map_.get_terrain_info(map_.get_terrain(loc)).is_light()) {
                colour.r = 0;
                colour.g = 0;
                colour.b = 0;
        }
+#endif
 
        const gamemap::location loc_nextx(loc.x+1,loc.y);
        const gamemap::location loc_nexty(loc.x,loc.y+1);
Index: wesnoth/src/sdl_utils.cpp
diff -u wesnoth/src/sdl_utils.cpp:1.60 wesnoth/src/sdl_utils.cpp:1.61
--- wesnoth/src/sdl_utils.cpp:1.60      Thu Oct 14 09:27:22 2004
+++ wesnoth/src/sdl_utils.cpp   Sat Oct 30 13:18:04 2004
@@ -1,4 +1,4 @@
-/* $Id: sdl_utils.cpp,v 1.60 2004/10/14 09:27:22 gakusho Exp $ */
+/* $Id: sdl_utils.cpp,v 1.61 2004/10/30 13:18:04 gruikya Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -429,6 +429,90 @@
        //return create_optimized_surface(nsurf);
 }
 
+// Cross-fades a surface
+surface blur_surface(surface surf, int depth)
+{
+       if(surf == NULL) {
+               return NULL;
+       }
+
+       surface nsurf = make_neutral_surface(surf);
+       surface res = create_compatible_surface(nsurf, surf->w, surf->h);
+       
+       if(nsurf == NULL || res == NULL) {
+               std::cerr << "could not make neutral surface...\n";
+               return NULL;
+       }
+
+       for(int count = 0; count < depth; ++count) {
+               surface_lock lock(nsurf);
+               surface_lock rlock(res);
+
+               {
+                       Uint32* p = lock.pixels();
+                       Uint32* left = p - 1;
+                       Uint32* right = p + 1;
+                       Uint32* top = p - res->w;
+                       Uint32* bottom = p + res->w;
+                       Uint32* rp = rlock.pixels();
+
+                       for(int y = 0; y < res->h; ++y) {
+                               for(int x = 0; x < res->w; ++x) {
+                                       Uint8 red, green, blue, alpha;
+                                       Uint16 rred=0, rgreen=0, rblue=0, 
ralpha=0;
+
+                                       if (x != 0) {
+                                               SDL_GetRGBA(*left, 
nsurf->format, &red, &green, &blue, &alpha);
+                                               rred += red;
+                                               rgreen += green;
+                                               rblue += blue;
+                                               ralpha += alpha;
+                                       }
+
+                                       if (x != res->w - 1) {
+                                               SDL_GetRGBA(*right, 
nsurf->format, &red, &green, &blue, &alpha);
+                                               rred += red;
+                                               rgreen += green;
+                                               rblue += blue;
+                                               ralpha += alpha;
+                                       }
+
+                                       if (y != 0) {
+                                               SDL_GetRGBA(*top, 
nsurf->format, &red, &green, &blue, &alpha);
+                                               rred += red;
+                                               rgreen += green;
+                                               rblue += blue;
+                                               ralpha += alpha;
+                                       }
+
+                                       if (y != res->h - 1) {
+                                               SDL_GetRGBA(*bottom, 
nsurf->format, &red, &green, &blue, &alpha);
+                                               rred += red;
+                                               rgreen += green;
+                                               rblue += blue;
+                                               ralpha += alpha;
+                                       }
+
+                                       rred /= 4;
+                                       rgreen /= 4;
+                                       rblue /= 4;
+                                       ralpha /= 4;
+
+                                       *rp = SDL_MapRGBA(res->format, 
(Uint8)rred, (Uint8)rgreen, (Uint8)rblue, (Uint8)ralpha);
+
+                                       ++left; ++right; ++top; ++bottom; ++rp;
+                               }
+                       }
+               }
+
+               if (count < depth - 1) {
+                       nsurf = res;
+               }
+       }
+
+       return create_optimized_surface(res);
+}
+
 // Cuts a rectangle from a surface.
 surface cut_surface(surface surf, const SDL_Rect& r)
 {
Index: wesnoth/src/sdl_utils.hpp
diff -u wesnoth/src/sdl_utils.hpp:1.46 wesnoth/src/sdl_utils.hpp:1.47
--- wesnoth/src/sdl_utils.hpp:1.46      Thu Oct  7 01:47:34 2004
+++ wesnoth/src/sdl_utils.hpp   Sat Oct 30 13:18:04 2004
@@ -1,4 +1,4 @@
-/* $Id: sdl_utils.hpp,v 1.46 2004/10/07 01:47:34 Sirp Exp $ */
+/* $Id: sdl_utils.hpp,v 1.47 2004/10/30 13:18:04 gruikya Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -106,6 +106,7 @@
 surface adjust_surface_alpha(surface surface, double amount);
 surface adjust_surface_alpha_add(surface surface, int amount);
 surface mask_surface(surface surf, surface mask);
+surface blur_surface(surface surf, int depth=1);
 surface cut_surface(surface surface, const SDL_Rect& r);
 surface blend_surface(surface surface, double amount, Uint32 colour);
 surface flip_surface(surface surface);




reply via email to

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