l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2004 May 18 23:50

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] fltk + SDL and questions about handling events
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

So basically you're doing the following, right?:

   while(1) {
     // poll FLTK
     // poll SDL events

     // do something

But the problem is this is a tight-loop and it's gonna eat up all of CPU
time.  So you'll need some sleeping code to yield some timeslices to other
processes, so your code becomes like this:

   while(1) {
     // poll FLTK
     // poll SDL events

     // do something


But this is problematic for SDL because SDL window freezes while usleep()
is running.  This is because SDL's event handler can't run while usleep()
is active.  So you'll need to use SDL's SDL_Delay() call instead, like

   while(1) {
     // poll FLTK
     // poll SDL events

     // do something


This is fine for SDL, but (without knowing FLTK too much) perhaps FLTK has
similar problems of freezing when non-FLTK sleep call is called? Looking
at the FLTK demo on the SDL website it looks like it's okay to do this
so... I guess it's good.

BTW, is this for Tuxpaint-config?  What's the SDL window for?


On Tue, 18 May 2004, Jan W wrote:

> 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
> //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/
> _______________________________________________
> vox-tech mailing list
> vox-tech@lists.lugod.org
> http://lists.lugod.org/mailman/listinfo/vox-tech

Mark K. Kim
AIM: markus kimius
Homepage: http://www.cbreak.org/
Xanga: http://www.xanga.com/vindaci
Friendster: http://www.friendster.com/user.jsp?id=13046
PGP key fingerprint: 7324 BACA 53AD E504 A76E  5167 6822 94F0 F298 5DCE
PGP key available on the homepage
vox-tech mailing list

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Sunset Systems
Who graciously hosts our website & mailing lists!