Dave writes:
[plug for SDLmm follows below…]
If you are doing this in C++ its not that hard to write an interface
class to handle all this, and then derive the various event types.
First of all, short announcement: I’m working on a lib called SDLmm,
which is a C++ wrapper library for SDL. Current wrapping status is
(about): Events 100%, WM 100%, Video all but mouse/GL. It’s hosted on
sourceforge (http://sourceforge.net/projects/sdlmm).
In any case, I have a very nice event system in my opinion. Basically,
you create a classed derived from EventHandler (documented at
http://sdlmm.sourceforge.net/class_SDLmm__EventHandler.html). Each
type of callback has one or more potential handlers. Here’s a simple
example of it’s use:
using namespace SDLmm;
class MyEventHandler : public EventHandler {
public:
bool done;
MyEventHandler() : done(false) { }
bool HandleKeyPressEvent(SDL_keysym &keysym) {
printf(“Got kbd press event: sym = %d (%s).\n”,
keysym.sym, Event::GetKeyName(keysym.sym));
return true; // event handled
}
bool HandleQuitEvent() {
printf(“Got quit event.\n”);
done = true;
return true;
}
bool HandleEvent(SDL_Event &event) {
// Handle every previously unhandled event the old fashioned way.
}
};
[…]
MyEventHandler ev;
while ( !ev.done ) {
Event::HandleEvents(ev);
[do other stuff]
}
I was told this was similar to that in AWT (thanks to gltron/tesmako
in #SDL for the idea of implementing a system like this).
I find it very handy and easy to use personally. Much cleaner than a
switch checking the type (which, on the other hand, is how the
implementation is done in by Event::HandleEvents).–
[ Below is a random fortune, which is unrelated to the above message. ]
If graphics hackers are so smart, why can’t they get the bugs out of
fresh paint?