realesmedia
Topic Author
Posts: 85
Joined: 18 May 2016, 10:26

[C++] Check if mouse on the GUI

13 Jan 2017, 10:26

How to implement events OnMouseEnter and OnMouseLeave for all elements at once?
How can I check if mouse on the GUI or not?
Last edited by realesmedia on 30 Jan 2017, 21:37, edited 1 time in total.
 
User avatar
sfernandez
Site Admin
Posts: 1915
Joined: 22 Dec 2011, 19:20

Re: [C++] Check if mouse on the GUI

16 Jan 2017, 17:19

What do you mean for all elements at once?

If you want to be notified when an element on a subtree of elements is hovered with the mouse you just need to register to MouseEnter in the parent of that tree, because routed events traverse all elements in the tree.

To check if mouse is over any element of the GUI you can use VisualTreeHelper like this:
Visual* root = VisualTreeHelper::GetRoot(anyElement);
HitTestResult hit = VisualTreeHelper::HitTest(root, mousePos);
if (hit.visualHit != 0)
{
  // Mouse is over a GUI element
}
else
{
  // No GUI element is under the mouse
}
 
realesmedia
Topic Author
Posts: 85
Joined: 18 May 2016, 10:26

Re: [C++] Check if mouse on the GUI

30 Jan 2017, 09:24

I have GUI but it's not only one who capture mouse click events. My scene capture it too and I want every click on GUI not be captured with scene.
 
realesmedia
Topic Author
Posts: 85
Joined: 18 May 2016, 10:26

Re: [C++] Check if mouse on the GUI

30 Jan 2017, 21:41

And, yes, variant with VisualTreeHelper is an option. Thanks.
 
User avatar
jsantos
Site Admin
Posts: 2905
Joined: 20 Jan 2012, 17:18
Contact:

Re: [C++] Check if mouse on the GUI

01 Feb 2017, 19:31

Good to know you solved the issue!

Who is online

Users browsing this forum: No registered users and 2 guests