Game Development Reference
In-Depth Information
It is important to provide the means to Refresh a control. For example, it is not necessary
forcontrolstocalculateitsplacementcoordinateseveryframe.It'sbesttodeferperforming
these calculations until something changes that requires a recalculation. If we change the
position of a text box, we would need to recalculate the position of the text to ensure it
remains drawn within the extents of the box, we also would need to adjust the caret's pos-
ition to be at the proper place, we can do this calculation by implementing it in the virtual
function Refresh .
Next, we have chosen to provide a background and foreground color for all controls, many
controls we use will contain text, the foreground color can be used when we render the
text.Colorconfigurationsmayvarydependingonthedesiredfeaturesetandcontrols,some
controls may need more color settings, for simplicity we will stick with these two and if
more are necessary they can be added to the relevant control's code.
Another important property is the alpha value, this controls the overall transparency of the
object and is applied to both the foreground and background color to guarantee that the en-
tire control can fade away and become invisible if necessary.
Finally, we have some state flags, these are used to determine the behavior of the control,
some are user-set, such as visible and enabled, others are automatically set as a response
to some form of input, focused refers to an object being the most recent recipient of some
form of input, and mouseOver is used to know if the input cursor is presently within this
control's bounds.
One important way to allow users to implement behaviors based on the control's behavior
is to expose some events.
event_handler<const control&> m_onFocusReceived;
event_handler<const control&> m_onFocusLost;
event_handler<const control&> m_onMouseEnter;
event_handler<const control&> m_onMouseLeave;
Theseeventsallowuserstorespondtoeventsandevenmakecustomchangestothecontrol
itself.
progressbar->OnMouseEnter() += [&](void*, const control&)
{ progressbar->SetForegroundColor(render::color::YELLOW); };
progressbar->OnMouseLeave() += [&](void*, const control&)
{ progressbar->SetForegroundColor(render::color::CYAN); };
Thisexamplechangessomeprogressbar'sforegroundcolortoyellowwhenthemousefirst
goes within its bounds, and then sets it to cyan once it leaves the bounds. This example
Search WWH ::




Custom Search