Hiding cursor...

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Nyxojaele
Posts: 98
Joined: Mon Sep 18, 2006 4:06 am

Hiding cursor...

Post by Nyxojaele »

I've noticed that when I execute this simple code:

Code: Select all

mDevice->getCursorControl()->setVisible(!mDevice->getCursorControl()->isVisible());
the cursor will not actually change visibility until I move the mouse. A simple way around this is to follow up that line with this line:

Code: Select all

mDevice->getCursorControl()->setPosition(mDevice->getCursorControl()->getPosition());
Now, I wanted to use this code to hide the mouse when the Left Mouse Button is pressed, and show the mouse again when it's released, so I put it together like this in my EventReceiver:

Code: Select all

		switch (e.MouseInput.Event) {
			case EMIE_LMOUSE_PRESSED_DOWN: {
				mDevice->getCursorControl()->setVisible(false);
				mDevice->getCursorControl()->setPosition(mDevice->getCursorControl()->getPosition());
				break;
			}
			case EMIE_LMOUSE_LEFT_UP: {
				mDevice->getCursorControl()->setVisible(true);
				mDevice->getCursorControl()->setPosition(mDevice->getCursorControl()->getPosition());
				break;
			}
			default:
				break;
		}
But this doesn't work, yet if I copied the same code and applied to to pressing/releasing a keyboard key, it works.

Something I've noticed while trying to debug this is that if I remove the code to set the cursor visible again when the LMB is released, when I press it, the cursor is still visible, but when I -release- it again, it gets hidden! Which is sorta the opposite of what I want. It's like these hide/unhide events are being somehow delayed until the mouse button is lifted again, and only when this is applied to the mouse buttons, not the keyboard keys...
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

the cursor will not actually change visibility until I move the mouse. A simple way around this is to follow up that line with this line:
mDevice->getCursorControl()->setPosition(mDevice->getCursorControl()->getPosition());
Great, I was having the same problem. Thanks.
shogun
Posts: 162
Joined: Wed Sep 05, 2007 11:02 am
Location: inside

Post by shogun »

I mentioned this buggy behaviour some time ago. The best solution is to hide the cursor from the beginning and use your own cursor-image (drawing it with draw2DImage after the GUI).
Nyxojaele
Posts: 98
Joined: Mon Sep 18, 2006 4:06 am

Post by Nyxojaele »

Thanks for the feedback guys. This was only something I wanted to do temporarily anyways, so I'll just deal with it until I have things in place to put my permanent solution in place (cursor replacement)
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

the problem seems to be that the visibility is changed inside the event receiver (I also don't know why)...

I think the "boolean key" workaround would help with this...
or simply set a flag to true/false in the receiver and act on the flag changing inside the main loop... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
ultramedia
Posts: 175
Joined: Wed Dec 20, 2006 12:04 pm

Post by ultramedia »

boolean key idea doesn't work for me (still won't hide the cursor)... :(

Guess the fake cursor is the only way...
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

It's fixed in the SVN.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
dudMaN
Posts: 111
Joined: Fri Mar 02, 2007 6:37 pm

Post by dudMaN »

Most likely the event receiver is resetting it, so you need to set some kind of flag.

Code: Select all


 // In whatever class
 bool isMouseVisible;

 // In your event receiver
 if(keys[MOUSE_WHATEVER] == true) {
  isMouseVisible=false;
 }

 // In your main loop
 setMouseVisibility(isMouseVisible);
Hope i could help.

-DudMan
Complete Irrlicht Beginners Tutorial
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=24898
Post Reply