Game Development Reference
In-Depth Information
PointInBounds are used by the Menu class to allow for interaction with the control.
We'll look at how to implement these when we look at the TextBlock class.
Once you have this in place, we can implement the Menu class, which will handle
storing the controls as well as managing which control is in focus and which control
the mouse or finger is touching, as shown in the code snippet that follows:
class Menu
{
private:
std::vector<std::shared_ptr<ControlBase>>
_controls;
std::shared_ptr<ControlBase> _focusControl;
public:
Menu(void);
~Menu(void);
void Draw(std::shared_ptr<SpriteBatch>
spriteBatch);
void ProcessClick(float x, float y);
void ProcessClick();
void AddControl(std::shared_ptr<ControlBase>
control);
bool SetFocus(std::shared_ptr<ControlBase>
control = nullptr);
void NextFocus();
};
The menu stores all of the controls, and tracks which one has focus for alternative
input methods such as the controller. The Draw() method simply loops through the
controls and draws them if their Visibility flag is set to true . The interesting
methods are ProcessClick() and the two focus methods.
ProcessClick() manages the hit detection and messaging for the user interface.
The x and y position values of the mouse or touch point are passed to the menu
Search WWH ::




Custom Search