Game Development Community

Resticting the mouse cursor

by Guy Allard · in Torque Game Engine Advanced · 06/12/2008 (12:23 pm) · 2 replies

I'm working on a project that uses the mouse to select objects. In TGE, the mouse cursor was restricted to within the game window, but in TGEA the cursor is free to move out of the game window and onto the desktop.

Is there a setting for the GuiProfiles that controls this behavior, or has something changed deeper down?

Also, in addition to being able to restrict the cursor to the game window, how would I go about restricting the cursor to within the bounds of a certain GUI object?

Cheers for the help

#1
06/13/2008 (11:49 pm)
Guy I've been working on this.

* First part: Locking the mouse to the window.

The problem is that Platform::setWindowLocked() within source\windowManager\platformInterface.cpp is empty; as an obvious result, any current call to it (as in the console function lockmouse() or as in our GuiRTSTSCtrl::onWake()) is useless. I dont know if the guys working on TGEA just forgot to finish it, or there is a more important reason to leave it blank. Anyway, here is the code I used there to workaround the situation:

PlatformWindow *currentWindow = PlatformWindowManager::get()->getFirstWindow();
if(currentWindow)
	currentWindow->setMouseLocked(locked);
This "solution", however will require work, as in my tests, any window change, clears the locking: if you open the console, or display any sub-window (like the exit dialog), the mouse locking is gone. As soon as you put your hands on the version 1.7.1 look if there is any change on this.


* Second part: Restricting the cursor to a GUI object.

It seems like there is very simple way to restrict, not the cursor itself, but any input from the mouse, to a given GuiControl: mouseLock(). Lucky for us, it is exactly what we are looking for.
#2
06/14/2008 (1:34 am)
Cheers for that.
They've added the mouse lock back in to 1.7.1, but the cursor is still free to wander outside of the game window.