3 // SuperTux - A Jump'n Run
4 // Copyright (C) 2004 Matthias Braun <matze@braunis.de
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #ifndef SUPERTUX_DRAWINGCONTEXT_H
20 #define SUPERTUX_DRAWINGCONTEXT_H
27 #include "../math/vector.h"
28 #include "../video/screen.h"
29 #include "../video/surface.h"
37 // some constants for predefined layer values
39 LAYER_BACKGROUND0 = -300,
40 LAYER_BACKGROUND1 = -200,
41 LAYER_BACKGROUNDTILES = -100,
44 LAYER_FOREGROUNDTILES = 200,
45 LAYER_FOREGROUND0 = 300,
46 LAYER_FOREGROUND1 = 400,
50 /// Handles drawing of things.
52 * This class provides functions for drawing things on screen. It also
53 * maintains a stack of transforms that are applied to graphics.
61 /// Adds a drawing request for a surface into the request list.
62 void draw_surface(const Surface* surface, const Vector& position, int layer,
63 Uint32 drawing_effect = NONE_EFFECT);
64 /// Adds a drawing request for part of a surface.
65 void draw_surface_part(const Surface* surface, const Vector& source,
66 const Vector& size, const Vector& dest, int layer,
67 Uint32 drawing_effect = NONE_EFFECT);
69 void draw_text(Font* font, const std::string& text, const Vector& position,
70 int layer, Uint32 drawing_effect = NONE_EFFECT);
71 /// Draws aligned text.
72 void draw_text_center(Font* font, const std::string& text,
73 const Vector& position, int layer, Uint32 drawing_effect = NONE_EFFECT);
74 /// Draws a color gradient onto the whole screen */
75 void draw_gradient(Color from, Color to, int layer);
76 /// Fills a rectangle.
77 void draw_filled_rect(const Vector& topleft, const Vector& size,
78 Color color, int layer);
80 /// Processes all pending drawing requests and flushes the list.
83 const Vector& get_translation() const
85 return transform.translation;
87 void set_translation(const Vector& newtranslation)
89 transform.translation = newtranslation;
92 void push_transform();
95 /// Apply that effect in the next draws (effects are listed on surface.h).
96 void set_drawing_effect(int effect);
102 Vector translation; // only translation for now...
104 Vector apply(const Vector& v) const
106 return v - translation;
112 /// the transform stack
113 std::vector<Transform> transformstack;
114 /// the currently active transform
119 SURFACE, SURFACE_PART, TEXT, GRADIENT, FILLRECT
122 struct SurfacePartRequest
124 const Surface* surface;
135 struct GradientRequest
141 struct FillRectRequest
147 struct DrawingRequest
150 Uint32 drawing_effect;
157 bool operator<(const DrawingRequest& other) const
159 return layer < other.layer;
163 void draw_surface_part(DrawingRequest& request);
164 void draw_text(DrawingRequest& request);
165 void draw_text_center(DrawingRequest& request);
166 void draw_gradient(DrawingRequest& request);
167 void draw_filled_rect(DrawingRequest& request);
169 typedef std::vector<DrawingRequest> DrawingRequests;
170 DrawingRequests drawingrequests;
173 } //namespace SuperTux
175 #endif /*SUPERTUX_DRAWINGCONTEXT_H*/