28 #include <SFML/Graphics/Sprite.hpp>
29 #include <SFML/Graphics/Image.hpp>
30 #include <SFML/Graphics/GraphicsContext.hpp>
39 mySubRect (0, 0, 1, 1),
51 Drawable (Position, Scale, Rotation, Col),
52 mySubRect (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);
205 glTexCoord2f(Rect.
Left, Rect.
Top); glVertex2f(0, 0);
206 glTexCoord2f(Rect.
Left, Rect.
Bottom); glVertex2f(0, Height);
207 glTexCoord2f(Rect.
Right, Rect.
Bottom); glVertex2f(Width, Height);
208 glTexCoord2f(Rect.
Right, Rect.
Top); glVertex2f(Width, 0) ;
214 GLCheck(glDisable(GL_TEXTURE_2D));
219 glVertex2f(0, Height);
220 glVertex2f(Width, Height);
221 glVertex2f(Width, 0);
Vector2f GetSize() const
Get the sprite size.
virtual void Render(RenderTarget &Target) const
/see Drawable::Render
T x
X coordinate of the vector.
unsigned int GetWidth() const
Return the width of the image.
void FlipY(bool Flipped)
Flip the sprite vertically.
Abstract base class for every object that can be drawn into a render window.
void Resize(float Width, float Height)
Resize the sprite (by changing its scale factors) (take 2 values).
T Right
Right coordinate of the rectangle.
const Image * GetImage() const
Get the source image of the sprite.
T GetHeight() const
Get the height of the rectangle.
Image is the low-level class for loading and manipulating images.
void SetSubRect(const IntRect &SubRect)
Set the sub-rectangle of the sprite inside the source image.
const Vector2f & GetScale() const
Get the current scale of the object.
void FlipX(bool Flipped)
Flip the sprite horizontally.
void SetScale(float ScaleX, float ScaleY)
Set the scale of the object (take 2 values)
T GetWidth() const
Get the width 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 SetImage(const Image &Img)
Change the image of the sprite.
Sprite()
Default constructor.
const Color & GetColor() const
Get the color of the object.
Color is an utility class for manipulating 32-bits RGBA colors.
T Bottom
Bottom coordinate of the rectangle.
T y
Y coordinate of the vector.
unsigned int GetHeight() const
Return the height of the image.
Base class for all render targets (window, image, ...)
const IntRect & GetSubRect() const
Get the sub-rectangle of the sprite inside the source image.
T Top
Top coordinate of the rectangle.
T Left
Left coordinate of the rectangle.