Gamedev Framework (gf)  0.12.0
A C++14 framework for 2D games
Public Member Functions | List of all members
gf::SpriteWidget Class Reference

A widget with a set of sprites. More...

#include <gf/Widgets.h>

Inheritance diagram for gf::SpriteWidget:
Inheritance graph
[legend]

Public Member Functions

 SpriteWidget ()=default
 Constructor with no texture. More...
 
 SpriteWidget (const Texture &texture, const RectF &defaultRect, const RectF &selectedRect, const RectF &disabledRect)
 Constructor with a single texture and three rectangles. More...
 
 SpriteWidget (const Texture &defaultTexture, const Texture &selectedTexture, const Texture &disabledTexture)
 Constructor with three full textures. More...
 
virtual void draw (RenderTarget &target, const RenderStates &states) override
 Draw the object to a render target. More...
 
virtual bool contains (Vector2f coords) override
 Check if the widget contains the coordinates. More...
 
void setDisabledSprite (const Texture &texture, const RectF &textureRect)
 Set the texture for disabled state. More...
 
void setDefaultSprite (const Texture &texture, const RectF &textureRect)
 Set the texture for default state. More...
 
void setSelectedSprite (const Texture &texture, const RectF &textureRect)
 Set the texture for selected state. 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...
 
- Public Member Functions inherited from gf::Widget
 Widget ()
 Constructor. More...
 
void setDisabled ()
 Disable the widget. More...
 
bool isDisabled () const noexcept
 Check if the widget is disabled. More...
 
void setDefault ()
 Set the widget to it's default state. More...
 
bool isDefault () const noexcept
 Check if the widget is in default state. More...
 
void setSelected ()
 Select the widget. More...
 
bool isSelected () const
 Check if the widget is selected. More...
 
void setState (WidgetState state)
 Set the state of the widget directly. More...
 
WidgetState getState () const noexcept
 Get the state of the widget. More...
 
void setCallback (std::function< void()> callback)
 Set the callback of the widget. More...
 
void triggerCallback ()
 Execute the callback function. 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::Widget
virtual void triggered ()
 Function called when the callback is triggered. More...
 
- Protected Member Functions inherited from gf::Transformable
void setOriginFromAnchorAndBounds (Anchor anchor, const RectF &bounds)
 Set the origin from an anchor and bounds. More...
 

Detailed Description

A widget with a set of sprites.

Constructor & Destructor Documentation

◆ SpriteWidget() [1/3]

gf::SpriteWidget::SpriteWidget ( )
default

Constructor with no texture.

◆ SpriteWidget() [2/3]

gf::SpriteWidget::SpriteWidget ( const Texture texture,
const RectF defaultRect,
const RectF selectedRect,
const RectF disabledRect 
)

Constructor with a single texture and three rectangles.

Parameters
textureThe texture used for the widget
defaultRectThe rectangle in the texture used for default state
selectedRectThe rectangle in the texture used for selected state
disabledRectThe rectangle in the texture used for disabled state

◆ SpriteWidget() [3/3]

gf::SpriteWidget::SpriteWidget ( const Texture defaultTexture,
const Texture selectedTexture,
const Texture disabledTexture 
)

Constructor with three full textures.

Parameters
defaultTextureThe texture used for default state
selectedTextureThe texture used for selected state
disabledTextureThe texture used for disabled state

Member Function Documentation

◆ contains()

virtual bool gf::SpriteWidget::contains ( Vector2f  coords)
overridevirtual

Check if the widget contains the coordinates.

Parameters
coordsThe coordinates to check
Returns
True if the coordinates are inside the widget

Implements gf::Widget.

◆ draw()

virtual void gf::SpriteWidget::draw ( RenderTarget target,
const RenderStates states 
)
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.

Parameters
targetRender target to draw to
statesCurrent render states

Implements gf::Drawable.

◆ getLocalBounds()

RectF gf::SpriteWidget::getLocalBounds ( ) const
inline

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.

Returns
Local bounding rectangle of the entity

◆ setAnchor()

void gf::SpriteWidget::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().

Parameters
anchorThe anchor of the entity
See also
getLocalBounds(), Transformable::setOrigin()

◆ setDefaultSprite()

void gf::SpriteWidget::setDefaultSprite ( const Texture texture,
const RectF textureRect 
)

Set the texture for default state.

Parameters
textureThe texture used for default state
textureRectThe rectangle in the texture used for default state

◆ setDisabledSprite()

void gf::SpriteWidget::setDisabledSprite ( const Texture texture,
const RectF textureRect 
)

Set the texture for disabled state.

Parameters
textureThe texture used for disabled state
textureRectThe rectangle in the texture used for disabled state

◆ setSelectedSprite()

void gf::SpriteWidget::setSelectedSprite ( const Texture texture,
const RectF textureRect 
)

Set the texture for selected state.

Parameters
textureThe texture used for selected state
textureRectThe rectangle in the texture used for selected state