Game Development Reference
In-Depth Information
To implement a functional, working button we do not need to worry too much about what
a button will look like. We will begin by writing the inner workings of a functional button
and towards the end, to make buttons more visually interesting we will make use of the
sprite class (see Sprites ). Using sprites we can use different animations depending on the
state of a button.
The button class will derive from the control class, inheriting a good amount of functional-
ity in terms of determining if the button is in focus or if the mouse is hovering over it.
class button : public control
{
public:
enum eState
{
Default,
Pressed,
Disabled,
StateCount
};
event_handler<const button&>& OnPressed()
{ return m_onPressed; }
event_handler<const button&>& OnReleased()
{ return m_onReleased; }
button(std::shared_ptr<core_ui> core, const std::shared_ptr<render::platform::font>& font, const
std::shared_ptr<render::platform::sprite_batch> spriteBatch)
: control(core, font, spriteBatch)
, m_state(Default)
, m_alignment(ui::align::Center | ui::align::Middle)
{}
Search WWH ::




Custom Search