- sf
- ui
- Button
A button which does a simply task when clicked
. More...
#include <Button.hpp>
Public Member Functions | |
Button () | |
Creates a button without textures that does nothing. More... | |
Button (sf::Texture const &texture, sf::Texture const &textureFocused, sf::Texture const &textureFired) | |
Creates a button with textures that does nothing Do not forget to set the font ! More... | |
template<typename C > | |
Button (C *object, void(C::*function)()) | |
Creates a button without textures that call a function in a object Do not forget to set textures and font ! More... | |
template<typename C > | |
Button (C *object, void(C::*function)(), sf::Texture const &texture, sf::Texture const &textureFocused, sf::Texture const &textureFired) | |
Creates a button with textures that call a function in a object Do not forget to set the font ! More... | |
template<typename F > | |
Button (F function) | |
Creates a button without textures that call a function or a functor (struct with operator() ) Do not forget to set textures and font ! More... | |
template<typename F > | |
Button (F function, sf::Texture const &texture, sf::Texture const &textureFocused, sf::Texture const &textureFired) | |
Creates a button with textures that call a function or a functor (struct with operator() ) Do not forget to set the font ! More... | |
void | doClick () |
Perform a click on the button. More... | |
virtual void | updateEvent (sf::Event const &event) |
Update the component each time an event has been polled. More... | |
virtual void | updateFixed (sf::Time delta) |
Update the component with the main loop's frequency Can be useful for animation, or time's needed stuff. More... | |
bool | isFired () const |
sf::Texture const * | getTextureFired () const |
void | setTextureFired (sf::Texture const &textureFired) |
Sets the texture fired. More... | |
virtual const sf::String & | getText () const |
virtual void | setText (sf::String const &text) |
Sets the text's string of the component Don't forget to set the font. More... | |
virtual const sf::Font * | getFont () const |
virtual void | setFont (sf::Font const &font) |
Sets the font of the component's text. More... | |
virtual unsigned int | getFontSize () const |
virtual void | setFontSize (unsigned int size) |
Set the font's size of the component. More... | |
virtual sf::Color | getFontColor () const |
virtual void | setFontColor (sf::Color color) |
Sets the color's font of the text. More... | |
bool | isFocused () const |
void | setFocused (bool focused) |
Set if the component is focused. More... | |
const sf::Texture * | getTextureFocused () const |
void | setTextureFocused (const sf::Texture &textureFocused) |
Set the texture that is displayed when the component is displayed. 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 | onClick () |
Called when the button is clicked Execute the task. More... | |
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... | |
virtual bool | checkClickOn (int x, int y) const |
virtual bool | isCoordOnComponent (int x, int y) const |
virtual void | gainFocus () |
Called when the component gain focus. More... | |
virtual void | lostFocus () |
Called when the component lost focus. More... | |
void | triggerEvent (const sf::ui::ComponentEvent &event) |
Triggers the event and notify all observers. More... | |
Protected Attributes | |
sf::Texture const * | m_textureFired |
sf::Text | m_text |
bool | m_clicked |
sf::priv::ThreadFunc * | m_task |
sf::Texture const * | m_textureFocused |
bool | m_focused |
sf::Sprite | m_sprite |
sf::Texture const * | m_texture |
std::set < sf::ui::ComponentObserver * > | m_observers |
|
inline |
Creates a button without textures that does nothing.
Definition at line 40 of file Button.hpp.
|
inline |
Creates a button with textures that does nothing Do not forget to set the font !
texture | the texture of this button |
textureFocused | the texture when the button is focused |
textureFired | the texture when the button is fired |
Definition at line 58 of file Button.hpp.
|
inline |
Creates a button without textures that call a function in a object Do not forget to set textures and font !
object | the object that contains the function to execute |
function | the function to execute |
Definition at line 76 of file Button.hpp.
|
inline |
Creates a button with textures that call a function in a object Do not forget to set the font !
object | the object that contains the function to execute |
function | the function to execute |
texture | the texture of this button |
textureFocused | the texture when the button is focused |
textureFired | the texture when the button is fired |
Definition at line 97 of file Button.hpp.
|
inline |
Creates a button without textures that call a function or a functor (struct with operator() ) Do not forget to set textures and font !
function | the function/functor to execute |
Definition at line 114 of file Button.hpp.
|
inline |
Creates a button with textures that call a function or a functor (struct with operator() ) Do not forget to set the font !
function | the function/functor to execute |
texture | the texture of this button |
textureFocused | the texture when the button is focused |
textureFired | the texture when the button is fired |
Definition at line 134 of file Button.hpp.
|
inherited |
Add an observer.
|
protectedvirtualinherited |
button | - the mouse's button |
x | - the x coord |
y | - the y coord |
|
inherited |
void sf::ui::Button::doClick | ( | ) |
Perform a click on the button.
|
protectedvirtual |
Draw the component to the render target.
Reimplemented from sf::ui::Component.
|
protectedvirtualinherited |
Called when the component gain focus.
|
virtual |
Implements sf::ui::IText.
|
virtual |
Implements sf::ui::IText.
|
virtual |
Implements sf::ui::IText.
|
inherited |
|
inherited |
|
inherited |
|
virtualinherited |
Reimplemented in sf::ui::Label, and sf::ui::CheckBox.
|
virtual |
Implements sf::ui::IText.
|
inherited |
sf::Texture const* sf::ui::Button::getTextureFired | ( | ) | const |
|
inherited |
|
protectedvirtualinherited |
x | - the x coord |
y | - the y coord |
bool sf::ui::Button::isFired | ( | ) | const |
|
inherited |
|
protectedvirtualinherited |
Called when the component lost focus.
Reimplemented in sf::ui::FormattedTextField.
|
inherited |
Move the component.
vector | the move's vector |
|
inherited |
Move the component.
x | the x movement |
y | the y movement |
|
protectedvirtual |
Called when the button is clicked Execute the task.
Implements sf::ui::AbstractButton.
|
inherited |
Remove all the observers.
|
inherited |
Remove the observer at the given index.
observer | the observer to remove |
|
inherited |
Set if the component is focused.
focused | - is focused |
|
virtual |
Sets the font of the component's text.
Implements sf::ui::IText.
|
virtual |
|
virtual |
|
inherited |
Set the component's position.
position | - the position vector |
|
inherited |
Set the component's position.
x | - the x coordinate |
y | - the y coordinate |
|
virtual |
Sets the text's string of the component Don't forget to set the font.
text | the new string of the component |
Implements sf::ui::IText.
|
inherited |
Set the texture of the component.
void sf::ui::Button::setTextureFired | ( | sf::Texture const & | textureFired | ) |
Sets the texture fired.
textureFired | the texture when the button is fired |
|
inherited |
Set the texture that is displayed when the component is displayed.
textureFocused | - the texture when the component is focused |
|
protectedinherited |
Triggers the event and notify all observers.
event | - the event to push |
|
protectedvirtual |
Called when the component need update its geometry Inherit when you need to update some sprite.
Reimplemented from sf::ui::Component.
|
virtual |
Update the component each time an event has been polled.
event | the window's event polled |
Reimplemented from sf::ui::AbstractButton.
|
virtual |
Update the component with the main loop's frequency Can be useful for animation, or time's needed stuff.
delta | the time between this update and the last |
Implements sf::ui::Component.
|
inherited |
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: