So I understand the basics behind the
EvtGetEvent(&event,timeout); where time>0
After the timeout a nilEvent is generated. The one problem is that one can
be generated by other means, so you have to check and see if the current
time is greater than the time that you wanted the real nilEvent and if not,
you go back to waiting. I use this for a simple animation and all is fine
until I open a menu. The animation continues and if it happens to be in a
place where the menu is drawn, it draws over it. To solve this, I do a
check and see if the active menu is visible using:
MenuBarType *myMenu = MenuGetActiveMenu();
if((myMenu && myMenu->attr.visible)
{
// whatever
}
if it is visible, I reset the timeout on a nil event and I do NOT do the
animation.
This seems like a bit of a hack. Is there a cleaner way of doing this?
here is the "real" code.
void AppEventLoop(void)
{
UInt16 error;
EventType event;
do
{
// doing something every 5 seconds or so
// generate a nilEvent every second so that I do not have to
// calc the new wait time (longest wait will be 5+1 sec)
EvtGetEvent(&event,SysTicksPerSecond()*1);
if(!SysHandleEvent(&event) &&
!MenuHandleEvent(0,&event,&error) &&
!AppHandleEvent(&event))
FrmDispatchEvent(&event);
}
while(event.eType!=appStopEvent);
}
Boolean MainFormHandleEvent(EventPtr event)
{
Boolean handled=false;
// do something every 5 seconds
static const UInt32 hintTime=SysTicksPerSecond()*5;
static UInt32 nextAnimationTime=TimGetTicks()+hintTime;
if(event->eType==penDownEvent || event->eType==penMoveEvent)
handled=penEvent(event);
else if(event->eType==menuEvent)
handled=MainFormDoCommand(event);
if(handled)
// reset the animation after each move
nextAnimationTime=TimGetTicks()+hintTime;
else if(event->eType == nilEvent)
{
MenuBarType *myMenu = MenuGetActiveMenu();
if(myMenu && myMenu->attr.visible)
// reset the animation if a menu is visible
nextAnimationTime=TimGetTicks()+hintTime;
else if(nextAnimationTime<TimGetTicks())
{
DoAnimation();
nextAnimationTime=TimGetTicks()+hintTime; // reset the animation
}
}
return handled;
}
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/