To subcribe a mouse event

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

Moderators: CEGUI MVP, CEGUI Team

User avatar
geru
Just popping in
Just popping in
Posts: 7
Joined: Tue Nov 11, 2008 21:14
Location: www.fog3d.org
Contact:

To subcribe a mouse event

Postby geru » Wed Nov 26, 2008 18:57

Hi!!

I'm trying to subscribe a mouse event on a quit button. For do that, tutorial says that I have to create a button, and subscribe it whith the next function:

Code: Select all

quit->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(close(??), this));


Well, to handle the event, I write the close() function out of a cegui class, in order to pass to subscriber function, as a pointer (&function()). And I received this error:

Code: Select all

cegui.cpp:54: error: no matching function for call to ‘close()’
/usr/include/unistd.h:320: note: candidates are: int close(int)
cegui.cpp:23: note:                 bool close(const CEGUI::EventArgs&)
make: *** [cegui.o] Error 1


I don't understand what is CEGUI::EventArgs&, somebody can help me?

Thanks very much ;-)

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Postby CrazyEddie » Wed Nov 26, 2008 19:27

Hi,

CEGUI::EventArgs is the base of a hierarchy of classes that is used to pass relevant information about an event to the subscribed event handler (btw, I would not rely on that d_hasWindow member you can see there, it's highly likely to be removed in a future release).

The specific subclass that is passed will depend upon the event that is being subscribed to, for PushButton::Clicked, this is a CEGUI::WindowEventArgs - so within the event handler you could cast the passed CEGUI::EventArgs reference to a CEGUI::WindowEventArgs reference, you can then access the 'window' field of this object to find out the specific button that was clicked.

HTH

CE.

User avatar
geru
Just popping in
Just popping in
Posts: 7
Joined: Tue Nov 11, 2008 21:14
Location: www.fog3d.org
Contact:

Postby geru » Thu Nov 27, 2008 11:23

Hi!

Thanks you very much, now CEGUI detects events well ;-).

But, I have another problem :-S. That is, I create one button with CEGUI, that when I am playing and I press de 'P' key in order to pause the scene and give control events to Cegui, the button displays on screen and it is waiting for the mouse event (click). When I click on it, the control of events is passed to input (i can play again), but the CEGUI button doesn't delete from screen.

When I trying to delete the CEGUI object, I receive segmentation fault. How can I do that?

Here is the code of the constructor:

Code: Select all

Cegui::Cegui(Ogre::SceneManager *manager) {
  Ogre::RenderWindow *window = Ogre::Root::getSingleton().getAutoCreatedWindow();
  renderer = new CEGUI::OgreCEGUIRenderer(window, Ogre::RENDER_QUEUE_OVERLAY, false, 0, manager);
  system = new CEGUI::System(renderer);
  // Default skin
  CEGUI::SchemeManager::getSingleton().loadScheme((CEGUI::utf8*)"TaharezLookSkin.scheme");
  system->setDefaultMouseCursor((CEGUI::utf8*)"TaharezLook", (CEGUI::utf8*)"MouseArrow");
  CEGUI::MouseCursor::getSingleton().setImage(CEGUI::System::getSingleton().getDefaultMouseCursor());
  system->setDefaultFont((CEGUI::utf8*)"BlueHighway-12");
}


Here, to create a button:

Code: Select all

void Cegui::menu(Scene *scene) {
  CEGUI::WindowManager *window = CEGUI::WindowManager::getSingletonPtr();
  //CEGUI::Window *menu = window->loadWindowLayout((CEGUI::utf8*)"ogregui.layout");
  CEGUI::Window *menu = window->createWindow("DefaultGUISheet", "CEGUI/Menu");
  CEGUI::Window *quit = window->createWindow("TaharezLook/Button", "CEGUI/Menu/QuitButton");
  quit->setText("PAUSE");
  quit->setSize(CEGUI::UVector2(CEGUI::UDim(1, 0), CEGUI::UDim(0.10, 0)));
  menu->addChildWindow(quit);
  system->setGUISheet(menu);
  scenePointer = scene;
  input::Input::getInstance()->setListeners(this, this); //Cegui is now listening
  quit->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&Cegui::close, this));
}



And here, destructor:

Code: Select all

Cegui::~Cegui(void) {
  delete renderer;
  delete system;
}



Thanks again ;-).

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Postby CrazyEddie » Thu Nov 27, 2008 13:49

Hi,

I'm not sure I'd want to be initialising and tearing down the whole CEGUI system every time someone pauses. You'll probably be better off just setting up and cleaning up CEGUI up once, and then create / delete just the button (or even have it pre-created and just show/hide it). If you're not actually setting it up every time, forgive me, it just looked that way :)

With regards to the seg, it's probably because you're deleting the CEGUI::System and your renderer object out of sequence. You have to delete the CEGUI::System first, then the renderer (because part of the cleanup accesses the renderer object - in your case, you already deleted it).

CE.

User avatar
geru
Just popping in
Just popping in
Posts: 7
Joined: Tue Nov 11, 2008 21:14
Location: www.fog3d.org
Contact:

Postby geru » Thu Nov 27, 2008 22:33

Thanks you very much again.

I am going to delete the created buttons.

A greeting,

Geru.


Return to “Offtopic Discussion”

Who is online

Users browsing this forum: No registered users and 4 guests