Added an alpha argument for drawing fonts.
[supertux.git] / lib / video / drawing_context.cpp
index 846e38c..0019ff5 100644 (file)
 #include <cassert>
 #include <iostream>
 
-#include "video/drawing_context.h"
-#include "video/surface.h"
-#include "app/globals.h"
-#include "video/font.h"
+#include "../video/drawing_context.h"
+#include "../video/surface.h"
+#include "../app/globals.h"
+#include "../video/font.h"
+
+using namespace SuperTux;
 
 DrawingContext::DrawingContext()
 {
@@ -76,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;
 
@@ -88,6 +90,8 @@ DrawingContext::draw_text(Font* font, const std::string& text,
   TextRequest* textrequest = new TextRequest;
   textrequest->font = font;
   textrequest->text = text;
+  textrequest->center = false;
+  textrequest->alpha = alpha;
   request.request_data = textrequest;
 
   drawingrequests.push_back(request);
@@ -95,19 +99,20 @@ 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;
 
   request.type = TEXT;
   request.layer = layer;
-  request.pos = transform.apply(position) + Vector(screen->w/2 - 
-      font->get_text_width(text)/2, 0);
+  request.pos = transform.apply(position);
   request.drawing_effect = drawing_effect;
 
   TextRequest* textrequest = new TextRequest;
   textrequest->font = font;
   textrequest->text = text;
+  textrequest->center = true;
+  textrequest->alpha = alpha;
   request.request_data = textrequest;
 
   drawingrequests.push_back(request);
@@ -213,8 +218,11 @@ void
 DrawingContext::draw_text(DrawingRequest& request)
 {
   TextRequest* textrequest = (TextRequest*) request.request_data;
-  
-  textrequest->font->draw(textrequest->text, request.pos, request.drawing_effect);
+
+  if(textrequest->center)
+    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->alpha);
 
   delete textrequest;
 }