Game Development Reference
In-Depth Information
{
m_onFocusLost.Invoke(this, *this);
m_focused = false;
}
}
}
return false;
}
There are two distinct cases we are testing for, the first one is if the mouse is within the
controlornot,weareonlyinterestedinknowingwhenthemousewentinandwhenitwent
out, it's not necessary to send an event every frame while the mouse is hovering over a
control.
Thesecondcaseiswhenthecontrolcomesintofocus,thisisdonebysomeinteractionfrom
the user. If the user presses within the control's rectangle the control will come into focus
and we will invoke the OnFocusReceived event, otherwise if the button press happened
outside the control (or on another control) we will invoke OnFocusLost .
Thedefaulthittestingisdoneusingthecontrol'srectangleboundary,ifsomecontrolsneed
moreprecisehittesting,theycanoverridethe HandleInput functionandperformthecalcu-
lations there, always making sure to invoke the events to maintain the expected functional-
ity of controls.
If the input was handled we return true, otherwise we return false; this allows us to chain
input handling calls and stop when someone has successfully handled the input.
The remaining interface provides the access functions to the properties.
float& Alpha() { return m_alpha; }
const math::vector2 Position() const
{ return m_rectangle.Position(); }
const math::vector2 Size() const
{ return m_rectangle.Size(); }
void SetPosition(const math::vector2& position, eUnit unit=Percent);
void SetSize(const math::vector2& size, eUnit unit=Pixels);
void SetExtents(const math::vector4& extents, eUnit unit=Percent);
const render::color& ForegroundColor() const
{ return m_foregroundColor; }
const render::color& BackgroundColor() const
{ return m_backgroundColor; }
void SetForegroundColor(const render::color& color)
{ m_foregroundColor = color; Refresh(); }
Search WWH ::




Custom Search