]> git.sesse.net Git - casparcg/blob - dependencies/SFML-1.6/include/SFML/Graphics/Drawable.hpp
Subtree merge of old SVN "dependencies" folder into the "master" git branch. You...
[casparcg] / dependencies / SFML-1.6 / include / SFML / Graphics / Drawable.hpp
1 ////////////////////////////////////////////////////////////\r
2 //\r
3 // SFML - Simple and Fast Multimedia Library\r
4 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
5 //\r
6 // This software is provided 'as-is', without any express or implied warranty.\r
7 // In no event will the authors be held liable for any damages arising from the use of this software.\r
8 //\r
9 // Permission is granted to anyone to use this software for any purpose,\r
10 // including commercial applications, and to alter it and redistribute it freely,\r
11 // subject to the following restrictions:\r
12 //\r
13 // 1. The origin of this software must not be misrepresented;\r
14 //    you must not claim that you wrote the original software.\r
15 //    If you use this software in a product, an acknowledgment\r
16 //    in the product documentation would be appreciated but is not required.\r
17 //\r
18 // 2. Altered source versions must be plainly marked as such,\r
19 //    and must not be misrepresented as being the original software.\r
20 //\r
21 // 3. This notice may not be removed or altered from any source distribution.\r
22 //\r
23 ////////////////////////////////////////////////////////////\r
24 \r
25 #ifndef SFML_DRAWABLE_HPP\r
26 #define SFML_DRAWABLE_HPP\r
27 \r
28 ////////////////////////////////////////////////////////////\r
29 // Headers\r
30 ////////////////////////////////////////////////////////////\r
31 #include <SFML/System/Vector2.hpp>\r
32 #include <SFML/Graphics/Color.hpp>\r
33 #include <SFML/Graphics/Matrix3.hpp>\r
34 \r
35 \r
36 namespace sf\r
37 {\r
38 class RenderTarget;\r
39 \r
40 ////////////////////////////////////////////////////////////\r
41 /// Enumerate the blending modes for drawable objects\r
42 ////////////////////////////////////////////////////////////\r
43 namespace Blend\r
44 {\r
45     enum Mode\r
46     {\r
47         Alpha,    ///< Pixel = Src * a + Dest * (1 - a)\r
48         Add,      ///< Pixel = Src + Dest\r
49         Multiply, ///< Pixel = Src * Dest\r
50         None      ///< No blending\r
51     };\r
52 }\r
53 \r
54 ////////////////////////////////////////////////////////////\r
55 /// Abstract base class for every object that can be drawn\r
56 /// into a render window\r
57 ////////////////////////////////////////////////////////////\r
58 class SFML_API Drawable\r
59 {\r
60 public :\r
61 \r
62     ////////////////////////////////////////////////////////////\r
63     /// Default constructor\r
64     ///\r
65     /// \param Position : Position of the object (0, 0 by default)\r
66     /// \param Scale :    Scale factor (1, 1 by default)\r
67     /// \param Rotation : Orientation, in degrees (0 by default)\r
68     /// \param Col :      Color of the object (white by default)\r
69     ///\r
70     ////////////////////////////////////////////////////////////\r
71     Drawable(const Vector2f& Position = Vector2f(0, 0), const Vector2f& Scale = Vector2f(1, 1), float Rotation = 0.f, const Color& Col = Color(255, 255, 255, 255));\r
72 \r
73     ////////////////////////////////////////////////////////////\r
74     /// Virtual destructor\r
75     ///\r
76     ////////////////////////////////////////////////////////////\r
77     virtual ~Drawable();\r
78 \r
79     ////////////////////////////////////////////////////////////\r
80     /// Set the position of the object (take 2 values)\r
81     ///\r
82     /// \param X : New X coordinate\r
83     /// \param Y : New Y coordinate\r
84     ///\r
85     ////////////////////////////////////////////////////////////\r
86     void SetPosition(float X, float Y);\r
87 \r
88     ////////////////////////////////////////////////////////////\r
89     /// Set the position of the object (take a 2D vector)\r
90     ///\r
91     /// \param Position : New position\r
92     ///\r
93     ////////////////////////////////////////////////////////////\r
94     void SetPosition(const Vector2f& Position);\r
95 \r
96     ////////////////////////////////////////////////////////////\r
97     /// Set the X position of the object\r
98     ///\r
99     /// \param X : New X coordinate\r
100     ///\r
101     ////////////////////////////////////////////////////////////\r
102     void SetX(float X);\r
103 \r
104     ////////////////////////////////////////////////////////////\r
105     /// Set the Y position of the object\r
106     ///\r
107     /// \param Y : New Y coordinate\r
108     ///\r
109     ////////////////////////////////////////////////////////////\r
110     void SetY(float Y);\r
111 \r
112     ////////////////////////////////////////////////////////////\r
113     /// Set the scale of the object (take 2 values)\r
114     ///\r
115     /// \param ScaleX : New horizontal scale (must be strictly positive)\r
116     /// \param ScaleY : New vertical scale (must be strictly positive)\r
117     ///\r
118     ////////////////////////////////////////////////////////////\r
119     void SetScale(float ScaleX, float ScaleY);\r
120 \r
121     ////////////////////////////////////////////////////////////\r
122     /// Set the scale of the object (take a 2D vector)\r
123     ///\r
124     /// \param Scale : New scale (both values must be strictly positive)\r
125     ///\r
126     ////////////////////////////////////////////////////////////\r
127     void SetScale(const Vector2f& Scale);\r
128 \r
129     ////////////////////////////////////////////////////////////\r
130     /// Set the X scale factor of the object\r
131     ///\r
132     /// \param X : New X scale factor\r
133     ///\r
134     ////////////////////////////////////////////////////////////\r
135     void SetScaleX(float FactorX);\r
136 \r
137     ////////////////////////////////////////////////////////////\r
138     /// Set the Y scale factor of the object\r
139     ///\r
140     /// \param Y : New Y scale factor\r
141     ///\r
142     ////////////////////////////////////////////////////////////\r
143     void SetScaleY(float FactorY);\r
144 \r
145     ////////////////////////////////////////////////////////////\r
146     /// Set the center of the object, in coordinates relative to the\r
147     /// top-left of the object (take 2 values).\r
148     /// The default center is (0, 0)\r
149     ///\r
150     /// \param CenterX : X coordinate of the center\r
151     /// \param CenterY : Y coordinate of the center\r
152     ///\r
153     ////////////////////////////////////////////////////////////\r
154     void SetCenter(float CenterX, float CenterY);\r
155 \r
156     ////////////////////////////////////////////////////////////\r
157     /// Set the center of the object, in coordinates relative to the\r
158     /// top-left of the object (take a 2D vector).\r
159     /// The default center is (0, 0)\r
160     ///\r
161     /// \param Center : New center\r
162     ///\r
163     ////////////////////////////////////////////////////////////\r
164     void SetCenter(const Vector2f& Center);\r
165 \r
166     ////////////////////////////////////////////////////////////\r
167     /// Set the orientation of the object\r
168     ///\r
169     /// \param Rotation : Angle of rotation, in degrees\r
170     ///\r
171     ////////////////////////////////////////////////////////////\r
172     void SetRotation(float Rotation);\r
173 \r
174     ////////////////////////////////////////////////////////////\r
175     /// Set the color of the object.\r
176     /// The default color is white\r
177     ///\r
178     /// \param Col : New color\r
179     ///\r
180     ////////////////////////////////////////////////////////////\r
181     void SetColor(const Color& Col);\r
182 \r
183     ////////////////////////////////////////////////////////////\r
184     /// Set the blending mode for the object.\r
185     /// The default blend mode is Blend::Alpha\r
186     ///\r
187     /// \param Mode : New blending mode\r
188     ///\r
189     ////////////////////////////////////////////////////////////\r
190     void SetBlendMode(Blend::Mode Mode);\r
191 \r
192     ////////////////////////////////////////////////////////////\r
193     /// Get the position of the object\r
194     ///\r
195     /// \return Current position\r
196     ///\r
197     ////////////////////////////////////////////////////////////\r
198     const Vector2f& GetPosition() const;\r
199 \r
200     ////////////////////////////////////////////////////////////\r
201     /// Get the current scale of the object\r
202     ///\r
203     /// \return Current scale factor (always positive)\r
204     ///\r
205     ////////////////////////////////////////////////////////////\r
206     const Vector2f& GetScale() const;\r
207 \r
208     ////////////////////////////////////////////////////////////\r
209     /// Get the center of the object\r
210     ///\r
211     /// \return Current position of the center\r
212     ///\r
213     ////////////////////////////////////////////////////////////\r
214     const Vector2f& GetCenter() const;\r
215 \r
216     ////////////////////////////////////////////////////////////\r
217     /// Get the orientation of the object.\r
218     /// Rotation is always in the range [0, 360]\r
219     ///\r
220     /// \return Current rotation, in degrees\r
221     ///\r
222     ////////////////////////////////////////////////////////////\r
223     float GetRotation() const;\r
224 \r
225     ////////////////////////////////////////////////////////////\r
226     /// Get the color of the object\r
227     ///\r
228     /// \return Current color\r
229     ///\r
230     ////////////////////////////////////////////////////////////\r
231     const Color& GetColor() const;\r
232 \r
233     ////////////////////////////////////////////////////////////\r
234     /// Get the current blending mode\r
235     ///\r
236     /// \return Current blending mode\r
237     ///\r
238     ////////////////////////////////////////////////////////////\r
239     Blend::Mode GetBlendMode() const;\r
240 \r
241     ////////////////////////////////////////////////////////////\r
242     /// Move the object of a given offset (take 2 values)\r
243     ///\r
244     /// \param OffsetX : X offset\r
245     /// \param OffsetY : Y offset\r
246     ///\r
247     ////////////////////////////////////////////////////////////\r
248     void Move(float OffsetX, float OffsetY);\r
249 \r
250     ////////////////////////////////////////////////////////////\r
251     /// Move the object of a given offset (take a 2D vector)\r
252     ///\r
253     /// \param Offset : Amount of units to move the object of\r
254     ///\r
255     ////////////////////////////////////////////////////////////\r
256     void Move(const Vector2f& Offset);\r
257 \r
258     ////////////////////////////////////////////////////////////\r
259     /// Scale the object (take 2 values)\r
260     ///\r
261     /// \param FactorX : Scaling factor on X (must be strictly positive)\r
262     /// \param FactorY : Scaling factor on Y (must be strictly positive)\r
263     ///\r
264     ////////////////////////////////////////////////////////////\r
265     void Scale(float FactorX, float FactorY);\r
266 \r
267     ////////////////////////////////////////////////////////////\r
268     /// Scale the object (take a 2D vector)\r
269     ///\r
270     /// \param Factor : Scaling factors (both values must be strictly positive)\r
271     ///\r
272     ////////////////////////////////////////////////////////////\r
273     void Scale(const Vector2f& Factor);\r
274 \r
275     ////////////////////////////////////////////////////////////\r
276     /// Rotate the object\r
277     ///\r
278     /// \param Angle : Angle of rotation, in degrees\r
279     ///\r
280     ////////////////////////////////////////////////////////////\r
281     void Rotate(float Angle);\r
282 \r
283     ////////////////////////////////////////////////////////////\r
284     /// Transform a point from global coordinates into local coordinates\r
285     /// (ie it applies the inverse of object's center, translation, rotation and scale to the point)\r
286     ///\r
287     /// \param Point : Point to transform\r
288     ///\r
289     /// \return Transformed point\r
290     ///\r
291     ////////////////////////////////////////////////////////////\r
292     sf::Vector2f TransformToLocal(const sf::Vector2f& Point) const;\r
293 \r
294     ////////////////////////////////////////////////////////////\r
295     /// Transform a point from local coordinates into global coordinates\r
296     /// (ie it applies the object's center, translation, rotation and scale to the point)\r
297     ///\r
298     /// \param Point : Point to transform\r
299     ///\r
300     /// \return Transformed point\r
301     ///\r
302     ////////////////////////////////////////////////////////////\r
303     sf::Vector2f TransformToGlobal(const sf::Vector2f& Point) const;\r
304 \r
305 protected :\r
306 \r
307     ////////////////////////////////////////////////////////////\r
308     /// Get the transform matrix of the drawable\r
309     ///\r
310     /// \return Transform matrix\r
311     ///\r
312     ////////////////////////////////////////////////////////////\r
313     const Matrix3& GetMatrix() const;\r
314 \r
315     ////////////////////////////////////////////////////////////\r
316     /// Get the inverse transform matrix of the drawable\r
317     ///\r
318     /// \return Inverse transform matrix\r
319     ///\r
320     ////////////////////////////////////////////////////////////\r
321     const Matrix3& GetInverseMatrix() const;\r
322 \r
323 private :\r
324 \r
325     friend class RenderTarget;\r
326 \r
327     ////////////////////////////////////////////////////////////\r
328     /// Draw the object into the specified window\r
329     ///\r
330     /// \param Target : Target into which render the object\r
331     ///\r
332     ////////////////////////////////////////////////////////////\r
333     void Draw(RenderTarget& Target) const;\r
334 \r
335     ////////////////////////////////////////////////////////////\r
336     /// Render the specific geometry of the object\r
337     ///\r
338     /// \param Target : Target into which render the object\r
339     ///\r
340     ////////////////////////////////////////////////////////////\r
341     virtual void Render(RenderTarget& Target) const = 0;\r
342 \r
343     ////////////////////////////////////////////////////////////\r
344     // Member data\r
345     ////////////////////////////////////////////////////////////\r
346     Vector2f        myPosition;      ///< Position of the object on screen\r
347     Vector2f        myScale;         ///< Scale of the object\r
348     Vector2f        myCenter;        ///< Origin of translation / rotation / scaling of the object\r
349     float           myRotation;      ///< Orientation of the object, in degrees\r
350     Color           myColor;         ///< Overlay color of the object\r
351     Blend::Mode     myBlendMode;     ///< Blending mode\r
352     mutable bool    myNeedUpdate;    ///< Do we need to recompute the transform matrix ?\r
353     mutable bool    myInvNeedUpdate; ///< Do we need to recompute the inverse transform matrix ?\r
354     mutable Matrix3 myMatrix;        ///< Precomputed transform matrix gathering the translation / rotation / scale / center\r
355     mutable Matrix3 myInvMatrix;     ///< Precomputed inverse transform matrix gathering the translation / rotation / scale / center\r
356 };\r
357 \r
358 } // namespace sf\r
359 \r
360 \r
361 #endif // SFML_DRAWABLE_HPP\r