Hello everyone,
I have a question about the proper way to hide the mouse cursor using Ogre. Here's the situation :
1.) I have downloaded and compiled Ogre version 1.0.3 for Windows.
2.) I have downloaded and installed the Ogre Wizard, version 0.13.2, for the .Net frame work.
3.) I've created, compiled and run a simple application using the wizard mentionned above. Up to this point everything's going well.
4.) Now I wanted to test if I was able to hide the CEGUI mouse cursor. The idea being that I might want to make screenshots of the scene without the mouse cursor showing up. So what I did was to add two line to the keyPressed method of a class inhereting from FrameListener, actually ExampleFrameListener. These two lines are this :
if(e->getKey() == Ogre::KC_H)
CEGUI::MouseCursor::getSingleton().hide();
But this doesn't hide the mouse cursor. Can someone please tell me what I'm doing wrong or missing? I'm getting confused. I thank you all in advance for any help provided or any hints about my mistake.
PS : By the way if someone could explain the meaning of "injects a key down event to the system" that would be great? What system? Ogre? CEGUI? Windows? And how should I repond to this event?
Hidding the CEGUI mouse cursor using Ogre ( newbie question
Moderators: CEGUI MVP, CEGUI Team
- l_ourson69
- Just popping in
- Posts: 3
- Joined: Sun Aug 14, 2005 01:59
- CrazyEddie
- CEGUI Project Lead
- Posts: 6760
- Joined: Wed Jan 12, 2005 12:06
- Location: England
- Contact:
Re: Hidding the CEGUI mouse cursor using Ogre ( newbie quest
Hi,
That line should indeed hide the CEGUI cursor. Have you confirmed in the debugger that the line is being reached?
"Injects a key down event into the system" means that the method informs the cegui system that a key has changed from the 'up' state to the 'down' state. It refers to the CEGUI system, since while CEGUI can utilise Ogre for rendering, CEGUI is not a part of Ogre
That line should indeed hide the CEGUI cursor. Have you confirmed in the debugger that the line is being reached?
"Injects a key down event into the system" means that the method informs the cegui system that a key has changed from the 'up' state to the 'down' state. It refers to the CEGUI system, since while CEGUI can utilise Ogre for rendering, CEGUI is not a part of Ogre
Useful Links: Forum Guidelines | Documentation | Tutorials | HOWTO | Videos | Donate to CEGUI | CEGUI Twitter
- l_ourson69
- Just popping in
- Posts: 3
- Joined: Sun Aug 14, 2005 01:59
Re: Hidding the CEGUI mouse cursor using Ogre ( newbie quest
Thanks for the tip crazyeddie!
I've just put a breakpoint to that line and it's getting executed. Actually I can see the mouse flickers as I press the key, some sort of hides for a millisecond but shows instantly back again.
Could this be because Ogre "refreshes" the scene and shows back again the CEGUI cursor without respecting the hidden state?
Also thanks for the explanation. Now how can I respond to this notification? What's the method to override or declare? I ask because I'm having a problem with keyboard input. Should I post it here or open another thread?
Anyhow this is the problem : as for now I've overridden the Ogre keyPressed method and react to key events there, but I'm having a problem while using the keyboard into an entrytext object : the arrow keys are not moving the carret, instead they move the camera. So why can I do to prevent the key event won't make the camera move, but instead just move the carret in the entrytext?
Again thank you all in advance.
I've just put a breakpoint to that line and it's getting executed. Actually I can see the mouse flickers as I press the key, some sort of hides for a millisecond but shows instantly back again.
Could this be because Ogre "refreshes" the scene and shows back again the CEGUI cursor without respecting the hidden state?
Also thanks for the explanation. Now how can I respond to this notification? What's the method to override or declare? I ask because I'm having a problem with keyboard input. Should I post it here or open another thread?
Anyhow this is the problem : as for now I've overridden the Ogre keyPressed method and react to key events there, but I'm having a problem while using the keyboard into an entrytext object : the arrow keys are not moving the carret, instead they move the camera. So why can I do to prevent the key event won't make the camera move, but instead just move the carret in the entrytext?
Again thank you all in advance.
- CrazyEddie
- CEGUI Project Lead
- Posts: 6760
- Joined: Wed Jan 12, 2005 12:06
- Location: England
- Contact:
Re: Hidding the CEGUI mouse cursor using Ogre ( newbie quest
This should not be a case of Ogre re-drawing the cursor, since Ogre just does what it's told, and if the CEGUI cursor is set to hidden, it's not drawn
I would check the line in your code where the mouse cursor gets re-shown; there is obviously something happening there that is not what you expect
To answer your other question:
You need to maintain a small amount of state, and when an editbox gets acivated set some 'move_camera' flag to false, then check this flag in your code before moving the camera. Then when the editbox is deactivated, set the flag to true, so that normal use of the arrow keys can continue.
I would check the line in your code where the mouse cursor gets re-shown; there is obviously something happening there that is not what you expect
To answer your other question:
You need to maintain a small amount of state, and when an editbox gets acivated set some 'move_camera' flag to false, then check this flag in your code before moving the camera. Then when the editbox is deactivated, set the flag to true, so that normal use of the arrow keys can continue.
Useful Links: Forum Guidelines | Documentation | Tutorials | HOWTO | Videos | Donate to CEGUI | CEGUI Twitter
- l_ourson69
- Just popping in
- Posts: 3
- Joined: Sun Aug 14, 2005 01:59
Re: Hidding the CEGUI mouse cursor using Ogre ( newbie quest
Thanks CrazyEddie,
I just realize what's going on with the mouse cursor. As I expected the problem comes from the Ogre code. (I'm not saying Ogre sucks, far from that)
This is what's happening : I derived my FrameListener class from the oldy ExampleFrameListener class. Ok, this is a handy class for speeding things up at creation time. But it has some "crazy" code (Not as crazy as you man ) It seems that when you're in buffered mode, it still keeps listening to the "m" and "k" key events.
I'm not going to go into the depths of what this means, the only thing I can tell is that by pure change I pressed on the "m" key and pooff the CEGUI mouse disappeared, among other weird behaviors I didn't expect since I was in buffered mode, and as they say you have to set ONLY AND ONLY the keys you want to respond to. Aaaaaaaanyhow, that's how Ogre rocks, so let's not tease the beast. I guess I deserve it for being so lazy!!!
I hope this will/can help others in the future. So to sum it up CEGUI::MouseCursor::getSingleton().hide() is the proper and only way to hide the CEGUI mouse cursor. Point!
Again thanks a lot for the help and time I might have taken from you. Sorry.
I just realize what's going on with the mouse cursor. As I expected the problem comes from the Ogre code. (I'm not saying Ogre sucks, far from that)
This is what's happening : I derived my FrameListener class from the oldy ExampleFrameListener class. Ok, this is a handy class for speeding things up at creation time. But it has some "crazy" code (Not as crazy as you man ) It seems that when you're in buffered mode, it still keeps listening to the "m" and "k" key events.
I'm not going to go into the depths of what this means, the only thing I can tell is that by pure change I pressed on the "m" key and pooff the CEGUI mouse disappeared, among other weird behaviors I didn't expect since I was in buffered mode, and as they say you have to set ONLY AND ONLY the keys you want to respond to. Aaaaaaaanyhow, that's how Ogre rocks, so let's not tease the beast. I guess I deserve it for being so lazy!!!
I hope this will/can help others in the future. So to sum it up CEGUI::MouseCursor::getSingleton().hide() is the proper and only way to hide the CEGUI mouse cursor. Point!
Again thanks a lot for the help and time I might have taken from you. Sorry.
- CrazyEddie
- CEGUI Project Lead
- Posts: 6760
- Joined: Wed Jan 12, 2005 12:06
- Location: England
- Contact:
Re: Hidding the CEGUI mouse cursor using Ogre ( newbie quest
Cool.
Glad you got it working correctly
Glad you got it working correctly
Useful Links: Forum Guidelines | Documentation | Tutorials | HOWTO | Videos | Donate to CEGUI | CEGUI Twitter
Re: Hidding the CEGUI mouse cursor using Ogre ( newbie quest
I've had the same problem (also using Ogre) and solved it with the following code:
void keyPressed(KeyEvent* e)
{
if (e->getKey() == KC_SYSRQ)
{
static size_t nb = 0; // Screenshot number
String fileName = StringConverter::toString(nb++, 6, '0' ) + ".png";
bool bMouseVisible = CEGUI::MouseCursor::getSingleton().isVisible();
CEGUI::MouseCursor::getSingleton().hide();
if(bMouseVisible) // Force a new frame
mWindow->update();
mWindow->writeContentsToFile(fileName);
if(bMouseVisible) // Mouse was shown before, so show after
CEGUI::MouseCursor::getSingleton().show();
LogManager::getSingleton().logMessage("screenshot saved in " + fileName);
}
else
{
CEGUI::System::getSingleton().injectKeyDown(e->getKey());
CEGUI::System::getSingleton().injectChar(e->getKeyChar());
}
e->consume();
}
My understanding of the problem is that the hide() and show() functions only flag the cursor for rendering during the following frames. If the hide() and the writeContentsToFile() functions are executed during the same frame then the mouse cursor will still be shown. The mouse cursor, when set to hidden, is simply not drawn in the next frame; the mouse cursor is not erased during the current frame. The call to update() forces the next frame to be drawn.
What remains to be seen is whether calling update() will have hidden effects: Ogre forum.
void keyPressed(KeyEvent* e)
{
if (e->getKey() == KC_SYSRQ)
{
static size_t nb = 0; // Screenshot number
String fileName = StringConverter::toString(nb++, 6, '0' ) + ".png";
bool bMouseVisible = CEGUI::MouseCursor::getSingleton().isVisible();
CEGUI::MouseCursor::getSingleton().hide();
if(bMouseVisible) // Force a new frame
mWindow->update();
mWindow->writeContentsToFile(fileName);
if(bMouseVisible) // Mouse was shown before, so show after
CEGUI::MouseCursor::getSingleton().show();
LogManager::getSingleton().logMessage("screenshot saved in " + fileName);
}
else
{
CEGUI::System::getSingleton().injectKeyDown(e->getKey());
CEGUI::System::getSingleton().injectChar(e->getKeyChar());
}
e->consume();
}
My understanding of the problem is that the hide() and show() functions only flag the cursor for rendering during the following frames. If the hide() and the writeContentsToFile() functions are executed during the same frame then the mouse cursor will still be shown. The mouse cursor, when set to hidden, is simply not drawn in the next frame; the mouse cursor is not erased during the current frame. The call to update() forces the next frame to be drawn.
What remains to be seen is whether calling update() will have hidden effects: Ogre forum.
Return to “Modifications / Integrations / Customisations”
Who is online
Users browsing this forum: No registered users and 4 guests