Closed mkelcb closed 3 years ago
I managed to solve this problem with the following idea: when handling mouse clicks, check if the mouse is over any of the interface widgets by checking against their bounds. Maybe not the most elegant, but it works:
Vector2 mouseLoc = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
for (int i = 0; i < grid.Widgets.Count; i++)
if (grid.Widgets[i].Bounds.Contains(mouseLoc)) return; // mouse is over the interface
use
_desktop.IsMouseOverGUI
I have a problem with a simple use case, I add a TextButton with a click event:
and when I click this it triggers, but if I am also listening for mouse clicks on the main game area for example:
then this will also fire. Whereas what I would like is for the button to consume the mouse left click, and not let it trigger any further events in my game. I checked the Myra wiki and the TextButton class to see if there was perhaps a way to set the button to prevent regular mouse clicks from also being triggered but I couldn't find a way to disable this behaviour.
What is the preferred way to only get 1 click event on the button?