[vox-tech] fltk + SDL and questions about handling events

Jan W vox-tech@lists.lugod.org
Tue, 18 May 2004 19:26:45 -0700 (PDT)


Hi all:

I have a question about events structs with fltk and SDL:

here's the guts of my main function:

int main(int argc, char **argv)
{
// I have two functions defined to handle events:
Fl::add_handler(my_event_handler);
//and
SDL_Init(SDL_INIT_VIDEO);

//and I have SDL_Event *sdlevent pointer defined
window->construct_new_window();
window->show()
// To allow fltk to share events with SDL, instead of then 
// going into fl::run(), I made a custom event loop:

//fl::run();

while(fl::check()) {
   if (SDL_PollEvent(&sdlevent))
       my_event_handler(0);
   }
return(0)
}

The only thing left out is that i copy sdlevent.key.keysym.sym to my local key
char variable, and my other matching events (Shift, control, mouseclick) into
the FL equivalents such that they will fall into points in the switch{} in the
global event handler, my_event_handler.  It works nicely now, with multiple
windows all sharing events...

I know that fltk stores its event in static structures, and that SDL uses a
completely different model to handle events (FL::event() is an integer,
SDL_PollEvent fills the struct SDL_Event with current event data).  In fltk,
the event structures are defined when they are created, and fl::run() passes
the current events onto the ones defined (callbacks for button clicks, etc). 
That's why I substitute the call from run to check, because check() just the
checks the queue once, not looping forever.  This gives me a chance to call
PollEvent, and thus checking the two queues using the same event loop.

My question is this: is this a good way to do it?  Has anyone had experience
with handling events from multiple windows/libraries/event structs?  I just
need my code to be cross platform portable and reliable (i haven't tried it on
anything beside x86 linux)...

Any other tips or tricks?

--thanks in advance

jan

=====
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
EDUCATION, n. That which discloses to the wise and disguises from the
foolish their lack of understanding.
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><


	
		
__________________________________
Do you Yahoo!?
SBC Yahoo! - Internet access at a great low price.
http://promo.yahoo.com/sbc/