First of all, your if test is wrong. You have to make sure it's a mouseinput before using the elements under that assumption. But the problem is that you will only see the effect when moving your mouse a little bit, otherwise the cursor is not updated.
void AClassFromMyProject::setCursorVisible(bool visible) const
{
ICursorControl* cursor = m_pDevice->getCursorControl();
cursor->setVisible(visible); // This line and the next should go hand by hand
cursor->setPosition(cursor->getPosition());
}
This way it updates itself, call it refresh if you like so the visibility is changed without having you moving the mouse right after setVisible() was called.
It also seems to be a win32 related problem. These are somewhat behind the schedule for some time now, due to lack of people taking care of that Irrlicht device... So it really needs good and documented patches for me to commit them almost untested!
I also needed to disable the cursor on windows, so I wrote some patch for that now.
In CIrrDeviceWin32.cpp I removed the stuff in WM_SETCURSOR. I don't know why it was done that way, but I think to make that old code work like expected the cursor of the window-class would have to be removed. Instead I changed setVisible in CIrrDeviceWin32.h to look like that:
//! Changes the visible state of the mouse cursor.
virtual void setVisible(bool visible)
{
CURSORINFO info;
info.cbSize = sizeof(CURSORINFO);
if ( visible )
{
while ( GetCursorInfo(&info) )
{
if ( info.flags == CURSOR_SHOWING )
{
IsVisible = visible;
break;
}
ShowCursor(true); // this only increases an internal display counter in windows, so it might have to be called some more
}
}
else
{
while ( GetCursorInfo(&info) )
{
if ( info.flags == 0 ) // cursor hidden
{
IsVisible = visible;
break;
}
ShowCursor(false); // this only decreases an internal display counter in windows, so it might have to be called some more
}
}
}
Seems to work here,but any further testing and feedback from other people is welcome.
*sigh* I also can't replicate it with current trunk. Which is especially strange as I also tried adding the changes which had been made in the meantime before I started fixing it. Probably I missed something.
I just want to add that the bug shows for me. NVIdia 7300 with performance HUD drivers installed. I would not stake my life on it but I am pretty sure that hiding the cursor worked with V1.2 which I was using until last week, same configuration otherwise.
I looked into the code in the device that makes the curser invisible and it seems that this done by using a trick in which the cursor is placed outside the visible windows. This will not work if the code alters the mouse position of course, which is the case for me and probably also for the other user who sees the error. Maybe this helps to reproduce the error.
Altering the mouse position while the cursor is invisible is an important feature. I use it while moving my camera around with the mouse.
Do you have some test-code to reproduce the problem?
If I boot into Windows some time I'll try altering the mouse position after setting it invisible, maybe that was what I've been missing in my test.
I thought so due to the updateInternalCursorPosition() call but maybe it does something else. Probably does because I removed the call and still the cursor does not become invisible