Documentation of SFML 1.6

Warning: this page refers to an old version of SFML. Click here to switch to the latest version.
Drawable.hpp
1 
2 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
5 //
6 // This software is provided 'as-is', without any express or implied warranty.
7 // In no event will the authors be held liable for any damages arising from the use of this software.
8 //
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it freely,
11 // subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented;
14 // you must not claim that you wrote the original software.
15 // If you use this software in a product, an acknowledgment
16 // in the product documentation would be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source distribution.
22 //
24 
25 #ifndef SFML_DRAWABLE_HPP
26 #define SFML_DRAWABLE_HPP
27 
29 // Headers
31 #include <SFML/System/Vector2.hpp>
32 #include <SFML/Graphics/Color.hpp>
33 #include <SFML/Graphics/Matrix3.hpp>
34 
35 
36 namespace sf
37 {
38 class RenderTarget;
39 
43 namespace Blend
44 {
45  enum Mode
46  {
48  Add,
51  };
52 }
53 
58 class SFML_API Drawable
59 {
60 public :
61 
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));
72 
77  virtual ~Drawable();
78 
86  void SetPosition(float X, float Y);
87 
94  void SetPosition(const Vector2f& Position);
95 
102  void SetX(float X);
103 
110  void SetY(float Y);
111 
119  void SetScale(float ScaleX, float ScaleY);
120 
127  void SetScale(const Vector2f& Scale);
128 
135  void SetScaleX(float FactorX);
136 
143  void SetScaleY(float FactorY);
144 
154  void SetCenter(float CenterX, float CenterY);
155 
164  void SetCenter(const Vector2f& Center);
165 
172  void SetRotation(float Rotation);
173 
181  void SetColor(const Color& Col);
182 
190  void SetBlendMode(Blend::Mode Mode);
191 
198  const Vector2f& GetPosition() const;
199 
206  const Vector2f& GetScale() const;
207 
214  const Vector2f& GetCenter() const;
215 
223  float GetRotation() const;
224 
231  const Color& GetColor() const;
232 
239  Blend::Mode GetBlendMode() const;
240 
248  void Move(float OffsetX, float OffsetY);
249 
256  void Move(const Vector2f& Offset);
257 
265  void Scale(float FactorX, float FactorY);
266 
273  void Scale(const Vector2f& Factor);
274 
281  void Rotate(float Angle);
282 
292  sf::Vector2f TransformToLocal(const sf::Vector2f& Point) const;
293 
303  sf::Vector2f TransformToGlobal(const sf::Vector2f& Point) const;
304 
305 protected :
306 
313  const Matrix3& GetMatrix() const;
314 
321  const Matrix3& GetInverseMatrix() const;
322 
323 private :
324 
325  friend class RenderTarget;
326 
333  void Draw(RenderTarget& Target) const;
334 
341  virtual void Render(RenderTarget& Target) const = 0;
342 
344  // Member data
346  Vector2f myPosition;
347  Vector2f myScale;
348  Vector2f myCenter;
349  float myRotation;
350  Color myColor;
351  Blend::Mode myBlendMode;
352  mutable bool myNeedUpdate;
353  mutable bool myInvNeedUpdate;
354  mutable Matrix3 myMatrix;
355  mutable Matrix3 myInvMatrix;
356 };
357 
358 } // namespace sf
359 
360 
361 #endif // SFML_DRAWABLE_HPP