Frame listener question

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

Tekmoto
Just popping in
Just popping in
Posts: 7
Joined: Fri Apr 14, 2006 06:08

Frame listener question

Postby Tekmoto » Mon Apr 17, 2006 02:00

Hi,

I'm a bit confused as to how the FrameListener works for CEGUI. I followed the example on the Ogre3D tutorial (http://www.ogre3d.org/wiki/index.php/Basic_Tutorial_6).

My questions are:

1) How does the program know to quit when I click on the "Quit" button?

2) How would I register an action to a button I created?

Thanks in advance! You've all been very helpful!

- Charles

Here is the FrameListener code I used:

Code: Select all

class GuiFrameListener : public ExampleFrameListener, public MouseMotionListener, public MouseListener
{
private:
   CEGUI::Renderer* mGUIRenderer;
   bool mShutdownRequested;

public:
   // NB using buffered input
   GuiFrameListener(RenderWindow* win, Camera* cam, CEGUI::Renderer* renderer)
       : ExampleFrameListener(win, cam, true, true),
         mGUIRenderer(renderer),
         mShutdownRequested(false)
   {
       mEventProcessor->addMouseMotionListener(this);
       mEventProcessor->addMouseListener(this);
       mEventProcessor->addKeyListener(this);
   }

   // Tell the frame listener to exit at the end of the next frame
   void requestShutdown(void)
   {
       mShutdownRequested = true;
   }

   bool frameEnded(const FrameEvent& evt)
   {
       if (mShutdownRequested)
           return false;
       else
           return ExampleFrameListener::frameEnded(evt);
   }

   void mouseMoved (MouseEvent *e)
   {
       CEGUI::System::getSingleton().injectMouseMove(
               e->getRelX() * mGUIRenderer->getWidth(),
               e->getRelY() * mGUIRenderer->getHeight());
       e->consume();
   }

   void mouseDragged (MouseEvent *e)
   {
       mouseMoved(e);
   }

   void mousePressed (MouseEvent *e)
   {
       CEGUI::System::getSingleton().injectMouseButtonDown(
         convertOgreButtonToCegui(e->getButtonID()));
       e->consume();
   }

   void mouseReleased (MouseEvent *e)
   {
       CEGUI::System::getSingleton().injectMouseButtonUp(
         convertOgreButtonToCegui(e->getButtonID()));
       e->consume();
   }

   void mouseClicked(MouseEvent* e) {}
   void mouseEntered(MouseEvent* e) {}
   void mouseExited(MouseEvent* e) {}

   void keyPressed(KeyEvent* e)
   {
       if(e->getKey() == KC_ESCAPE)
       {
           mShutdownRequested = true;
           e->consume();
           return;
       }

       CEGUI::System::getSingleton().injectKeyDown(e->getKey());
       CEGUI::System::getSingleton().injectChar(e->getKeyChar());
       e->consume();
   }

   void keyReleased(KeyEvent* e)
   {
       CEGUI::System::getSingleton().injectKeyUp(e->getKey());
       e->consume();
   }

   void keyClicked(KeyEvent* e)
   {
       // Do nothing
       e->consume();
   }
};

User avatar
jacmoe
Just can't stay away
Just can't stay away
Posts: 136
Joined: Sun Apr 03, 2005 14:18
Location: Holbaek, Denmark
Contact:

Postby jacmoe » Mon Apr 17, 2006 03:09

Question number one is actually an OGRE question:
In the example framework, when you return false from frameEnded, OGRE::Root::beginRendering ends, and your application quits.

Tekmoto
Just popping in
Just popping in
Posts: 7
Joined: Fri Apr 14, 2006 06:08

Postby Tekmoto » Mon Apr 17, 2006 04:44

ok i think i get it...

Thanks!


Return to “Help”

Who is online

Users browsing this forum: No registered users and 19 guests