4 // Copyright (C) 2006 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.
20 #ifndef SUPERTUX_DRAWINGCONTEXT_H
21 #define SUPERTUX_DRAWINGCONTEXT_H
32 #include "math/vector.hpp"
33 #include "math/rect.hpp"
34 #include "surface.hpp"
41 // some constants for predefined layer values
43 LAYER_BACKGROUND0 = -300,
44 LAYER_BACKGROUND1 = -200,
45 LAYER_BACKGROUNDTILES = -100,
48 LAYER_FLOATINGOBJECTS = 150,
49 LAYER_FOREGROUNDTILES = 200,
50 LAYER_FOREGROUND0 = 300,
51 LAYER_FOREGROUND1 = 400,
56 * This class provides functions for drawing things on screen. It also
57 * maintains a stack of transforms that are applied to graphics.
65 /// Adds a drawing request for a surface into the request list.
66 void draw_surface(const Surface* surface, const Vector& position,
68 /// Adds a drawing request for a surface into the request list.
69 void draw_surface(const Surface* surface, const Vector& position, float angle,
71 /// Adds a drawing request for part of a surface.
72 void draw_surface_part(const Surface* surface, const Vector& source,
73 const Vector& size, const Vector& dest, int layer);
75 void draw_text(const Font* font, const std::string& text,
76 const Vector& position, FontAlignment alignment, int layer);
78 /// Draws text on screen center (feed Vector.x with a 0).
79 /// This is the same as draw_text() with a SCREEN_WIDTH/2 position and
80 /// alignment set to LEFT_ALLIGN
81 void draw_center_text(const Font* font, const std::string& text,
82 const Vector& position, int layer);
83 /// Draws a color gradient onto the whole screen */
84 void draw_gradient(const Color& from, const Color& to, int layer);
85 /// Fills a rectangle.
86 void draw_filled_rect(const Vector& topleft, const Vector& size,
87 const Color& color, int layer);
88 void draw_filled_rect(const Rect& rect, const Color& color, int layer);
90 /// Processes all pending drawing requests and flushes the list.
93 const Vector& get_translation() const
94 { return transform.translation; }
96 void set_translation(const Vector& newtranslation)
97 { transform.translation = newtranslation; }
99 void push_transform();
100 void pop_transform();
102 /// Apply that effect in the next draws (effects are listed on surface.h).
103 void set_drawing_effect(DrawingEffect effect);
104 /// return currently applied drawing effect
105 DrawingEffect get_drawing_effect() const;
106 /// apply that alpha in the next draws (1.0 means fully opaque) */
107 void set_alpha(float alpha);
108 /// return currently set alpha
109 float get_alpha() const;
116 void set_target(Target target);
123 DrawingEffect drawing_effect;
127 : drawing_effect(NO_EFFECT), alpha(1.0f)
130 Vector apply(const Vector& v) const
132 return v - translation;
136 /// the transform stack
137 std::vector<Transform> transformstack;
138 /// the currently active transform
148 : sfactor(GL_SRC_ALPHA), dfactor(GL_ONE_MINUS_SRC_ALPHA)
151 std::vector<Blend> blend_stack;
156 SURFACE, SURFACE_PART, TEXT, GRADIENT, FILLRECT
159 struct SurfacePartRequest
161 const Surface* surface;
169 FontAlignment alignment;
172 struct GradientRequest
178 struct FillRectRequest
184 struct DrawingRequest
190 DrawingEffect drawing_effect;
201 bool operator<(const DrawingRequest& other) const
203 return layer < other.layer;
207 typedef std::vector<DrawingRequest> DrawingRequests;
209 void handle_drawing_requests(DrawingRequests& requests);
210 void draw_surface_part(DrawingRequest& request);
211 void draw_text(DrawingRequest& request);
212 void draw_text_center(DrawingRequest& request);
213 void draw_gradient(DrawingRequest& request);
214 void draw_filled_rect(DrawingRequest& request);
216 DrawingRequests drawing_requests;
217 DrawingRequests lightmap_requests;
219 DrawingRequests* requests;
223 std::vector<Target> target_stack;
225 int lightmap_width, lightmap_height;
226 float lightmap_uv_right, lightmap_uv_bottom;