28#include <SFML/Graphics/Sprite.hpp>
29#include <SFML/Graphics/Image.hpp>
30#include <SFML/Graphics/GraphicsContext.hpp>
39mySubRect (0, 0, 1, 1),
52mySubRect (0, 0, 1, 1),
91 int LocalWidth = mySubRect.
GetWidth();
92 int LocalHeight = mySubRect.GetHeight();
94 if ((LocalWidth > 0) && (LocalHeight > 0))
95 SetScale(Width / LocalWidth, Height / LocalHeight);
114 myIsFlippedX = Flipped;
123 myIsFlippedY = Flipped;
150 return Vector2f(mySubRect.GetWidth() *
GetScale().x, mySubRect.GetHeight() *
GetScale().y);
162 unsigned int ImageX = mySubRect.Left + X;
163 unsigned int ImageY = mySubRect.Top + Y;
165 if (myIsFlippedX) ImageX = mySubRect.GetWidth() - ImageX - 1;
166 if (myIsFlippedY) ImageY = mySubRect.GetHeight() - ImageY - 1;
168 return myImage->GetPixel(ImageX, ImageY) *
GetColor();
183 float Width =
static_cast<float>(mySubRect.GetWidth());
184 float Height =
static_cast<float>(mySubRect.GetHeight());
187 if (myImage && (myImage->GetWidth() > 0) && (myImage->GetHeight() > 0))
191 GLCheck(glTranslatef(0.375f, 0.375f, 0.f));
197 FloatRect TexCoords = myImage->GetTexCoords(mySubRect);
198 FloatRect
Rect(myIsFlippedX ? TexCoords.
Right : TexCoords.
Left,
199 myIsFlippedY ? TexCoords.
Bottom : TexCoords.
Top,
200 myIsFlippedX ? TexCoords.
Left : TexCoords.
Right,
201 myIsFlippedY ? TexCoords.
Top : TexCoords.
Bottom);
214 GLCheck(glDisable(GL_TEXTURE_2D));
219 glVertex2f(0, Height);
220 glVertex2f(Width, Height);
221 glVertex2f(Width, 0);
Color is an utility class for manipulating 32-bits RGBA colors.
void SetScale(float ScaleX, float ScaleY)
Set the scale of the object (take 2 values).
void Scale(float FactorX, float FactorY)
Scale the object (take 2 values).
const Vector2f & GetScale() const
Get the current scale of the object.
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.
const Color & GetColor() const
Get the color of the object.
Image is the low-level class for loading and manipulating images.
unsigned int GetHeight() const
Return the height of the image.
unsigned int GetWidth() const
Return the width of the image.
Rect is an utility class for manipulating rectangles.
T GetWidth() const
Get the width of the rectangle.
T Top
Top coordinate of the rectangle.
T Right
Right coordinate of the rectangle.
T Left
Left coordinate of the rectangle.
T Bottom
Bottom coordinate of the rectangle.
Color GetPixel(unsigned int X, unsigned int Y) const
Get the color of a given pixel in the sprite (point is in local coordinates).
void FlipX(bool Flipped)
Flip the sprite horizontally.
void SetImage(const Image &Img)
Change the image of the sprite.
void Resize(float Width, float Height)
Resize the sprite (by changing its scale factors) (take 2 values).
void SetSubRect(const IntRect &SubRect)
Set the sub-rectangle of the sprite inside the source image.
const Image * GetImage() const
Get the source image of the sprite.
virtual void Render(RenderTarget &Target) const
/see Drawable::Render
const IntRect & GetSubRect() const
Get the sub-rectangle of the sprite inside the source image.
void FlipY(bool Flipped)
Flip the sprite vertically.
Sprite()
Default constructor.
Vector2f GetSize() const
Get the sprite size.
T x
X coordinate of the vector.
T y
Y coordinate of the vector.