2019-12-12 17:32:41 +01:00
|
|
|
// Copyright (C) 2002-2012 Nikolaus Gebhardt
|
|
|
|
// This file is part of the "Irrlicht Engine".
|
|
|
|
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
|
|
|
|
2021-08-27 17:55:04 +02:00
|
|
|
#ifndef IRR_C_GUI_BUTTON_H_INCLUDED
|
|
|
|
#define IRR_C_GUI_BUTTON_H_INCLUDED
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
#include "IrrCompileConfig.h"
|
|
|
|
#ifdef _IRR_COMPILE_WITH_GUI_
|
|
|
|
|
|
|
|
#include "IGUIButton.h"
|
|
|
|
#include "IGUISpriteBank.h"
|
|
|
|
#include "ITexture.h"
|
|
|
|
#include "SColor.h"
|
|
|
|
|
|
|
|
namespace irr
|
|
|
|
{
|
|
|
|
namespace gui
|
|
|
|
{
|
|
|
|
|
|
|
|
class CGUIButton : public IGUIButton
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
//! constructor
|
|
|
|
CGUIButton(IGUIEnvironment* environment, IGUIElement* parent,
|
|
|
|
s32 id, core::rect<s32> rectangle, bool noclip=false);
|
|
|
|
|
|
|
|
//! destructor
|
|
|
|
virtual ~CGUIButton();
|
|
|
|
|
|
|
|
//! called if an event happened.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual bool OnEvent(const SEvent& event) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! draws the element and its children
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void draw() IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! sets another skin independent font. if this is set to zero, the button uses the font of the skin.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setOverrideFont(IGUIFont* font=0) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Gets the override font (if any)
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual IGUIFont* getOverrideFont() const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Get the font which is used right now for drawing
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual IGUIFont* getActiveFont() const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Sets another color for the button text.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setOverrideColor(video::SColor color) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Gets the override color
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual video::SColor getOverrideColor(void) const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
2020-12-10 15:45:30 +01:00
|
|
|
//! Gets the currently used text color
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual video::SColor getActiveColor() const IRR_OVERRIDE;
|
2020-12-10 15:45:30 +01:00
|
|
|
|
2019-12-12 17:32:41 +01:00
|
|
|
//! Sets if the button text should use the override color or the color in the gui skin.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void enableOverrideColor(bool enable) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Checks if an override color is enabled
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual bool isOverrideColorEnabled(void) const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Sets an image which should be displayed on the button when it is in the given state.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setImage(EGUI_BUTTON_IMAGE_STATE state, video::ITexture* image=0, const core::rect<s32>& sourceRect=core::rect<s32>(0,0,0,0)) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Sets an image which should be displayed on the button when it is in normal state.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setImage(video::ITexture* image=0) IRR_OVERRIDE
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
|
|
|
setImage(EGBIS_IMAGE_UP, image);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Sets an image which should be displayed on the button when it is in normal state.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setImage(video::ITexture* image, const core::rect<s32>& pos) IRR_OVERRIDE
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
|
|
|
setImage(EGBIS_IMAGE_UP, image, pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Sets an image which should be displayed on the button when it is in pressed state.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setPressedImage(video::ITexture* image=0) IRR_OVERRIDE
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
|
|
|
setImage(EGBIS_IMAGE_DOWN, image);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Sets an image which should be displayed on the button when it is in pressed state.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setPressedImage(video::ITexture* image, const core::rect<s32>& pos) IRR_OVERRIDE
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
|
|
|
setImage(EGBIS_IMAGE_DOWN, image, pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Sets the sprite bank used by the button
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setSpriteBank(IGUISpriteBank* bank=0) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Sets the animated sprite for a specific button state
|
|
|
|
/** \param index: Number of the sprite within the sprite bank, use -1 for no sprite
|
|
|
|
\param state: State of the button to set the sprite for
|
|
|
|
\param index: The sprite number from the current sprite bank
|
|
|
|
\param color: The color of the sprite
|
|
|
|
*/
|
|
|
|
virtual void setSprite(EGUI_BUTTON_STATE state, s32 index,
|
|
|
|
video::SColor color=video::SColor(255,255,255,255),
|
2021-08-27 14:55:10 +02:00
|
|
|
bool loop=false, bool scale=false) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Get the sprite-index for the given state or -1 when no sprite is set
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual s32 getSpriteIndex(EGUI_BUTTON_STATE state) const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Get the sprite color for the given state. Color is only used when a sprite is set.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual video::SColor getSpriteColor(EGUI_BUTTON_STATE state) const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Returns if the sprite in the given state does loop
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual bool getSpriteLoop(EGUI_BUTTON_STATE state) const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Returns if the sprite in the given state is scaled
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual bool getSpriteScale(EGUI_BUTTON_STATE state) const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! 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.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setIsPushButton(bool isPushButton=true) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Checks whether the button is a push button
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual bool isPushButton() const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Sets the pressed state of the button if this is a pushbutton
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setPressed(bool pressed=true) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Returns if the button is currently pressed
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual bool isPressed() const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Sets if the button should use the skin to draw its border
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setDrawBorder(bool border=true) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Checks if the button face and border are being drawn
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual bool isDrawingBorder() const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Sets if the alpha channel should be used for drawing images on the button (default is false)
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setUseAlphaChannel(bool useAlphaChannel=true) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Checks if the alpha channel should be used for drawing images on the button
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual bool isAlphaChannelUsed() const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Sets if the button should scale the button images to fit
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setScaleImage(bool scaleImage=true) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Checks whether the button scales the used images
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual bool isScalingImage() const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Get if the shift key was pressed in last EGET_BUTTON_CLICKED event
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual bool getClickShiftState() const IRR_OVERRIDE
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
|
|
|
return ClickShiftState;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Get if the control key was pressed in last EGET_BUTTON_CLICKED event
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual bool getClickControlState() const IRR_OVERRIDE
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
|
|
|
return ClickControlState;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Writes attributes of the element.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Reads attributes of the element
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void drawSprite(EGUI_BUTTON_STATE state, u32 startTime, const core::position2di& center);
|
|
|
|
EGUI_BUTTON_IMAGE_STATE getImageState(bool pressed) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
struct ButtonSprite
|
|
|
|
{
|
|
|
|
ButtonSprite() : Index(-1), Loop(false), Scale(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const ButtonSprite& other) const
|
|
|
|
{
|
|
|
|
return Index == other.Index && Color == other.Color && Loop == other.Loop && Scale == other.Scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 Index;
|
|
|
|
video::SColor Color;
|
|
|
|
bool Loop;
|
|
|
|
bool Scale;
|
|
|
|
};
|
|
|
|
|
|
|
|
ButtonSprite ButtonSprites[EGBS_COUNT];
|
|
|
|
IGUISpriteBank* SpriteBank;
|
|
|
|
|
|
|
|
struct ButtonImage
|
|
|
|
{
|
|
|
|
ButtonImage() : Texture(0), SourceRect(core::rect<s32>(0,0,0,0))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ButtonImage(const ButtonImage& other) : Texture(0), SourceRect(core::rect<s32>(0,0,0,0))
|
|
|
|
{
|
|
|
|
*this = other;
|
|
|
|
}
|
|
|
|
|
|
|
|
~ButtonImage()
|
|
|
|
{
|
|
|
|
if ( Texture )
|
|
|
|
Texture->drop();
|
|
|
|
}
|
|
|
|
|
|
|
|
ButtonImage& operator=(const ButtonImage& other)
|
|
|
|
{
|
|
|
|
if ( this == &other )
|
|
|
|
return *this;
|
|
|
|
|
|
|
|
if (other.Texture)
|
|
|
|
other.Texture->grab();
|
|
|
|
if ( Texture )
|
|
|
|
Texture->drop();
|
|
|
|
Texture = other.Texture;
|
|
|
|
SourceRect = other.SourceRect;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const ButtonImage& other) const
|
|
|
|
{
|
|
|
|
return Texture == other.Texture && SourceRect == other.SourceRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
video::ITexture* Texture;
|
|
|
|
core::rect<s32> SourceRect;
|
|
|
|
};
|
|
|
|
|
|
|
|
ButtonImage ButtonImages[EGBIS_COUNT];
|
|
|
|
|
|
|
|
IGUIFont* OverrideFont;
|
|
|
|
|
|
|
|
bool OverrideColorEnabled;
|
|
|
|
video::SColor OverrideColor;
|
|
|
|
|
|
|
|
u32 ClickTime, HoverTime, FocusTime;
|
|
|
|
|
|
|
|
bool ClickShiftState;
|
|
|
|
bool ClickControlState;
|
|
|
|
|
|
|
|
bool IsPushButton;
|
|
|
|
bool Pressed;
|
|
|
|
bool UseAlphaChannel;
|
|
|
|
bool DrawBorder;
|
|
|
|
bool ScaleImage;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace gui
|
|
|
|
} // end namespace irr
|
|
|
|
|
|
|
|
#endif // _IRR_COMPILE_WITH_GUI_
|
|
|
|
|
2021-08-27 17:55:04 +02:00
|
|
|
#endif // IRR_C_GUI_BUTTON_H_INCLUDED
|