/// <summary> /// Handle user input. /// </summary> /// <param name="input">The helper for reading input from the user.</param> public virtual void HandleInput(InputState input) { //If the component is not active nor visible, discontinue. if (!_IsActive || !_IsVisible) { return; } //If the left mouse button has been pressed. if (input.IsNewLeftMouseClick()) { //If the user clicks somewhere on the item, fire the event. if (Helper.IsPointWithinBox(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), Position, Width, Height)) { //Fire the event. MouseClickInvoke(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), MouseButton.Left); } //If not, see if it is appropriate to defocus the component. else { FocusChangeInvoke(false); } } //If the right mouse button has been pressed. if (input.IsNewRightMouseClick()) { //If the user clicks somewhere on the item, fire the event. if (Helper.IsPointWithinBox(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), Position, Width, Height)) { //Fire the event. MouseClickInvoke(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), MouseButton.Right); } //If not, see if it is appropriate to defocus the component. else { FocusChangeInvoke(false); } } //If the left mouse button is being held down. if (input.IsNewLeftMousePress()) { //If the user clicks somewhere on the item, fire the event. if (Helper.IsPointWithinBox(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), Position, Width, Height)) { //Fire the event. MouseDownInvoke(Helper.GetMousePosition(), MouseButton.Left); } } //If the mouse is currently hovering over the component. if (Helper.IsPointWithinBox(Helper.GetMousePosition(), Position, Width, Height)) { //If the mouse has just entered the component's surface, fire the event and enable the flag. if (!_IsMouseHovering) { MouseHoverInvoke(); } } //Else, disable the flag. else { _IsMouseHovering = false; } //Loop through all items and give them access to user input. _Items.ForEach(item => item.HandleInput(input)); }
/// <summary> /// Handle user input. /// </summary> /// <param name="input">The helper for reading input from the user.</param> public void HandleInput(InputState input) { //If the GUI is not active nor visible, discontinue. if (!_IsActive || !_IsVisible) { return; } //Decide which collection of items to use. if (_ForegroundItems.Count != 0) { _ForegroundItems.ForEach(item => item.HandleInput(input)); } else { _Items.ForEach(item => item.HandleInput(input)); } //If the right click list is enabled and the user has pressed the left mouse button. if (_HasRightClicked && input.IsNewLeftMouseClick()) { //If the user clicks somewhere else than on the list, disable it. if (!Helper.IsPointWithinBox(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), _RightClickList.Position, _RightClickList.Width, _RightClickList.Height)) { //Disable the list. EnableOrDisableRightClickList(false, Vector2.Zero); } } //If the right mouse button has been pressed, enable or disable the right click list. if (input.IsNewRightMouseClick()) { EnableOrDisableRightClickList(true, new Vector2(Mouse.GetState().X, Mouse.GetState().Y)); } //Enable the right click list to handle user input, if the time is right. if (_HasRightClicked) { _RightClickList.HandleInput(input); } }