Game Development Reference
In-Depth Information
m_progressbar->SetCustomDrawFunction(
[=](const control& c)
{
const progress_bar& progressbar = static_cast<const progress_bar&>(c);
rectangle r = progressbar.GetRectangle() + rectangle(5.f,0,0.f, 0.f);
rectangle rc = progressbar.GetRectangle();
rc.Left() -= 10.f;
rc.Width() += 20.f;
auto whiteTexture = *m_element.GetCore()->GetWhiteTexture()->GetView();
m_spriteBatch->Draw(whiteTexture, r, nullptr, render::color::DARKCYAN);
m_spriteBatch->Draw(whiteTexture, r, nullptr, progressbar.GetForegroundColor());
});
This can be a useful feature not only to change the drawing of a given control's instance,
but for quickly prototyping visual changes. That said, most of the time it is best to derive
from the control we want to change and override the virtual function InternalDraw .
All controls may potentially handle some user input, the virtual function HandleInput will
be called each frame for all visible controls, the base implementation will detect if controls
should come into focus or if the mouse may be hovering over the control, when any of
these actions occur we will send out an event allowing other systems to register their own
event handlers.
bool control::HandleInput(float deltaTime, const input::input_state& inputState)
{
UNREFERENCED(deltaTime);
auto mouse = inputState.GetMouse();
if ( mouse != nullptr )
{
if ( m_rectangle.Contains( mouse->GetPosition() ) )
{
if ( !m_mouseOver )
{
m_onMouseEnter.Invoke(this, *this);
m_mouseOver = true;
}
if ( !m_focused && mouse->ButtonPressed(input::mouse::eButton::Left) )
{
m_onFocusReceived.Invoke(this, *this);
m_focused = true;
return true;
}
}
else
{
if ( m_mouseOver )
{
m_onMouseLeave.Invoke(this, *this);
m_mouseOver = false;
}
if ( m_focused && mouse->ButtonPressed(input::mouse::eButton::Left) )
Search WWH ::




Custom Search