Game Development Reference
In-Depth Information
void
Menu::AddControl(std::shared_ptr<ControlBase>
control)
{
_controls.push_back(control);
}
void Menu::ProcessClick(float x, float y)
{
for (auto item : _controls)
{
if (item->GetVisibility() &&
item->PointInBounds(x, y))
{
item->HandleClick();
break;
}
}
}
void Menu::ProcessClick()
{
if (_focusControl != nullptr)
_focusControl->HandleClick();
}
The
AddControl()
method is straightforward; we simply add the control to the list.
ProcessClick()
is the method that handles determining which control the user
has clicked on, so that the associated logic can be executed. We provide two over-
loads for the
ProcessClick()
method so that we can simulate a click with the
gamepad instead of choosing the focused control as the target for the click.
As shown in the following code snippet, the
SetFocus()
and
NextFocus()
meth-
ods both coordinate the control that is currently focused within the
Menu
class:
bool
Menu::SetFocus(std::shared_ptr<ControlBase>