Gamedev Framework (gf)
0.3.0
A C++11 framework for 2D games
|
A nine-patch. More...
#include <gf/NinePatch.h>
Public Member Functions | |
NinePatch () | |
Default constructor. More... | |
NinePatch (const Texture &texture) | |
Construct the nine-patch from a source texture. More... | |
NinePatch (const Texture &texture, const RectF &textureRect) | |
Construct the nine-patch from a sub-rectangle of a source texture. More... | |
void | setTexture (const Texture &texture, bool resetRect=false) |
Change the source texture of the nine-patch. More... | |
const Texture * | getTexture () const |
Get the source texture of the nine-patch. More... | |
void | unsetTexture () |
Unset the source texture of the nine-patch. More... | |
void | setTextureRect (const RectF &rect) |
Set the sub-rectangle of the texture that the nine-patch will display. More... | |
const RectF & | getTextureRect () const |
Get the sub-rectangle of the texture displayed by the nine-patch. More... | |
void | setColor (const Color4f &color) |
Set the global color of the nine-patch. More... | |
const Color4f & | getColor () const |
Get the global color of the nine-patch. More... | |
void | setLimits (float top, float bottom, float left, float right) |
Set the limits of the stretchable area. More... | |
void | setVerticalLimits (float top, float bottom) |
Set the vertical limits of the stretchable area. More... | |
void | setHorizontalLimits (float left, float right) |
Set the horizontal limits of the stretchable area. More... | |
void | setSize (Vector2f size) |
Set the size of the stretched area. More... | |
Vector2f | getSize () const |
Get the size of the stretched area. More... | |
RectF | getLocalBounds () const |
Get the local bounding rectangle of the entity. More... | |
void | setAnchor (Anchor anchor) |
Set the anchor origin of the entity. More... | |
VertexBuffer | commitGeometry () const |
Create a buffer with the current geometry. More... | |
virtual void | draw (RenderTarget &target, RenderStates states) override |
Draw the object to a render target. More... | |
Public Member Functions inherited from gf::Transformable | |
Transformable () | |
Default constructor. More... | |
void | setOrigin (Vector2f origin) |
Set the local origin of the object. More... | |
Vector2f | getOrigin () const |
Get the local origin of the object. More... | |
void | setPosition (Vector2f position) |
Set the position of the object. More... | |
Vector2f | getPosition () const |
Get the position of the object. More... | |
void | move (Vector2f offset) |
Move the object by a given offset. More... | |
void | setRotation (float angle) |
Set the orientation of the object. More... | |
float | getRotation () const |
Get the orientation of the object. More... | |
void | rotate (float angle) |
Rotate the object. More... | |
void | setScale (Vector2f factors) |
Set the scale factors of the object. More... | |
void | setScale (float factor) |
Set the scale factor of the object. More... | |
Vector2f | getScale () const |
Get the current scale of the object. More... | |
void | scale (Vector2f factors) |
Scale the object. More... | |
void | scale (float factor) |
Scale the object. More... | |
Matrix3f | getTransform () const |
Get the combined transform of the object. More... | |
Matrix3f | getInverseTransform () const |
Get the inverse of the combined transform of the object. More... | |
Public Member Functions inherited from gf::Drawable | |
virtual | ~Drawable () |
Virtual desctructor. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from gf::Transformable | |
void | setOriginFromAnchorAndBounds (Anchor anchor, const RectF &bounds) |
Set the origin from an anchor and bounds. More... | |
A nine-patch.
A nine-patch is a stretchable image that can be automatically resized. You just have to indicate the position of the stretchable area and that's it.
gf::NinePatch::NinePatch | ( | ) |
Default constructor.
Creates an empty nine-patch with no source texture
gf::NinePatch::NinePatch | ( | const Texture & | texture | ) |
Construct the nine-patch from a source texture.
texture | Source texture |
Construct the nine-patch from a sub-rectangle of a source texture.
texture | Source texture |
textureRect | Sub-rectangle of the texture to assign to the nine-patch |
VertexBuffer gf::NinePatch::commitGeometry | ( | ) | const |
Create a buffer with the current geometry.
The geometry is uploaded in the graphics memory so that it's faster to draw.
|
overridevirtual |
Draw the object to a render target.
This is a pure virtual function that has to be implemented by the derived class to define how the drawable should be drawn.
target | Render target to draw to |
states | Current render states |
Implements gf::Drawable.
const Color4f& gf::NinePatch::getColor | ( | ) | const |
RectF gf::NinePatch::getLocalBounds | ( | ) | const |
Get the local bounding rectangle of the entity.
The returned rectangle is in local coordinates, which means that it ignores the transformations (translation, rotation, scale, ...) that are applied to the entity. In other words, this function returns the bounds of the entity in the entity's coordinate system.
|
inline |
Get the size of the stretched area.
|
inline |
Get the source texture of the nine-patch.
If the nine-patch has no source texture, a nullptr
pointer is returned. The returned pointer is const, which means that you can't modify the texture when you retrieve it with this function.
|
inline |
Get the sub-rectangle of the texture displayed by the nine-patch.
void gf::NinePatch::setAnchor | ( | Anchor | anchor | ) |
Set the anchor origin of the entity.
Compute the origin of the entity based on the local bounds and the specified anchor. Internally, this function calls Transformable::setOrigin()
.
anchor | The anchor of the entity |
void gf::NinePatch::setColor | ( | const Color4f & | color | ) |
Set the global color of the nine-patch.
This color is modulated (multiplied) with the nine-patch's texture. It can be used to colorize the nine-patch, or change its global opacity.
By default, the nine-patch's color is opaque white.
color | New color of the nine-patch |
void gf::NinePatch::setHorizontalLimits | ( | float | left, |
float | right | ||
) |
Set the horizontal limits of the stretchable area.
The limits are given in normalized coordinates
left | The left limit |
right | The right limit |
void gf::NinePatch::setLimits | ( | float | top, |
float | bottom, | ||
float | left, | ||
float | right | ||
) |
Set the limits of the stretchable area.
The limits are given in normalized coordinates
top | The top limit |
bottom | The bottom limit |
left | The left limit |
right | The right limit |
void gf::NinePatch::setSize | ( | Vector2f | size | ) |
Set the size of the stretched area.
size | The size of the stretched area |
void gf::NinePatch::setTexture | ( | const Texture & | texture, |
bool | resetRect = false |
||
) |
Change the source texture of the nine-patch.
The texture must exist as long as the nine-patch uses it. Indeed, the nine-patch doesn't store its own copy of the texture, but rather keeps a pointer to the one that you passed to this function. If the source texture is destroyed and the nine-patch tries to use it, the behavior is undefined.
If resetRect
is true, the texture rect property of the nine-patch is automatically adjusted to the size of the new texture. If it is false, the texture rect is left unchanged.
texture | New texture |
resetRect | Should the texture rect be reset to the size of the new texture? |
void gf::NinePatch::setTextureRect | ( | const RectF & | rect | ) |
Set the sub-rectangle of the texture that the nine-patch will display.
The texture rect is useful when you don't want to display the whole texture, but rather a part of it. By default, the texture rect covers the entire texture.
The rectangle is given in texture coordinates, meaning that \((0,0)\) is the top left corner and \((1,1)\) is the bottom right corner.
rect | Rectangle defining the region of the texture to display |
void gf::NinePatch::setVerticalLimits | ( | float | top, |
float | bottom | ||
) |
Set the vertical limits of the stretchable area.
The limits are given in normalized coordinates
top | The top limit |
bottom | The bottom limit |
void gf::NinePatch::unsetTexture | ( | ) |
Unset the source texture of the nine-patch.
After a call to this function, the nine-patch has no source texture.