updating Nolok contrib templates
[supertux.git] / lib / video / drawing_context.h
index a927b67..8e1dfaa 100644 (file)
 
 #include <vector>
 #include <string>
+#include <stdint.h>
 
 #include "SDL.h"
 
-#include "../math/vector.h"
-#include "../video/screen.h"
-#include "../video/surface.h"
+#include "math/vector.h"
+#include "video/screen.h"
+#include "video/surface.h"
+#include "video/font.h"
 
 namespace SuperTux
   {
 
   class Surface;
-  class Font;
 
   // some constants for predefined layer values
   enum {
@@ -59,16 +60,23 @@ namespace SuperTux
       ~DrawingContext();
 
       /// Adds a drawing request for a surface into the request list.
-      void draw_surface(const Surface* surface, const Vector& position, int layer,
-                        Uint32 drawing_effect = NONE_EFFECT);
+      void draw_surface(const Surface* surface, const Vector& position,
+          int layer, uint32_t drawing_effect = NONE_EFFECT);
       /// Adds a drawing request for part of a surface.
       void draw_surface_part(const Surface* surface, const Vector& source,
                              const Vector& size, const Vector& dest, int layer,
-                             Uint32 drawing_effect = NONE_EFFECT);
+                             uint32_t drawing_effect = NONE_EFFECT);
       /// Draws a text.
-      void draw_text(Font* font, const std::string& text, const Vector& position,
-                     int allignment, int layer,
-                     Uint32 drawing_effect = NONE_EFFECT, int alpha = 255);
+      void draw_text(const Font* font, const std::string& text,
+          const Vector& position, FontAlignment alignment, int layer,
+          uint32_t drawing_effect = NONE_EFFECT);
+
+      /// Draws text on screen center (feed Vector.x with a 0).
+      /// This is the same as draw_text() with a SCREEN_WIDTH/2 position and
+      /// alignment set to LEFT_ALLIGN
+      void draw_center_text(const Font* font, const std::string& text,
+                           const Vector& position, int layer,
+                           uint32_t drawing_effect = NONE_EFFECT);
       /// Draws a color gradient onto the whole screen */
       void draw_gradient(Color from, Color to, int layer);
       /// Fills a rectangle.
@@ -79,9 +87,9 @@ namespace SuperTux
       void do_drawing();
 
       const Vector& get_translation() const
-        {  return transform.translation;  }
-      Uint32 get_drawing_effect() const
-        {  return transform.draw_effect;  }
+      {  return transform.translation;  }
+      uint32_t get_drawing_effect() const
+      {  return transform.drawing_effect;  }
 
       void set_translation(const Vector& newtranslation)
         {  transform.translation = newtranslation;  }
@@ -93,21 +101,27 @@ namespace SuperTux
       void set_drawing_effect(int effect);
       /// apply that zoom in the next draws */
       void set_zooming(float zoom);
+      /// apply that alpha in the next draws */
+      void set_alpha(int alpha);
 
     private:
       class Transform
-        {
-        public:
-          Vector translation; // only translation for now...
+      {
+      public:
+        Vector translation;
+        uint32_t drawing_effect;
+        float zoom;
+        int alpha;
 
-          Vector apply(const Vector& v) const
-            {
-              return v - translation;
-            }
+        Transform()
+          : drawing_effect(NONE_EFFECT), zoom(1), alpha(255)
+        { }
 
-          Uint32 draw_effect;
-          float zoom;
-        };
+        Vector apply(const Vector& v) const
+        {
+          return v - translation;
+        }
+      };
 
       /// the transform stack
       std::vector<Transform> transformstack;
@@ -127,10 +141,9 @@ namespace SuperTux
 
       struct TextRequest
         {
-          Font* font;
+          const Font* font;
           std::string text;
-          int allignment;
-          int alpha;
+          FontAlignment alignment;
         };
 
       struct GradientRequest
@@ -147,12 +160,13 @@ namespace SuperTux
 
       struct DrawingRequest
         {
+          RequestType type;
+          Vector pos;                
+          
           int layer;
-          Uint32 drawing_effect;
+          uint32_t drawing_effect;
           float zoom;
-
-          RequestType type;
-          Vector pos;
+          int alpha;
 
           void* request_data;