Refactored video/ subsystem to make adding other methods of rendering (in particular...
[supertux.git] / src / video / drawing_request.hpp
1 //  $Id: drawing_request.hpp 4986 2007-04-16 17:48:28Z matzeb $
2 //
3 //  SuperTux
4 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
5 //
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.
10 //
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.
15 //
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_DRAWINGREQUEST_H
20 #define SUPERTUX_DRAWINGREQUEST_H
21
22 #include <vector>
23 #include <string>
24 #include <memory>
25
26 #include <stdint.h>
27
28 #include <SDL_video.h>
29
30 #include "glutil.hpp"
31 #include "math/vector.hpp"
32 #include "color.hpp"
33 #include "font.hpp"
34
35 class Surface;
36
37 // some constants for predefined layer values
38 enum {
39   LAYER_BACKGROUND0 = -300,
40   LAYER_BACKGROUND1 = -200,
41   LAYER_BACKGROUNDTILES = -100,
42   LAYER_TILES = 0,
43   LAYER_OBJECTS = 50,
44   LAYER_FLOATINGOBJECTS = 150,
45   LAYER_FOREGROUNDTILES = 200,
46   LAYER_FOREGROUND0 = 300,
47   LAYER_FOREGROUND1 = 400,
48   LAYER_HUD = 500,
49   LAYER_GUI         = 600
50 };
51
52 class Blend
53 {
54 public:
55   GLenum sfactor;
56   GLenum dfactor;
57
58   Blend()
59     : sfactor(GL_SRC_ALPHA), dfactor(GL_ONE_MINUS_SRC_ALPHA)
60   {}
61
62   Blend(GLenum s, GLenum d)
63     : sfactor(s), dfactor(d)
64   {}
65 };
66
67 enum Target {
68   NORMAL, LIGHTMAP
69 };
70
71 enum RequestType
72 {
73   SURFACE, SURFACE_PART, TEXT, GRADIENT, FILLRECT, GETLIGHT
74 };
75
76 struct SurfacePartRequest
77 {
78   const Surface* surface;
79   Vector source, size;
80 };
81
82 struct TextRequest
83 {
84   const Font* font;
85   std::string text;
86   FontAlignment alignment;
87 };
88
89 struct GradientRequest
90 {
91   Color top, bottom;
92   Vector size;
93 };
94
95 struct FillRectRequest
96 {
97   Color color;
98   Vector size;
99 };
100
101 struct DrawingRequest
102 {
103   Target target;
104   RequestType type;
105   Vector pos;
106
107   int layer;
108   DrawingEffect drawing_effect;
109   float alpha;
110   Blend blend;
111   float angle;
112   Color color;
113
114   void* request_data;
115
116   DrawingRequest()
117     : angle(0.0f),
118       color(1.0f, 1.0f, 1.0f, 1.0f)
119   {}
120
121   bool operator<(const DrawingRequest& other) const
122   {
123     return layer < other.layer;
124   }
125 };
126
127 struct GetLightRequest
128 {
129   Color* color_ptr;
130 };
131
132 #endif
133