Fixed memory leak in DrawingContext
[supertux.git] / src / video / drawing_request.hpp
1 //  SuperTux
2 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 //
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.
8 //
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.
13 //
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/>.
16
17 #ifndef HEADER_SUPERTUX_VIDEO_DRAWING_REQUEST_HPP
18 #define HEADER_SUPERTUX_VIDEO_DRAWING_REQUEST_HPP
19
20 #include <memory>
21 #include <string>
22 #include <vector>
23
24 #include <stdint.h>
25
26 #include "math/vector.hpp"
27 #include "video/color.hpp"
28 #include "video/font.hpp"
29 #include "video/glutil.hpp"
30
31 class Surface;
32
33 // some constants for predefined layer values
34 enum {
35   // Image/gradient backgrounds (should cover entire screen)
36   LAYER_BACKGROUND0 = -300,
37   // Particle backgrounds
38   LAYER_BACKGROUND1 = -200,
39   // Tilemap backgrounds
40   LAYER_BACKGROUNDTILES = -100,
41   // Solid tilemaps
42   LAYER_TILES = 0,
43   // Ordinary objects
44   LAYER_OBJECTS = 50,
45   // Objects that pass through walls
46   LAYER_FLOATINGOBJECTS = 150,
47   //
48   LAYER_FOREGROUNDTILES = 200,
49   //
50   LAYER_FOREGROUND0 = 300,
51   //
52   LAYER_FOREGROUND1 = 400,
53   // Hitpoints, time, coins, etc.
54   LAYER_HUD = 500,
55   // Menus, mouse, console etc.
56   LAYER_GUI         = 600
57 };
58
59 class Blend
60 {
61 public:
62   GLenum sfactor;
63   GLenum dfactor;
64
65   Blend()
66     : sfactor(GL_SRC_ALPHA), dfactor(GL_ONE_MINUS_SRC_ALPHA)
67   {}
68
69   Blend(GLenum s, GLenum d)
70     : sfactor(s), dfactor(d)
71   {}
72 };
73
74 enum Target {
75   NORMAL, LIGHTMAP
76 };
77
78 enum RequestType
79 {
80   SURFACE, SURFACE_PART, TEXT, GRADIENT, FILLRECT, INVERSEELLIPSE, DRAW_LIGHTMAP, GETLIGHT
81 };
82
83 struct DrawingRequestData
84 {
85   virtual ~DrawingRequestData()
86   {}
87 };
88
89 struct SurfaceRequest : public DrawingRequestData
90 {
91   SurfaceRequest() :
92     surface()
93   {}
94
95   const Surface* surface;
96
97 private:
98   SurfaceRequest(const SurfaceRequest&) = delete;
99   SurfaceRequest& operator=(const SurfaceRequest&) = delete;
100 };
101
102 struct SurfacePartRequest : public DrawingRequestData
103 {
104   SurfacePartRequest() :
105     surface(),
106     source(),
107     size()
108   {}
109
110   const Surface* surface;
111   Vector source;
112   Vector size;
113
114 private:
115   SurfacePartRequest(const SurfacePartRequest&) = delete;
116   SurfacePartRequest& operator=(const SurfacePartRequest&) = delete;
117 };
118
119 struct TextRequest : public DrawingRequestData
120 {
121   TextRequest() :
122     font(),
123     text(),
124     alignment()
125   {}
126
127   const Font* font;
128   std::string text;
129   FontAlignment alignment;
130
131 private:
132   TextRequest(const TextRequest&);
133   TextRequest& operator=(const TextRequest&);
134 };
135
136 struct GradientRequest : public DrawingRequestData
137 {
138   GradientRequest()  :
139     top(),
140     bottom(),
141     size()
142   {}
143
144   Color top;
145   Color bottom;
146   Vector size;
147 };
148
149 struct FillRectRequest : public DrawingRequestData
150 {
151   FillRectRequest() :
152     color(),
153     size(),
154     radius()
155   {}
156
157   Color  color;
158   Vector size;
159   float  radius;
160 };
161
162 struct InverseEllipseRequest : public DrawingRequestData
163 {
164   InverseEllipseRequest() :
165     color(),
166     size()
167   {}
168
169   Color  color;
170   Vector size;
171 };
172
173 struct DrawingRequest
174 {
175   Target target;
176   RequestType type;
177   Vector pos;
178
179   int layer;
180   DrawingEffect drawing_effect;
181   float alpha;
182   Blend blend;
183   float angle;
184   Color color;
185
186   DrawingRequestData* request_data;
187
188   DrawingRequest() :
189     target(),
190     type(),
191     pos(),
192     layer(),
193     drawing_effect(),
194     alpha(),
195     blend(),
196     angle(0.0f),
197     color(1.0f, 1.0f, 1.0f, 1.0f),
198     request_data()
199   {}
200
201   bool operator<(const DrawingRequest& other) const
202   {
203     return layer < other.layer;
204   }
205 };
206
207 struct GetLightRequest : public DrawingRequestData
208 {
209   GetLightRequest() : color_ptr() {}
210
211   Color* color_ptr;
212
213 private:
214   GetLightRequest(const GetLightRequest&) = delete;
215   GetLightRequest& operator=(const GetLightRequest&) = delete;
216 };
217
218 #endif
219
220 /* EOF */