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);
214 GLCheck(glDisable(GL_TEXTURE_2D));
219 glVertex2f(0, Height);
220 glVertex2f(Width, Height);
221 glVertex2f(Width, 0);
virtual void Render(RenderTarget &Target) const
/see Drawable::Render
T x
X coordinate of the vector.
const Vector2f & GetScale() const
Get the current scale of the object.
const Color & GetColor() const
Get the color of the object.
Vector2f GetSize() const
Get the sprite size.
void FlipY(bool Flipped)
Flip the sprite vertically.
Abstract base class for every object that can be drawn into a render window.
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 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.
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.
T GetHeight() const
Get the height of the rectangle.
void FlipX(bool Flipped)
Flip the sprite horizontally.
const IntRect & GetSubRect() const
Get the sub-rectangle of the sprite inside the source image.
void SetScale(float ScaleX, float ScaleY)
Set the scale of the object (take 2 values)
void SetImage(const Image &Img)
Change the image of the sprite.
Sprite()
Default constructor.
unsigned int GetWidth() const
Return the width of the image.
Color is an utility class for manipulating 32-bits RGBA colors.
T Bottom
Bottom coordinate of the rectangle.
T GetWidth() const
Get the width of the rectangle.
T y
Y coordinate of the vector.
Base class for all render targets (window, image, ...)
unsigned int GetHeight() const
Return the height of the image.
T Top
Top coordinate of the rectangle.
T Left
Left coordinate of the rectangle.