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
36namespace sf
37{
38class RenderTarget;
39
43namespace Blend
44{
52}
53
58class SFML_API Drawable
59{
60public :
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
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
305protected :
306
313 const Matrix3& GetMatrix() const;
314
321 const Matrix3& GetInverseMatrix() const;
322
323private :
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
Color is an utility class for manipulating 32-bits RGBA colors.
Definition Color.hpp:41
void SetScale(float ScaleX, float ScaleY)
Set the scale of the object (take 2 values).
Definition Drawable.cpp:107
void SetScaleX(float FactorX)
Set the X scale factor of the object.
Definition Drawable.cpp:127
void SetCenter(float CenterX, float CenterY)
Set the center of the object, in coordinates relative to the top-left of the object (take 2 values).
Definition Drawable.cpp:157
const Matrix3 & GetMatrix() const
Get the transform matrix of the drawable.
Definition Drawable.cpp:334
void Scale(float FactorX, float FactorY)
Scale the object (take 2 values).
Definition Drawable.cpp:287
const Vector2f & GetPosition() const
Get the position of the object.
Definition Drawable.cpp:213
const Vector2f & GetScale() const
Get the current scale of the object.
Definition Drawable.cpp:222
void Rotate(float Angle)
Rotate the object.
Definition Drawable.cpp:306
void SetPosition(float X, float Y)
Set the position of the object (take 2 values).
Definition Drawable.cpp:65
const Matrix3 & GetInverseMatrix() const
Get the inverse transform matrix of the drawable.
Definition Drawable.cpp:350
void Move(float OffsetX, float OffsetY)
Move the object of a given offset (take 2 values).
Definition Drawable.cpp:268
void SetRotation(float Rotation)
Set the orientation of the object.
Definition Drawable.cpp:180
sf::Vector2f TransformToGlobal(const sf::Vector2f &Point) const
Transform a point from local coordinates into global coordinates (ie it applies the object's center,...
Definition Drawable.cpp:325
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))
Default constructor.
Definition Drawable.cpp:39
Blend::Mode GetBlendMode() const
Get the current blending mode.
Definition Drawable.cpp:258
const Color & GetColor() const
Get the color of the object.
Definition Drawable.cpp:249
void SetY(float Y)
Set the Y position of the object.
Definition Drawable.cpp:96
void SetScaleY(float FactorY)
Set the Y scale factor of the object.
Definition Drawable.cpp:141
void SetColor(const Color &Col)
Set the color of the object.
Definition Drawable.cpp:194
void SetBlendMode(Blend::Mode Mode)
Set the blending mode for the object.
Definition Drawable.cpp:204
const Vector2f & GetCenter() const
Get the center of the object.
Definition Drawable.cpp:231
void SetX(float X)
Set the X position of the object.
Definition Drawable.cpp:85
sf::Vector2f TransformToLocal(const sf::Vector2f &Point) const
Transform a point from global coordinates into local coordinates (ie it applies the inverse of object...
Definition Drawable.cpp:316
float GetRotation() const
Get the orientation of the object.
Definition Drawable.cpp:240
Utility class to manipulate 3x3 matrices representing 2D transformations.
Definition Matrix3.hpp:43
Base class for all render targets (window, image, ...).
Enumerate the blending modes for drawable objects.
Definition Drawable.hpp:44
@ Alpha
Pixel = Src * a + Dest * (1 - a).
Definition Drawable.hpp:47
@ None
No blending.
Definition Drawable.hpp:50
@ Multiply
Pixel = Src * Dest.
Definition Drawable.hpp:49
@ Add
Pixel = Src + Dest.
Definition Drawable.hpp:48