From ca65a4babe2341f4c9b8952cfd516df8d74575e4 Mon Sep 17 00:00:00 2001 From: Ricardo Cruz Date: Wed, 15 Sep 2004 18:47:45 +0000 Subject: [PATCH] Added an alpha argument for drawing fonts. SVN-Revision: 1918 --- lib/video/drawing_context.cpp | 10 ++++++---- lib/video/drawing_context.h | 5 +++-- lib/video/font.cpp | 16 ++++++++-------- lib/video/font.h | 6 +++--- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/lib/video/drawing_context.cpp b/lib/video/drawing_context.cpp index ea1020fec..0019ff542 100644 --- a/lib/video/drawing_context.cpp +++ b/lib/video/drawing_context.cpp @@ -78,7 +78,7 @@ DrawingContext::draw_surface_part(const Surface* surface, const Vector& source, void DrawingContext::draw_text(Font* font, const std::string& text, - const Vector& position, int layer, Uint32 drawing_effect) + const Vector& position, int layer, Uint32 drawing_effect, int alpha) { DrawingRequest request; @@ -91,6 +91,7 @@ DrawingContext::draw_text(Font* font, const std::string& text, textrequest->font = font; textrequest->text = text; textrequest->center = false; + textrequest->alpha = alpha; request.request_data = textrequest; drawingrequests.push_back(request); @@ -98,7 +99,7 @@ DrawingContext::draw_text(Font* font, const std::string& text, void DrawingContext::draw_text_center(Font* font, const std::string& text, - const Vector& position, int layer, Uint32 drawing_effect) + const Vector& position, int layer, Uint32 drawing_effect, int alpha) { DrawingRequest request; @@ -111,6 +112,7 @@ DrawingContext::draw_text_center(Font* font, const std::string& text, textrequest->font = font; textrequest->text = text; textrequest->center = true; + textrequest->alpha = alpha; request.request_data = textrequest; drawingrequests.push_back(request); @@ -218,9 +220,9 @@ DrawingContext::draw_text(DrawingRequest& request) TextRequest* textrequest = (TextRequest*) request.request_data; if(textrequest->center) - textrequest->font->draw_center(textrequest->text, request.pos, request.drawing_effect); + textrequest->font->draw_center(textrequest->text, request.pos, request.drawing_effect, textrequest->alpha); else - textrequest->font->draw(textrequest->text, request.pos, request.drawing_effect); + textrequest->font->draw(textrequest->text, request.pos, request.drawing_effect, textrequest->alpha); delete textrequest; } diff --git a/lib/video/drawing_context.h b/lib/video/drawing_context.h index 3c2b6eaff..c52e40f75 100644 --- a/lib/video/drawing_context.h +++ b/lib/video/drawing_context.h @@ -67,10 +67,10 @@ namespace SuperTux Uint32 drawing_effect = NONE_EFFECT); /// Draws a text. void draw_text(Font* font, const std::string& text, const Vector& position, - int layer, Uint32 drawing_effect = NONE_EFFECT); + int layer, Uint32 drawing_effect = NONE_EFFECT, int alpha = 255); /// Draws aligned text. void draw_text_center(Font* font, const std::string& text, - const Vector& position, int layer, Uint32 drawing_effect = NONE_EFFECT); + const Vector& position, int layer, Uint32 drawing_effect = NONE_EFFECT, int alpha = 255); /// Draws a color gradient onto the whole screen */ void draw_gradient(Color from, Color to, int layer); /// Fills a rectangle. @@ -130,6 +130,7 @@ namespace SuperTux Font* font; std::string text; bool center; + int alpha; }; struct GradientRequest diff --git a/lib/video/font.cpp b/lib/video/font.cpp index f6a3254bc..f132ec635 100644 --- a/lib/video/font.cpp +++ b/lib/video/font.cpp @@ -114,17 +114,17 @@ Font::get_height() const } void -Font::draw(const std::string& text, const Vector& pos, Uint32 drawing_effect) +Font::draw(const std::string& text, const Vector& pos, Uint32 drawing_effect, int alpha) { if(shadowsize > 0) draw_chars(shadow_chars, text, pos + Vector(shadowsize, shadowsize), - drawing_effect); + drawing_effect, alpha); - draw_chars(chars, text, pos, drawing_effect); + draw_chars(chars, text, pos, drawing_effect, alpha); } void -Font::draw_center(const std::string& text, const Vector& pos, Uint32 drawing_effect) +Font::draw_center(const std::string& text, const Vector& pos, Uint32 drawing_effect, int alpha) { /* Cut lines changes into seperate strings, needed to support centering text with break lines. @@ -140,12 +140,12 @@ Font::draw_center(const std::string& text, const Vector& pos, Uint32 drawing_eff { temp[text.copy(temp, text.size() - i, i)] = '\0'; draw(temp, Vector(screen->w/2 - get_text_width(temp)/2 + pos.x, pos.y + y), - drawing_effect); + drawing_effect, alpha); break; } temp[text.copy(temp, l - i, i)] = '\0'; draw(temp, Vector(screen->w/2 - get_text_width(temp)/2 + pos.x, pos.y + y), - drawing_effect); + drawing_effect, alpha); i = l+1; y += h + 2; @@ -154,7 +154,7 @@ Font::draw_center(const std::string& text, const Vector& pos, Uint32 drawing_eff void Font::draw_chars(Surface* pchars, const std::string& text, const Vector& pos, - Uint32 drawing_effect) + Uint32 drawing_effect, int alpha) { SurfaceImpl* impl = pchars->impl; @@ -179,7 +179,7 @@ Font::draw_chars(Surface* pchars, const std::string& text, const Vector& pos, int source_x = (index % 16) * w; int source_y = (index / 16) * h; - impl->draw_part(source_x, source_y, p.x, p.y, w, h, 255, drawing_effect); + impl->draw_part(source_x, source_y, p.x, p.y, w, h, alpha, drawing_effect); p.x += w; } } diff --git a/lib/video/font.h b/lib/video/font.h index bf4ebd586..3d1b9fc39 100644 --- a/lib/video/font.h +++ b/lib/video/font.h @@ -64,11 +64,11 @@ namespace SuperTux friend class DrawingContext; void draw(const std::string& text, const Vector& pos, - Uint32 drawing_effect = NONE_EFFECT); + Uint32 drawing_effect = NONE_EFFECT, int alpha = 255); void draw_center(const std::string& text, const Vector& pos, - Uint32 drawing_effect = NONE_EFFECT); + Uint32 drawing_effect = NONE_EFFECT, int alpha = 255); void draw_chars(Surface* pchars, const std::string& text, - const Vector& position, Uint32 drawing_effect); + const Vector& position, Uint32 drawing_effect, int alpha); Surface* chars; Surface* shadow_chars; -- 2.11.0