Jump to content

[SOLVED] Detect if mouse is over GUI


photo

Recommended Posts

Hi,

I am doing drag and drop with Unigine, and I want detect when I drop, if I am over GUI or not. 

What is the better way for do that with UnigineScript ??

 

Thanks

 

Tony

 

 

Link to comment

Unfortunately, Andrey doesn't work for us, The sample show the drag and drop between Widget.

We want drag and drop between Widget and "viewport" (without gui). Looking other sample we will try with the other event ENTER and LEAVE, may be that can work.

 

Tony

Link to comment

Hi Andrey,

 

Unfortunately, it's no so easy to add it inside our code, because we need to change a lot of code adding many callback .... for quick result we choose other option, we have a list of our Widget and when we receive the release of the mouse, we check for each widget the position of the mouse and the position of the widget. It's not the better way to do it, but could be work quickly.

 

Link to comment

We use these functions

/*
 */
int mouse_is_over_unigine_widget(Widget w) {
	if(w.isHidden()) return 0;
	int mx= w.getMouseX();
	int my= w.getMouseY();
	return ((mx > 0) && (my > 0) && (mx < w.getWidth()) && (my < w.getHeight()));
}

/*
 */
int mouse_is_over_any_unigine_widget() {
	forloop(int i=0;engine.gui.getNumChilds()) {
		if(mouse_is_over_unigine_widget(engine.gui.getChild(i)))
			return 1;
	}
	return 0;
}
  • Like 1
Link to comment
  • 6 years later...
  • 2 months later...

Hi,

I thought id do an update for v2.12.01 C# component system, because it is not one on one conversion.

	public WidgetButton button;

	button = new WidgetButton("button text");
	Gui gui = Gui.Get();
	gui.AddChild(button,Gui.ALIGN_LEFT);

	public static bool mouse_is_over_unigine_widget(Widget w)
	{
		if (w.Hidden) return false;
		bool r = (
			(w.MouseX > 0 ) &&
			(w.MouseY > 0 ) &&
			(w.MouseX < w.Width) &&
			(w.MouseY < w.Height) );
		return r;
	}

	public static bool mouse_is_over_any_unigine_widget()
	{
		for (int i = 0; i < Gui.Get().NumChildren; i++)
		{
			if(mouse_is_over_unigine_widget(Gui.Get().GetChild(i))) 
				return true;
		}
		return false;
	}

 

Link to comment
×
×
  • Create New...