1 // $Id: drawing_context.h 2334 2005-04-04 16:26:14Z grumbel $
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
30 #include "math/vector.hpp"
31 #include "video/screen.hpp"
32 #include "video/surface.hpp"
33 #include "video/font.hpp"
38 // some constants for predefined layer values
40 LAYER_BACKGROUND0 = -300,
41 LAYER_BACKGROUND1 = -200,
42 LAYER_BACKGROUNDTILES = -100,
45 LAYER_FOREGROUNDTILES = 200,
46 LAYER_FOREGROUND0 = 300,
47 LAYER_FOREGROUND1 = 400,
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,
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);
68 void draw_text(const Font* font, const std::string& text,
69 const Vector& position, FontAlignment alignment, int layer);
71 /// Draws text on screen center (feed Vector.x with a 0).
72 /// This is the same as draw_text() with a SCREEN_WIDTH/2 position and
73 /// alignment set to LEFT_ALLIGN
74 void draw_center_text(const Font* font, const std::string& text,
75 const Vector& position, int layer);
76 /// Draws a color gradient onto the whole screen */
77 void draw_gradient(Color from, Color to, int layer);
78 /// Fills a rectangle.
79 void draw_filled_rect(const Vector& topleft, const Vector& size,
80 Color color, int layer);
82 /// Processes all pending drawing requests and flushes the list.
85 const Vector& get_translation() const
86 { return transform.translation; }
88 void set_translation(const Vector& newtranslation)
89 { transform.translation = newtranslation; }
91 void push_transform();
94 /// Apply that effect in the next draws (effects are listed on surface.h).
95 void set_drawing_effect(uint32_t effect);
96 /// return currently applied drawing effect
97 uint32_t get_drawing_effect() const;
98 /// apply that zoom in the next draws */
99 void set_zooming(float zoom);
100 /// apply that alpha in the next draws */
101 void set_alpha(uint8_t alpha);
102 /// return currently set alpha
103 uint8_t get_alpha() const;
110 void set_target(Target target);
117 uint32_t drawing_effect;
122 : drawing_effect(NONE_EFFECT), zoom(1), alpha(255)
125 Vector apply(const Vector& v) const
127 return v - translation;
131 /// the transform stack
132 std::vector<Transform> transformstack;
133 /// the currently active transform
143 : sfactor(GL_SRC_ALPHA), dfactor(GL_ONE_MINUS_SRC_ALPHA)
146 std::vector<Blend> blend_stack;
151 SURFACE, SURFACE_PART, TEXT, GRADIENT, FILLRECT
154 struct SurfacePartRequest
156 const Surface* surface;
164 FontAlignment alignment;
167 struct GradientRequest
173 struct FillRectRequest
179 struct DrawingRequest
185 uint32_t drawing_effect;
192 bool operator<(const DrawingRequest& other) const
194 return layer < other.layer;
198 typedef std::vector<DrawingRequest> DrawingRequests;
200 void handle_drawing_requests(DrawingRequests& requests);
201 void draw_surface_part(DrawingRequest& request);
202 void draw_text(DrawingRequest& request);
203 void draw_text_center(DrawingRequest& request);
204 void draw_gradient(DrawingRequest& request);
205 void draw_filled_rect(DrawingRequest& request);
207 DrawingRequests drawing_requests;
208 DrawingRequests lightmap_requests;
210 DrawingRequests* requests;
214 std::vector<Target> target_stack;
215 std::auto_ptr<Texture> lightmap;
216 int lightmap_width, lightmap_height;
217 float lightmap_uv_right, lightmap_uv_bottom;