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
33 // some constants for predefined layer values
35 LAYER_BACKGROUND0 = -300,
36 LAYER_BACKGROUND1 = -200,
37 LAYER_BACKGROUNDTILES = -100,
40 LAYER_FOREGROUNDTILES = 200,
41 LAYER_FOREGROUND0 = 300,
42 LAYER_FOREGROUND1 = 400,
50 : red(0), green(0), blue(0), alpha(0)
53 Color(Uint8 red_, Uint8 green_, Uint8 blue_, Uint8 alpha_ = 0)
54 : red(red_), green(green_), blue(blue_), alpha(alpha_)
58 : red(o.red), green(o.green), blue(o.blue), alpha(o.alpha)
61 Uint8 red, green, blue, alpha;
65 * This class provides functions for drawing things on screen. It also
66 * maintains a stack of transforms that are applied to graphics.
74 /** Adds a drawing request for a surface into the request list */
75 void draw_surface(const Surface* surface, const Vector& position, int layer,
76 Uint32 drawing_effect = NONE_EFFECT);
77 /** Adds a drawing request for part of a surface */
78 void draw_surface_part(const Surface* surface, const Vector& source,
79 const Vector& size, const Vector& dest, int layer,
80 Uint32 drawing_effect = NONE_EFFECT);
82 void draw_text(Font* font, const std::string& text, const Vector& position,
84 /** draws aligned text */
85 void draw_text_center(Font* font, const std::string& text,
86 const Vector& position, int layer);
87 /** draws a color gradient onto the whole screen */
88 void draw_gradient(Color from, Color to, int layer);
89 /** fills a rectangle */
90 void draw_filled_rect(const Vector& topleft, const Vector& downright,
91 Color color, int layer);
93 /** Processes all pending drawing requests and flushes the list */
96 const Vector& get_translation() const
97 { return transform.translation; }
98 void set_translation(const Vector& newtranslation)
99 { transform.translation = newtranslation; }
101 void push_transform();
102 void pop_transform();
108 Vector translation; // only translation for now...
110 Vector apply(const Vector& v) const
112 return v - translation;
116 /// the transform stack
117 std::vector<Transform> transformstack;
118 /// the currently active transform
123 SURFACE, SURFACE_PART, TEXT, GRADIENT, FILLRECT
126 struct SurfacePartRequest
128 const Surface* surface;
138 struct GradientRequest
144 struct FillRectRequest
150 struct DrawingRequest
153 Uint32 drawing_effect;
160 bool operator<(const DrawingRequest& other) const
162 return layer < other.layer;
166 void draw_surface_part(DrawingRequest& request);
167 void draw_text(DrawingRequest& request);
168 void draw_gradient(DrawingRequest& request);
169 void draw_filled_rect(DrawingRequest& request);
171 typedef std::vector<DrawingRequest> DrawingRequests;
172 DrawingRequests drawingrequests;
175 #endif /*SUPERTUX_DRAWINGCONTEXT_H*/