Game Development Reference
In-Depth Information
protected:
virtual void InternalDraw();
virtual bool HandleInput(float deltaTime, const input::input_state& inputState);
eState m_state;
event_handler<const button&> m_onPressed;
event_handler<const button&> m_onReleased;
align::eAlignmentFlags m_alignment;
};
Buttons need to have a way to allow users to implement behaviors as a result of input. We
can do this by providing event handlers when the users press and releases a button. Typic-
ally a button will perform its intended function upon its release. Knowing that a button has
been pressed may be useful to provide feedback to the player, for example, by playing a
sound.
void InternalDraw()
{
if ( m_spriteSheet != nullptr )
{
m_sprite->Draw(m_rectangle.Position());
}
else
{
render::color color = m_colors[m_state];
m_spriteBatch->Draw(*m_core->GetWhiteTexture()->GetView(), m_rectangle, nullptr, color);
}
if ( m_showText )
{
math::vector2 size = static_cast<math::vector2>( m_font->MeasureString(m_text.c_str()) );
math::rectangle textRectangle = m_rectangle;
textRectangle.SetSize(size);
align a(textRectangle, m_rectangle);
a.Apply(m_alignment);
m_font->DrawString(m_spriteBatch.get(), m_text.c_str(), textRectangle.Position(), m_foregroundColor);
}
}
To draw our button we will support two cases, the first one is if we are using a sprite. In
thiscasedrawingisfairlystraightforward, wecallthesprite'sowndrawfunction,towhich
we provide the coordinate at which to draw the button. The next case does not use a sprite
but rather just a colored rectangle, this is useful primarily for development or debugging,
or perhaps in extremely low memory situations.
Search WWH ::




Custom Search