subscribeEvent for CEGUI

Forum for general chit-chat or off-topic discussion.

Moderators: CEGUI MVP, CEGUI Team

haibo19981984
Just popping in
Just popping in
Posts: 10
Joined: Wed May 06, 2009 06:37

subscribeEvent for CEGUI

Postby haibo19981984 » Fri May 22, 2009 05:35

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"?

Jamarr
CEGUI MVP
CEGUI MVP
Posts: 812
Joined: Tue Jun 03, 2008 23:59
Location: USA

Re: subscribeEvent for CEGUI

Postby Jamarr » Fri May 22, 2009 14:09

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)
If somebody helps you by replying to your thread, upvote him/her as a thanks! Make sure to include your CEGUI.log and everything you tried when posting! And remember that we are not magicians!

haibo19981984
Just popping in
Just popping in
Posts: 10
Joined: Wed May 06, 2009 06:37

Re: subscribeEvent for CEGUI

Postby haibo19981984 » Sat May 23, 2009 08:05

thanks for replay!


Return to “Offtopic Discussion”

Who is online

Users browsing this forum: No registered users and 6 guests