Page 1 of 1

Global Event Set

Posted: Wed May 04, 2005 09:55
by ritz
Hello All,

I am trying to implement Timer class in my widget. Every time timer gets fired I want to send an event to my window.
I have tried using GlobalEventSet for that.

Here is the code
#include "CEGUITimer.h"
#include "CEGUIBase.h"
#include "CEGUIGlobalEventSet.h"

namespace CEGUI
{
const utf8 CEGUITimer::EventTimerFired[] = "TimerFired";

CEGUITimer::CEGUITimer(Ogre::Root* p, long interval)
{
Ogre::Root::getSingleton().getTimer()->getMilliseconds();
p->addFrameListener(this);
setInterval( interval );

GlobalEventSet::getSingleton().addEvent(EventTimerFired);
}

CEGUITimer::~CEGUITimer()
{
mRoot->removeFrameListener(this);
}


bool CEGUITimer::frameStarted(const Ogre::FrameEvent& e)
{
if(mCounter > 0)
mCounter -= e.timeSinceLastFrame;
else
{
mCounter = mInterval;

onNotifyTimedEvent();
}

return true;
}


void CEGUITimer::setInterval(long interval)
{
mInterval = interval;

if( mCounter == 0)
mCounter = interval;
}

void CEGUITimer::onNotifyTimedEvent()
{
EventArgs args;
GlobalEventSet::getSingleton().fireEvent(EventTimerFired, args);
}
}

My timer is working fine.



Here is the code which i am using for subscription

Ogre::Root * root = NULL;

root = Ogre::Root::getSingletonPtr();

if (root == NULL)
return false;

d_timer = new CEGUITimer(root, duration);

if (d_timer != NULL)
{
GlobalEventSet::getSingleton().subscribeEvent(CEGUITimer::EventTimerFired,
Event::Subscriber(&HTMLViewer::onTimerFired, this));
return true;
}

The issue is in receiving the event. I am not able to receive the event.

I tried debugging fireevent code, what i could get is event is not getting fired.

Can any body please tell me where i am going wrong.

Thanks,
Ritz

Re: Global Event Set

Posted: Thu May 05, 2005 12:10
by lindquist
when using the global eventset, you must "prefix" the event string with the widgets event namespace fx:

"FrameWindow/CloseClicked"