2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef HEADER_SUPERTUX_VIDEO_DRAWING_CONTEXT_HPP
18 #define HEADER_SUPERTUX_VIDEO_DRAWING_CONTEXT_HPP
26 #include "math/rectf.hpp"
27 #include "math/vector.hpp"
28 #include "video/color.hpp"
29 #include "video/drawing_request.hpp"
30 #include "video/font.hpp"
31 #include "video/font_ptr.hpp"
32 #include "video/texture.hpp"
39 inline int next_po2(int val)
49 * This class provides functions for drawing things on screen. It also
50 * maintains a stack of transforms that are applied to graphics.
60 /// Adds a drawing request for a surface into the request list.
61 void draw_surface(SurfacePtr surface, const Vector& position,
63 /// Adds a drawing request for a surface into the request list.
64 void draw_surface(SurfacePtr surface, const Vector& position,
65 float angle, const Color& color, const Blend& blend,
67 /// Adds a drawing request for part of a surface.
68 void draw_surface_part(SurfacePtr surface, const Vector& source,
69 const Vector& size, const Vector& dest, int layer);
71 void draw_text(FontPtr font, const std::string& text,
72 const Vector& position, FontAlignment alignment, int layer, Color color = Color(1.0,1.0,1.0));
74 /// Draws text on screen center (feed Vector.x with a 0).
75 /// This is the same as draw_text() with a SCREEN_WIDTH/2 position and
76 /// alignment set to LEFT_ALIGN
77 void draw_center_text(FontPtr font, const std::string& text,
78 const Vector& position, int layer, Color color = Color(1.0,1.0,1.0));
79 /// Draws a color gradient onto the whole screen */
80 void draw_gradient(const Color& from, const Color& to, int layer);
81 /// Fills a rectangle.
82 void draw_filled_rect(const Vector& topleft, const Vector& size,
83 const Color& color, int layer);
84 void draw_filled_rect(const Rectf& rect, const Color& color, int layer);
85 void draw_filled_rect(const Rectf& rect, const Color& color, float radius, int layer);
87 void draw_inverse_ellipse(const Vector& pos, const Vector& size, const Color& color, int layer);
89 /// Returns the visible area in world coordinates
90 Rectf get_cliprect() const;
92 /// Processes all pending drawing requests and flushes the list.
95 const Vector& get_translation() const
96 { return transform.translation; }
98 void set_translation(const Vector& newtranslation)
99 { transform.translation = newtranslation; }
101 void push_transform();
102 void pop_transform();
104 /// Apply that effect in the next draws (effects are listed on surface.h).
105 void set_drawing_effect(DrawingEffect effect);
106 /// return currently applied drawing effect
107 DrawingEffect get_drawing_effect() const;
108 /// apply that alpha in the next draws (1.0 means fully opaque) */
109 void set_alpha(float alpha);
110 /// return currently set alpha
111 float get_alpha() const;
113 /// on next update, set color to lightmap's color at position
114 void get_light(const Vector& position, Color* color );
116 typedef ::Target Target;
117 static const Target NORMAL = ::NORMAL;
118 static const Target LIGHTMAP = ::LIGHTMAP;
121 void set_target(Target target);
123 void set_ambient_color( Color new_color );
126 * requests that a screenshot be taken after the next frame has been rendered
128 void take_screenshot();
131 typedef std::vector<DrawingRequest*> DrawingRequests;
134 void handle_drawing_requests(DrawingRequests& requests);
141 DrawingEffect drawing_effect;
146 drawing_effect(NO_EFFECT),
150 Vector apply(const Vector& v) const
152 return v - translation;
160 /// the transform stack
161 std::vector<Transform> transformstack;
162 /// the currently active transform
165 std::vector<Blend> blend_stack;
168 DrawingRequests drawing_requests;
169 DrawingRequests lightmap_requests;
171 DrawingRequests* requests;
175 std::vector<Target> target_stack;
177 /* obstack holding the memory of the drawing requests */
180 bool screenshot_requested; /**< true if a screenshot should be taken after the next frame has been rendered */
183 DrawingContext(const DrawingContext&);
184 DrawingContext& operator=(const DrawingContext&);