Hiding cursor when left mosue button clicked

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
NeRoX
Posts: 12
Joined: Fri Jul 11, 2008 8:15 pm

Hiding cursor when left mosue button clicked

Post by NeRoX »

Hi, in my OnEvent I writed:

Code: Select all

		if(event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)   
			mouseDownL = true;
		
		if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP)
			mouseDownL = false;
and in my loop I writted:

Code: Select all

device->getCursorControl()->setVisible(!mouseDownL);
Now, if I just click on the left button, it's hiding the cursor. If I click on the left button continuity and moving the mouse, the cursor is shown.

How can I fix that?

Thanks!!

P.S: Sorry for english :)
PROUD ISRAELI!
NeRoX
Posts: 12
Joined: Fri Jul 11, 2008 8:15 pm

Post by NeRoX »

someone?

thanks
PROUD ISRAELI!
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

I dont understand the trouble. I use the same type of thing in my app. here is a paste of the code for that.

Code: Select all

					case EMIE_LMOUSE_LEFT_UP :
					 { 
						// what a freakin hack
						m_LMouseButtonDown = false;
						return false;
					 } break;
pera
Posts: 460
Joined: Wed May 14, 2008 1:05 pm
Location: Novi Sad, Serbia
Contact:

Post by pera »

Maybe you have some error in code? Could you post whole OnEvent function or part handling mouse events?
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

What platforms are all y'all using?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
pera
Posts: 460
Joined: Wed May 14, 2008 1:05 pm
Location: Novi Sad, Serbia
Contact:

Post by pera »

What platforms are all y'all using?
me? computer?
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

pera wrote:
What platforms are all y'all using?
me? computer?
All y'all.

The cursor implementation is platform dependent, so it matters what OS you're using.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
pera
Posts: 460
Joined: Wed May 14, 2008 1:05 pm
Location: Novi Sad, Serbia
Contact:

Post by pera »

Im using windows but I don't believe
device->getCursorControl()->setVisible(true);
would work diferently on linux?
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

hmm, you're right, it's prety strange... :shock:
I made a small test prog:

Code: Select all

#include <irrlicht.h>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

bool mouseDownL;

class MyEventReceiver : public IEventReceiver{
public:
	virtual bool OnEvent(const SEvent& event){
		if (event.EventType == EET_MOUSE_INPUT_EVENT){
        if(event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN){
          printf("1\n");
          mouseDownL = true;
          return false; // doesn't matter is I return true or false
        }
        if(event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP){
          printf("2\n");
          mouseDownL = false;
          return false; // doesn't matter is I return true or false
        }
		}
		return false;
	}
};

int main(){
  MyEventReceiver recv;
	IrrlichtDevice *device = createDevice(EDT_DIRECT3D9, dimension2d<s32>(640, 480), 16, false, false, false, &recv);
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();

	while(device->run()){
		driver->beginScene(true, true, video::SColor(0,0,0,0));
		smgr->drawAll();
		driver->endScene();

    device->getCursorControl()->setVisible(!mouseDownL);

	}
	
	device->drop();
	return 0;
}
what happens is: when you press the left mouse button "1" is printed to the console, but the cursor doesn't hide...
when you left the button up "2" is printed and the cursor hides until you move the mouse, then the cursor is shown again...
that's realy strange !!!
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

I think this is similar to a bug we've seen before that if you've got the cursor hidden and then unhide it then it only actually becomes visible when it's moved, so you unhide it and then call setPosition(cursorPos) to force it.

but that doesn't really explain why it doesn't hide it when you mousedown...

maybe try cursor->setVisible(false); cursor->setPosition(cursor->getPosition());

?
Image Image Image
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

JP wrote:but that doesn't really explain why it doesn't hide it when you mousedown...
right !!! ;)

I also changed the render loop to this:

Code: Select all

bool om = mouseDownL;
while(device->run()){
  driver->beginScene(true, true, video::SColor(0,0,0,0));
  smgr->drawAll();
  driver->endScene();

  if(om != mouseDownL){
    printf("%d\n",mouseDownL);
    device->getCursorControl()->setVisible(!mouseDownL);
    device->getCursorControl()->setPosition(device->getCursorControl()->getPosition());
    om = mouseDownL;
  }
}
it prints the correct button status (1 if down and 0 if up), but the cursor doesn't hide at all !!! :shock:
the hiding from the previous code is now eliminated because of the setPosition of the cursor... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Windows cannot hide the Cursor while the mouse button is pressed. There are some workarounds described on MSDN, but I'm not really into this strange stuff.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

hybrid wrote:but I'm not really into this strange stuff.
I has pictars that says otherwise... 8)

More on topic.... NeRoX, can i just ask, out of interest, what your reason is for wanting to hide the cursor whilst the mouse is pressed?

I can think of a really simple workaround. Hide the cursor always and then draw your own cursor (can be identical to the standard cursor) at its location each frame and when you want to hide it just stop drawing it.

Et.

Voila.
Image Image Image
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

hybrid wrote:Windows cannot hide the Cursor while the mouse button is pressed.
wow, I'm now working for years with Windows and didn't know this... :oops:
well, another benefit of Windoofs !!! :roll:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
ecsos
Posts: 30
Joined: Mon Feb 04, 2008 8:02 am

Post by ecsos »

i posted a code snippet on this a while back:
it will fix the problem....i have it working in my current code if you need a patch for the current svn
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=27235
Post Reply