28#include <SFML/Graphics/Sprite.hpp>
29#include <SFML/Graphics/Image.hpp>
30#include <SFML/Graphics/GraphicsContext.hpp>
39mySubRect (0, 0, 1, 1),
51Drawable (Position, Scale, Rotation, Col),
52mySubRect (0, 0, 1, 1),
91 int LocalWidth = mySubRect.
GetWidth();
94 if ((LocalWidth > 0) && (LocalHeight > 0))
95 SetScale(Width / LocalWidth, Height / LocalHeight);
114 myIsFlippedX = Flipped;
123 myIsFlippedY = Flipped;
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);
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.
Abstract base class for every object that can be drawn into a render window.
void SetScale(float ScaleX, float ScaleY)
Set the scale of the object (take 2 values)
const Vector2f & GetScale() const
Get the current scale of the object.
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.
T GetWidth() const
Get the width of the rectangle.
T GetHeight() const
Get the height 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.
Base class for all render targets (window, image, ...)
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.