Game Development Community

Getting mouse clicks on multiple GUIs?

by Spencer Grey · in Torque Game Builder · 06/28/2006 (9:10 am) · 5 replies

Hey,

Sorry if this has been asked before, but is it possible to detect mouse events on multiple GUI's? As in, if I have my t2dSceneWindow and a GUI interface screen above that, can I detect mouse clicks on an object in the t2dSceneWindow?

Right now, the interface screen seems to be eating up my mouse events. The best I could think of was this:

[draw]

function interfaceScreenGui::onMouseDown(%this, %mod, %worldPos, %mouseClicks) {
%scenePos = sceneWindow2D.getMousePosition();
sceneWindow2D.onMouseDown(%mod, %scenePos, %mouseClicks);
}

function sceneWindow2D::onMouseDown(%this, %mod, %worldPos, %mouseClicks) {
echo ("click");
}

[/draw]

That way I can atleast use a pickpoint command to figure out what I'm clicking on in the t2dSceneWindow.

If anyone has a better way I'd appreciate it. Especially if it explains how to detect a mouse event on an object itself so I dont need to set up a switch statement in that sceneWindow2D:: function :)

Thanks!

PS: If I missed it in a document somewhere, dont be afraid to yell at me and tell me that :p

#1
06/28/2006 (9:27 am)
That's probably the simplest solution without messing with the source code. The GuiCanvas handles the mouse down event by searching from the outermost layer until it finds a control that contains the mouse point, then passes off the event to that control and stops searching.

Check out the whack-a-mole tutorial for info on detecting mouse events on an object itself.
#2
06/28/2006 (9:35 am)
Was afraid of that, hehe.

Detecting the events is easy, I was just curious about detecting them through another gui control.

Regardless, its easy enough to handle.

function interfaceScreenGui::onMouseDown(%this, %mod, %worldPos, %mouseClicks) {
	%scenePos = sceneWindow2D.getMousePosition();
	sceneWindow2D.onMouseDown(%mod, %scenePos, %mouseClicks);
}

function sceneWindow2D::onMouseDown(%this, %mod, %worldPos, %mouseClicks) {
	%objList = sceneWindow2D.getSceneGraph().pickPoint(%worldPos);
	%objCount = getWordCount(%objList);
	
	for (%i = 0; %i < %objCount; %i++) {
		
		%obj = getWord(%objList, %i);
		
		if (%obj.isSelectable) {
		                %obj.onMouseDown(%mod, %worldPos, %mouseClicks);
			return;					
		}
		
	}
}

The event eventually trickles down to my objects. Not that pretty, but it works.

Thanks for the quick reply!
#3
06/10/2010 (8:35 pm)
This is nice! How would it work for onMouseEnter?
#4
06/10/2010 (8:58 pm)
Since Owen hasn't been on for over a year and Spencer for 3, I'll attempt to answer for them.

It'll get much more complicated the more mouse events you want to handle. For example, onMouseEnter: you'll probably have to use onMouseMove in the interface screen, do a pickPoint in the scene window, and call onMouseEnter for object returned from that.

And in reality, it'll get much harder because you'll probably want onMouseLeave, too. That means you need to keep a list of the "entered" objects and compare them to the current pickList. The ones that are missing will need onMouseLeave called.

And so on...

I've played your demo a few times and haven't seen any issues with your GUI. Is there something specific that is happening? I know you've mentioned that mounting doesn't seem to work for you, but it might be worth opening a brand new project just to test mounting.
#5
06/11/2010 (7:50 am)
This is related to the mounting issue. The goal for my game is to increase the size of the sectors (everyone complains about claustrophobia). My first approach was to simply position the HUD elements relative to the player (with camera mounted to player). That worked as expected except I discovered that MountForce is still broken in 1.7.5. Even if it wasn't broken, the HUD update is shaky as it follows the player around and this approach was scrapped.

Now I'm working on creating different sections of the HUD in different scenewindows. These will be modal, but since they will be around the outside edges and since the camera will follow the player, I don't think it will be a problem to intercept mouse events in those areas.

I was asking this question just in case it turns out to be a problem and I need to pass mouse events to the next layer.