Page 1 of 1

Frame listener question

Posted: Mon Apr 17, 2006 02:00
by Tekmoto
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();
   }
};

Posted: Mon Apr 17, 2006 03:09
by jacmoe
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.

Posted: Mon Apr 17, 2006 04:44
by Tekmoto
ok i think i get it...

Thanks!