Page 1 of 1

subscribeEvent for CEGUI

Posted: Fri May 22, 2009 05:35
by haibo19981984
This is primary code,such as:

Code: Select all

class myTerrain
{
   ......
   myTerrain::setbrush()
   {
   }
}
class CGame
{
   myTerrain* d_terrain;
 
   void CGame::handleBrushShape(const CEGUI::EventArgs& e)
   {
      d_terrain.setbrush();
   }
   ......
   void CGame::init()
   {
   ......
   winMgr.getWindow("GameGUI/HumanInfo/Close")->subscribeEvent(
           CEGUI::Window::EventMouseButtonDown,
           CEGUI::Event::Subscriber(&CGame::handleBrushShape, this));
   ......
   }
}

I want to separate handleBrushShape() from CGame,such as:

Code: Select all

class myTerrain
{
   myTerrain::setbrush()
   {
   }
   ......
   myTerrain::handleBrushShape(const CEGUI::EventArgs& e)
   {
      ......
      setbrush();
   }
}
class CGame
{
   myTerrain* d_terrain;
 
   void CGame::handleBrushShape(const CEGUI::EventArgs& e)
   {
      ......
      d_terrain.setbrush();
   }
   ......
   void CGame::init()
   {
   ......
   winMgr.getWindow("GameGUI/HumanInfo/Close")->subscribeEvent(
           CEGUI::Window::EventMouseButtonDown,
           CEGUI::Event::Subscriber(??????, this));
   ......
   }
}

How can I write in "??????".
Can I write "&(myTerrain->handleBrushShape())" or "&myTerrain::handleBrushShape"?

Re: subscribeEvent for CEGUI

Posted: Fri May 22, 2009 14:09
by Jamarr
You do not have to pass in the 'this' pointer just because you are calling subscribe from CGame. The 'this' pointer is exactly the same as a class-pointer; since the method you want will be in myTerrain you obviously cannot access that method from a CGame pointer.

So you subscribe to the event just as you did originally, by passing in a method-pointer and a corresponding class-pointer. The only difference is that you are using a different class, so you need to reference the method in that class and pass in a pointer to that class instead. Ex:

Code: Select all

CEGUI::Event::Subscriber(&myTerrain::handleBrushShape, d_terrain)

Re: subscribeEvent for CEGUI

Posted: Sat May 23, 2009 08:05
by haibo19981984
thanks for replay!