Jump to content

[SOLVED] Detect if mouse is over GUI


photo

Recommended Posts

Posted

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

 

 

Posted

Hi Tony!

 

Have you looked at samples/widgets/sprite_03 sample?

Posted

Hi Andrey,

 

I will go to look :)

 

Thanks

Posted

You're welcome. :)

 

I'll wait for your feedback before I resolve this topic.

Posted

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

Posted

Hi Tony,

 

Did you get any results on drag'n'drop feature?

Posted

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.

 

Posted

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
  • 6 years later...
Posted

hello,

Is there a better solution to this problem now?

i want to detect my mouse over gui widget or in viewport.

  • 2 months later...
Posted

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;
	}

 

×
×
  • Create New...