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.
19 #ifndef SUPERTUX_DRAWINGCONTEXT_H
20 #define SUPERTUX_DRAWINGCONTEXT_H
28 //#include "obstack/obstack.h"
29 //#include "math/vector.hpp"
30 //#include "math/rect.hpp"
31 #include "drawing_request.hpp"
35 #include <unison/video/Texture.hpp>
36 #include <unison/video/Window.hpp>
37 #include <unison/video/DisplayList.hpp>
44 struct DrawingRequest;
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(const Surface* surface, const Vector& position,
63 /// Adds a drawing request for a surface into the request list.
64 void draw_surface(const Surface* 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(const Surface* surface, const Vector& source,
69 const Vector& size, const Vector& dest, int layer);
71 void draw_text(const Font* font, const std::string& text,
72 const Vector& position, FontAlignment alignment, int layer);
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_ALLIGN
77 void draw_center_text(const Font* font, const std::string& text,
78 const Vector& position, int layer);
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 Rect& rect, const Color& color, int layer);
86 /// Processes all pending drawing requests and flushes the list.
89 const Vector& get_translation() const
90 { return transform.translation; }
92 void set_translation(const Vector& newtranslation)
93 { transform.translation = newtranslation; }
95 void push_transform();
98 /// Apply that effect in the next draws (effects are listed on surface.h).
99 void set_drawing_effect(DrawingEffect effect);
100 /// return currently applied drawing effect
101 DrawingEffect get_drawing_effect() const;
102 /// apply that alpha in the next draws (1.0 means fully opaque) */
103 void set_alpha(float alpha);
104 /// return currently set alpha
105 float get_alpha() const;
107 /// on next update, set color to lightmap's color at position
108 void get_light(const Vector& position, Color* color );
110 typedef ::Target Target;
111 static const Target NORMAL = ::NORMAL;
112 static const Target LIGHTMAP = ::LIGHTMAP;
115 void set_target(Target target);
117 void set_ambient_color( Color new_color );
120 * requests that a screenshot be taken after the next frame has been rendered
122 void take_screenshot();
129 DrawingEffect drawing_effect;
133 : drawing_effect(NO_EFFECT), alpha(1.0f)
136 Vector apply(const Vector& v) const
138 return v - translation;
142 Unison::Video::Surface lightmap;
143 std::vector<std::pair<Unison::Video::Point, Color *> > get_light_requests;
145 std::map<int, Unison::Video::DisplayList> normal_list;
146 std::map<int, Unison::Video::DisplayList> lightmap_list;
147 std::map<int, Unison::Video::DisplayList> *draw_target;
149 //Renderer *renderer;
150 //Lightmap *lightmap;
152 /// the transform stack
153 std::vector<Transform> transformstack;
154 /// the currently active transform
157 std::vector<Blend> blend_stack;
160 /*typedef std::vector<DrawingRequest*> DrawingRequests;
162 void handle_drawing_requests(DrawingRequests& requests);
164 DrawingRequests drawing_requests;
165 DrawingRequests lightmap_requests;
167 DrawingRequests* requests;*/
171 std::vector<Target> target_stack;
173 /* obstack holding the memory of the drawing requests */
174 //struct obstack obst;
176 bool screenshot_requested; /**< true if a screenshot should be taken after the next frame has been rendered */