Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
sf::ui::Component Class Referenceabstract

The base class for all UI components

. More...

#include <Component.hpp>

Inheritance diagram for sf::ui::Component:
sf::ui::ComponentObservable sf::ui::Focusable sf::ui::Label sf::ui::AbstractButton sf::ui::KeyField sf::ui::TextField sf::ui::Button sf::ui::CheckBox sf::ui::FormattedTextField sf::ui::PasswordField

Public Member Functions

 Component ()
 Creates an empty component, without texture. More...
 
 Component (sf::Texture const &texture)
 Creates a component with the give texture. More...
 
virtual void updateEvent (sf::Event const &event)=0
 Update the component each time an event has been polled. More...
 
virtual void updateFixed (sf::Time delta)=0
 Update the component with the main loop's frequency Can be useful for animation, or time's needed stuff. More...
 
void updateSize ()
 Update the size of the component Call it when you update your texture after it was set, to recalculate the component's size with new texture loaded. More...
 
void move (sf::Vector2f const &vector)
 Move the component. More...
 
void move (float x, float y)
 Move the component. More...
 
const sf::Texture * getTexture () const
 
void setTexture (const sf::Texture &texture)
 Set the texture of the component. More...
 
const sf::Vector2f & getPosition () const
 
void setPosition (sf::Vector2f const &position)
 Set the component's position. More...
 
void setPosition (float x, float y)
 Set the component's position. More...
 
virtual sf::Vector2f getSize () const
 
void addObserver (sf::ui::ComponentObserver *observer)
 Add an observer. More...
 
std::set
< sf::ui::ComponentObserver * >
::const_iterator 
getObserversBegin () const
 
std::set
< sf::ui::ComponentObserver * >
::const_iterator 
getObserversEnd () const
 
int countObservers ()
 
void removeObserver (sf::ui::ComponentObserver *observer)
 Remove the observer at the given index. More...
 
void removeAllObservers ()
 Remove all the observers. More...
 

Protected Member Functions

virtual void draw (sf::RenderTarget &target, sf::RenderStates states) const
 Draw the component to the render target. More...
 
virtual void updateCoord ()
 Called when the component need update its geometry Inherit when you need to update some sprite. More...
 
void triggerEvent (const sf::ui::ComponentEvent &event)
 Triggers the event and notify all observers. More...
 

Protected Attributes

sf::Sprite m_sprite
 
sf::Texture const * m_texture
 
std::set
< sf::ui::ComponentObserver * > 
m_observers
 

Detailed Description

The base class for all UI components

.

Definition at line 29 of file Component.hpp.

Constructor & Destructor Documentation

sf::ui::Component::Component ( )

Creates an empty component, without texture.

sf::ui::Component::Component ( sf::Texture const &  texture)

Creates a component with the give texture.

Parameters
texture- the texture displayed by the component

Member Function Documentation

void sf::ui::ComponentObservable::addObserver ( sf::ui::ComponentObserver observer)
inherited

Add an observer.

int sf::ui::ComponentObservable::countObservers ( )
inherited
Returns
the number of observers
virtual void sf::ui::Component::draw ( sf::RenderTarget &  target,
sf::RenderStates  states 
) const
protectedvirtual

Draw the component to the render target.

Reimplemented in sf::ui::Button, sf::ui::CheckBox, sf::ui::Label, sf::ui::TextField, and sf::ui::KeyField.

std::set<sf::ui::ComponentObserver*>::const_iterator sf::ui::ComponentObservable::getObserversBegin ( ) const
inherited
Returns
the begin of the observers' iterator
std::set<sf::ui::ComponentObserver*>::const_iterator sf::ui::ComponentObservable::getObserversEnd ( ) const
inherited
Returns
the end of the observers' iterator
const sf::Vector2f& sf::ui::Component::getPosition ( ) const
Returns
the position of the component
virtual sf::Vector2f sf::ui::Component::getSize ( ) const
virtual
Returns
the size of the component

Reimplemented in sf::ui::Label, and sf::ui::CheckBox.

const sf::Texture* sf::ui::Component::getTexture ( ) const
Returns
the texture of the component
void sf::ui::Component::move ( sf::Vector2f const &  vector)

Move the component.

Parameters
vectorthe move's vector
void sf::ui::Component::move ( float  x,
float  y 
)

Move the component.

Parameters
xthe x movement
ythe y movement
void sf::ui::ComponentObservable::removeAllObservers ( )
inherited

Remove all the observers.

void sf::ui::ComponentObservable::removeObserver ( sf::ui::ComponentObserver observer)
inherited

Remove the observer at the given index.

Parameters
observerthe observer to remove
void sf::ui::Component::setPosition ( sf::Vector2f const &  position)

Set the component's position.

Parameters
position- the position vector
void sf::ui::Component::setPosition ( float  x,
float  y 
)

Set the component's position.

Parameters
x- the x coordinate
y- the y coordinate
void sf::ui::Component::setTexture ( const sf::Texture &  texture)

Set the texture of the component.

void sf::ui::ComponentObservable::triggerEvent ( const sf::ui::ComponentEvent event)
protectedinherited

Triggers the event and notify all observers.

Parameters
event- the event to push
virtual void sf::ui::Component::updateCoord ( )
protectedvirtual

Called when the component need update its geometry Inherit when you need to update some sprite.

Reimplemented in sf::ui::Button, sf::ui::Label, sf::ui::CheckBox, sf::ui::TextField, and sf::ui::KeyField.

virtual void sf::ui::Component::updateEvent ( sf::Event const &  event)
pure virtual

Update the component each time an event has been polled.

Parameters
eventthe window's event polled

Implemented in sf::ui::Button, sf::ui::TextField, sf::ui::KeyField, sf::ui::Label, and sf::ui::AbstractButton.

virtual void sf::ui::Component::updateFixed ( sf::Time  delta)
pure virtual

Update the component with the main loop's frequency Can be useful for animation, or time's needed stuff.

Parameters
deltathe time between this update and the last one

Implemented in sf::ui::Button, sf::ui::TextField, sf::ui::CheckBox, sf::ui::KeyField, and sf::ui::Label.

void sf::ui::Component::updateSize ( )

Update the size of the component Call it when you update your texture after it was set, to recalculate the component's size with new texture loaded.

Example:

sf::Texture texture;
sf::Label label(texture); // Now label has a pointer to texture, moreover its size is (0;0)
texture.loadFromFile("texture.png"); // New texture loaded, and so its size has changed
label.updateSize(); // Tell label that it have to change its size, and calculate it with the updated texture's size

The documentation for this class was generated from the following file: