Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
GUIButton Class Reference

#include <guiButton.h>

+ Inheritance diagram for GUIButton:
+ Collaboration diagram for GUIButton:

Classes

struct  ButtonImage
 
struct  ButtonSprite
 

Public Member Functions

 GUIButton (gui::IGUIEnvironment *environment, gui::IGUIElement *parent, s32 id, core::rect< s32 > rectangle, ISimpleTextureSource *tsrc, bool noclip=false)
 constructor
 
virtual ~GUIButton ()
 destructor
 
virtual bool OnEvent (const SEvent &event) override
 called if an event happened.
 
virtual void draw () override
 draws the element and its children
 
virtual void setOverrideFont (gui::IGUIFont *font=0) override
 sets another skin independent font. if this is set to zero, the button uses the font of the skin.
 
virtual gui::IGUIFont * getOverrideFont () const override
 Gets the override font (if any)
 
virtual gui::IGUIFont * getActiveFont () const override
 Get the font which is used right now for drawing.
 
virtual void setOverrideColor (video::SColor color) override
 Sets another color for the button text.
 
virtual video::SColor getOverrideColor () const override
 Gets the override color.
 
virtual video::SColor getActiveColor () const override
 Gets the currently used text color.
 
virtual void enableOverrideColor (bool enable) override
 Sets if the button text should use the override color or the color in the gui skin.
 
virtual bool isOverrideColorEnabled (void) const override
 Checks if an override color is enabled.
 
virtual void setImage (gui::EGUI_BUTTON_IMAGE_STATE state, video::ITexture *image=nullptr, const core::rect< s32 > &sourceRect=core::rect< s32 >(0, 0, 0, 0)) override
 Sets an image which should be displayed on the button when it is in the given state.
 
virtual void setImage (video::ITexture *image=nullptr) override
 Sets an image which should be displayed on the button when it is in normal state.
 
virtual void setImage (video::ITexture *image, const core::rect< s32 > &pos) override
 Sets an image which should be displayed on the button when it is in normal state.
 
virtual void setPressedImage (video::ITexture *image=nullptr) override
 Sets an image which should be displayed on the button when it is in pressed state.
 
virtual void setPressedImage (video::ITexture *image, const core::rect< s32 > &pos) override
 Sets an image which should be displayed on the button when it is in pressed state.
 
virtual void setText (const wchar_t *text) override
 Sets the text displayed by the button.
 
virtual void setSpriteBank (gui::IGUISpriteBank *bank=0) override
 Sets the sprite bank used by the button.
 
virtual void setSprite (gui::EGUI_BUTTON_STATE state, s32 index, video::SColor color=video::SColor(255, 255, 255, 255), bool loop=false) override
 Sets the animated sprite for a specific button state.
 
virtual s32 getSpriteIndex (gui::EGUI_BUTTON_STATE state) const override
 Get the sprite-index for the given state or -1 when no sprite is set.
 
virtual video::SColor getSpriteColor (gui::EGUI_BUTTON_STATE state) const override
 Get the sprite color for the given state. Color is only used when a sprite is set.
 
virtual bool getSpriteLoop (gui::EGUI_BUTTON_STATE state) const override
 Returns if the sprite in the given state does loop.
 
virtual void setIsPushButton (bool isPushButton=true) override
 Sets if the button should behave like a push button.
 
virtual bool isPushButton () const override
 Checks whether the button is a push button.
 
virtual void setPressed (bool pressed=true) override
 Sets the pressed state of the button if this is a pushbutton.
 
virtual bool isPressed () const override
 Returns if the button is currently pressed.
 
bool isHovered () const
 Returns if this element (or one of its direct children) is hovered.
 
bool isFocused () const
 Returns if this element (or one of its direct children) is focused.
 
virtual void setDrawBorder (bool border=true) override
 Sets if the button should use the skin to draw its border.
 
virtual bool isDrawingBorder () const override
 Checks if the button face and border are being drawn.
 
virtual void setUseAlphaChannel (bool useAlphaChannel=true) override
 Sets if the alpha channel should be used for drawing images on the button (default is false)
 
virtual bool isAlphaChannelUsed () const override
 Checks if the alpha channel should be used for drawing images on the button.
 
virtual void setScaleImage (bool scaleImage=true) override
 Sets if the button should scale the button images to fit.
 
virtual bool isScalingImage () const override
 Checks whether the button scales the used images.
 
virtual bool getClickShiftState () const override
 Get if the shift key was pressed in last EGET_BUTTON_CLICKED event.
 
virtual bool getClickControlState () const override
 Get if the control key was pressed in last EGET_BUTTON_CLICKED event.
 
void setColor (video::SColor color)
 
void setFromState ()
 Set element properties from a StyleSpec corresponding to the button state.
 
virtual void setFromStyle (const StyleSpec &style)
 Set element properties from a StyleSpec.
 
void setStyles (const std::array< StyleSpec, StyleSpec::NUM_STATES > &styles)
 Set the styles used for each state.
 

Static Public Member Functions

static GUIButtonaddButton (gui::IGUIEnvironment *environment, const core::rect< s32 > &rectangle, ISimpleTextureSource *tsrc, IGUIElement *parent, s32 id, const wchar_t *text, const wchar_t *tooltiptext=L"")
 Do not drop returned handle.
 

Protected Member Functions

void drawSprite (gui::EGUI_BUTTON_STATE state, u32 startTime, const core::position2di &center)
 
gui::EGUI_BUTTON_IMAGE_STATE getImageState (bool pressed) const
 
ISimpleTextureSourcegetTextureSource ()
 
gui::EGUI_BUTTON_IMAGE_STATE getImageState (bool pressed, const ButtonImage *images) const
 

Private Attributes

ButtonSprite ButtonSprites [gui::EGBS_COUNT]
 
gui::IGUISpriteBank * SpriteBank = nullptr
 
ButtonImage ButtonImages [gui::EGBIS_COUNT]
 
std::array< StyleSpec, StyleSpec::NUM_STATESStyles
 
gui::IGUIFont * OverrideFont = nullptr
 
bool OverrideColorEnabled = false
 
video::SColor OverrideColor = video::SColor(101,255,255,255)
 
u32 ClickTime = 0
 
u32 HoverTime = 0
 
u32 FocusTime = 0
 
bool ClickShiftState = false
 
bool ClickControlState = false
 
bool IsPushButton = false
 
bool Pressed = false
 
bool UseAlphaChannel = false
 
bool DrawBorder = true
 
bool ScaleImage = false
 
video::SColor Colors [4]
 
bool WasHovered = false
 
bool WasFocused = false
 
ISimpleTextureSourceTSrc
 
gui::IGUIStaticText * StaticText
 
core::rect< s32 > BgMiddle
 
core::rect< s32 > Padding
 
core::vector2d< s32 > ContentOffset
 
video::SColor BgColor = video::SColor(0xFF,0xFF,0xFF,0xFF)
 

Constructor & Destructor Documentation

◆ GUIButton()

GUIButton::GUIButton ( gui::IGUIEnvironment * environment,
gui::IGUIElement * parent,
s32 id,
core::rect< s32 > rectangle,
ISimpleTextureSource * tsrc,
bool noclip = false )

constructor

References irr::gui::StaticText::add(), Colors, and irr::gui::StaticText::setTextAlignment().

Referenced by addButton().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ~GUIButton()

GUIButton::~GUIButton ( )
virtual

destructor

References OverrideFont, and SpriteBank.

Member Function Documentation

◆ addButton()

GUIButton * GUIButton::addButton ( gui::IGUIEnvironment * environment,
const core::rect< s32 > & rectangle,
ISimpleTextureSource * tsrc,
IGUIElement * parent,
s32 id,
const wchar_t * text,
const wchar_t * tooltiptext = L"" )
static

Do not drop returned handle.

References GUIButton(), and setText().

Referenced by GUIFormSpecMenu::parseButton(), GUIScrollBar::refreshControls(), GUIFormSpecMenu::regenerateGui(), GUIKeyChangeMenu::regenerateGui(), GUIOpenURLMenu::regenerateGui(), GUIPasswordChange::regenerateGui(), and GUIVolumeChange::regenerateGui().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ draw()

void GUIButton::draw ( )
overridevirtual

draws the element and its children

References BgColor, BgMiddle, ButtonImages, ClickTime, Colors, draw2DImage9Slice(), DrawBorder, drawSprite(), FocusTime, getImageState(), HoverTime, isFocused(), isHovered(), Pressed, ScaleImage, setFromState(), SpriteBank, UseAlphaChannel, WasFocused, and WasHovered.

+ Here is the call graph for this function:

◆ drawSprite()

void GUIButton::drawSprite ( gui::EGUI_BUTTON_STATE state,
u32 startTime,
const core::position2di & center )
protected

References ButtonSprites, GUIButton::ButtonSprite::Color, porting::getTimeMs(), GUIButton::ButtonSprite::Index, and SpriteBank.

Referenced by draw().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ enableOverrideColor()

void GUIButton::enableOverrideColor ( bool enable)
overridevirtual

Sets if the button text should use the override color or the color in the gui skin.

References OverrideColorEnabled.

◆ getActiveColor()

video::SColor GUIButton::getActiveColor ( ) const
overridevirtual

Gets the currently used text color.

◆ getActiveFont()

IGUIFont * GUIButton::getActiveFont ( ) const
overridevirtual

Get the font which is used right now for drawing.

References OverrideFont.

Referenced by GUIButtonItemImage::GUIButtonItemImage().

+ Here is the caller graph for this function:

◆ getClickControlState()

virtual bool GUIButton::getClickControlState ( ) const
inlineoverridevirtual

Get if the control key was pressed in last EGET_BUTTON_CLICKED event.

References ClickControlState.

◆ getClickShiftState()

virtual bool GUIButton::getClickShiftState ( ) const
inlineoverridevirtual

Get if the shift key was pressed in last EGET_BUTTON_CLICKED event.

References ClickShiftState.

◆ getImageState() [1/2]

EGUI_BUTTON_IMAGE_STATE GUIButton::getImageState ( bool pressed) const
protected

References ButtonImages, and getImageState().

Referenced by draw(), and getImageState().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getImageState() [2/2]

EGUI_BUTTON_IMAGE_STATE GUIButton::getImageState ( bool pressed,
const ButtonImage * images ) const
protected

References isFocused(), and isHovered().

+ Here is the call graph for this function:

◆ getOverrideColor()

video::SColor GUIButton::getOverrideColor ( ) const
overridevirtual

Gets the override color.

References OverrideColor.

◆ getOverrideFont()

IGUIFont * GUIButton::getOverrideFont ( ) const
overridevirtual

Gets the override font (if any)

References OverrideFont.

◆ getSpriteColor()

video::SColor GUIButton::getSpriteColor ( gui::EGUI_BUTTON_STATE state) const
overridevirtual

Get the sprite color for the given state. Color is only used when a sprite is set.

References ButtonSprites.

◆ getSpriteIndex()

s32 GUIButton::getSpriteIndex ( gui::EGUI_BUTTON_STATE state) const
overridevirtual

Get the sprite-index for the given state or -1 when no sprite is set.

References ButtonSprites.

◆ getSpriteLoop()

bool GUIButton::getSpriteLoop ( gui::EGUI_BUTTON_STATE state) const
overridevirtual

Returns if the sprite in the given state does loop.

References ButtonSprites.

◆ getTextureSource()

ISimpleTextureSource * GUIButton::getTextureSource ( )
inlineprotected

References TSrc.

Referenced by setFromStyle(), and GUIButtonImage::setFromStyle().

+ Here is the caller graph for this function:

◆ isAlphaChannelUsed()

bool GUIButton::isAlphaChannelUsed ( ) const
overridevirtual

Checks if the alpha channel should be used for drawing images on the button.

Returns if the alpha channel should be used for drawing images on the button.

References UseAlphaChannel.

◆ isDrawingBorder()

bool GUIButton::isDrawingBorder ( ) const
overridevirtual

Checks if the button face and border are being drawn.

References DrawBorder.

◆ isFocused()

bool GUIButton::isFocused ( ) const

Returns if this element (or one of its direct children) is focused.

Referenced by draw(), getImageState(), and setFromState().

+ Here is the caller graph for this function:

◆ isHovered()

bool GUIButton::isHovered ( ) const

Returns if this element (or one of its direct children) is hovered.

Referenced by draw(), getImageState(), and setFromState().

+ Here is the caller graph for this function:

◆ isOverrideColorEnabled()

bool GUIButton::isOverrideColorEnabled ( void ) const
overridevirtual

Checks if an override color is enabled.

References OverrideColorEnabled.

◆ isPressed()

bool GUIButton::isPressed ( ) const
overridevirtual

Returns if the button is currently pressed.

References Pressed.

Referenced by setFromState(), and setFromStyle().

+ Here is the caller graph for this function:

◆ isPushButton()

bool GUIButton::isPushButton ( ) const
overridevirtual

Checks whether the button is a push button.

Returns whether the button is a push button.

References IsPushButton.

Referenced by setIsPushButton().

+ Here is the caller graph for this function:

◆ isScalingImage()

bool GUIButton::isScalingImage ( ) const
overridevirtual

Checks whether the button scales the used images.

Returns whether the button scale the used images.

References ScaleImage.

◆ OnEvent()

bool GUIButton::OnEvent ( const SEvent & event)
overridevirtual

called if an event happened.

References ClickControlState, ClickShiftState, FocusTime, porting::getTimeMs(), HoverTime, IsPushButton, Pressed, and setPressed().

+ Here is the call graph for this function:

◆ setColor()

void GUIButton::setColor ( video::SColor color)

References BgColor, and Colors.

Referenced by setFromStyle().

+ Here is the caller graph for this function:

◆ setDrawBorder()

void GUIButton::setDrawBorder ( bool border = true)
overridevirtual

Sets if the button should use the skin to draw its border.

References DrawBorder.

Referenced by setFromStyle().

+ Here is the caller graph for this function:

◆ setFromState()

void GUIButton::setFromState ( )

Set element properties from a StyleSpec corresponding to the button state.

References StyleSpec::getStyleFromStatePropagation(), isFocused(), isHovered(), isPressed(), setFromStyle(), StyleSpec::STATE_DEFAULT, StyleSpec::STATE_FOCUSED, StyleSpec::STATE_HOVERED, StyleSpec::STATE_PRESSED, and Styles.

Referenced by draw(), setPressed(), and setStyles().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setFromStyle()

void GUIButton::setFromStyle ( const StyleSpec & style)
virtual

◆ setImage() [1/3]

virtual void GUIButton::setImage ( gui::EGUI_BUTTON_IMAGE_STATE state,
video::ITexture * image = nullptr,
const core::rect< s32 > & sourceRect = core::rect< s32 >(0, 0, 0, 0) )
overridevirtual

Sets an image which should be displayed on the button when it is in the given state.

Referenced by setFromStyle(), setImage(), setImage(), setPressedImage(), and setPressedImage().

+ Here is the caller graph for this function:

◆ setImage() [2/3]

void GUIButton::setImage ( video::ITexture * image,
const core::rect< s32 > & pos )
overridevirtual

Sets an image which should be displayed on the button when it is in normal state.

References setImage().

+ Here is the call graph for this function:

◆ setImage() [3/3]

void GUIButton::setImage ( video::ITexture * image = nullptr)
overridevirtual

Sets an image which should be displayed on the button when it is in normal state.

References setImage().

+ Here is the call graph for this function:

◆ setIsPushButton()

void GUIButton::setIsPushButton ( bool isPushButton = true)
overridevirtual

Sets if the button should behave like a push button.

Which means it can be in two states: Normal or Pressed. With a click on the button, the user can change the state of the button.

References IsPushButton, and isPushButton().

+ Here is the call graph for this function:

◆ setOverrideColor()

void GUIButton::setOverrideColor ( video::SColor color)
overridevirtual

Sets another color for the button text.

Sets another color for the text.

References OverrideColor, OverrideColorEnabled, and irr::gui::StaticText::setOverrideColor().

Referenced by setFromStyle().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setOverrideFont()

void GUIButton::setOverrideFont ( gui::IGUIFont * font = 0)
overridevirtual

sets another skin independent font. if this is set to zero, the button uses the font of the skin.

References OverrideFont, and irr::gui::StaticText::setOverrideFont().

Referenced by setFromStyle().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setPressed()

void GUIButton::setPressed ( bool pressed = true)
overridevirtual

Sets the pressed state of the button if this is a pushbutton.

References ClickTime, porting::getTimeMs(), Pressed, and setFromState().

Referenced by OnEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setPressedImage() [1/2]

void GUIButton::setPressedImage ( video::ITexture * image,
const core::rect< s32 > & pos )
overridevirtual

Sets an image which should be displayed on the button when it is in pressed state.

References setImage().

+ Here is the call graph for this function:

◆ setPressedImage() [2/2]

void GUIButton::setPressedImage ( video::ITexture * image = nullptr)
overridevirtual

Sets an image which should be displayed on the button when it is in pressed state.

References setImage().

+ Here is the call graph for this function:

◆ setScaleImage()

void GUIButton::setScaleImage ( bool scaleImage = true)
overridevirtual

Sets if the button should scale the button images to fit.

Sets if the images should be scaled to fit the button.

References ScaleImage.

Referenced by GUIButtonImage::GUIButtonImage(), GUIFormSpecMenu::parseImageButton(), and setFromStyle().

+ Here is the caller graph for this function:

◆ setSprite()

void GUIButton::setSprite ( gui::EGUI_BUTTON_STATE state,
s32 index,
video::SColor color = video::SColor(255,255,255,255),
bool loop = false )
overridevirtual

Sets the animated sprite for a specific button state.

Parameters
indexNumber of the sprite within the sprite bank, use -1 for no sprite
stateState of the button to set the sprite for
indexThe sprite number from the current sprite bank
colorThe color of the sprite

References ButtonSprites.

◆ setSpriteBank()

void GUIButton::setSpriteBank ( gui::IGUISpriteBank * bank = 0)
overridevirtual

Sets the sprite bank used by the button.

References SpriteBank.

◆ setStyles()

void GUIButton::setStyles ( const std::array< StyleSpec, StyleSpec::NUM_STATES > & styles)

Set the styles used for each state.

References setFromState(), and Styles.

Referenced by GUIFormSpecMenu::parseButton(), GUIFormSpecMenu::parseImageButton(), and GUIFormSpecMenu::parseItemImageButton().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setText()

void GUIButton::setText ( const wchar_t * text)
overridevirtual

Sets the text displayed by the button.

References irr::gui::StaticText::setText().

Referenced by addButton(), GUIButtonImage::addButton(), and GUIButtonItemImage::addButton().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setUseAlphaChannel()

void GUIButton::setUseAlphaChannel ( bool useAlphaChannel = true)
overridevirtual

Sets if the alpha channel should be used for drawing images on the button (default is false)

References UseAlphaChannel.

Referenced by setFromStyle().

+ Here is the caller graph for this function:

Member Data Documentation

◆ BgColor

video::SColor GUIButton::BgColor = video::SColor(0xFF,0xFF,0xFF,0xFF)
private

Referenced by draw(), setColor(), and setFromStyle().

◆ BgMiddle

core::rect<s32> GUIButton::BgMiddle
private

Referenced by draw(), and setFromStyle().

◆ ButtonImages

ButtonImage GUIButton::ButtonImages[gui::EGBIS_COUNT]
private

Referenced by draw(), and getImageState().

◆ ButtonSprites

ButtonSprite GUIButton::ButtonSprites[gui::EGBS_COUNT]
private

◆ ClickControlState

bool GUIButton::ClickControlState = false
private

Referenced by getClickControlState(), and OnEvent().

◆ ClickShiftState

bool GUIButton::ClickShiftState = false
private

Referenced by getClickShiftState(), and OnEvent().

◆ ClickTime

u32 GUIButton::ClickTime = 0
private

Referenced by draw(), and setPressed().

◆ Colors

video::SColor GUIButton::Colors[4]
private

◆ ContentOffset

core::vector2d<s32> GUIButton::ContentOffset
private

Referenced by setFromStyle().

◆ DrawBorder

bool GUIButton::DrawBorder = true
private

◆ FocusTime

u32 GUIButton::FocusTime = 0
private

Referenced by draw(), and OnEvent().

◆ HoverTime

u32 GUIButton::HoverTime = 0
private

Referenced by draw(), and OnEvent().

◆ IsPushButton

bool GUIButton::IsPushButton = false
private

◆ OverrideColor

video::SColor GUIButton::OverrideColor = video::SColor(101,255,255,255)
private

◆ OverrideColorEnabled

bool GUIButton::OverrideColorEnabled = false
private

◆ OverrideFont

gui::IGUIFont* GUIButton::OverrideFont = nullptr
private

◆ Padding

core::rect<s32> GUIButton::Padding
private

Referenced by setFromStyle().

◆ Pressed

bool GUIButton::Pressed = false
private

Referenced by draw(), isPressed(), OnEvent(), and setPressed().

◆ ScaleImage

bool GUIButton::ScaleImage = false
private

Referenced by draw(), isScalingImage(), and setScaleImage().

◆ SpriteBank

gui::IGUISpriteBank* GUIButton::SpriteBank = nullptr
private

◆ StaticText

gui::IGUIStaticText* GUIButton::StaticText
private

◆ Styles

std::array<StyleSpec, StyleSpec::NUM_STATES> GUIButton::Styles
private

◆ TSrc

ISimpleTextureSource* GUIButton::TSrc
private

Referenced by getTextureSource().

◆ UseAlphaChannel

bool GUIButton::UseAlphaChannel = false
private

◆ WasFocused

bool GUIButton::WasFocused = false
private

Referenced by draw().

◆ WasHovered

bool GUIButton::WasHovered = false
private

Referenced by draw().


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