[SDL] Making a GUI system in SDL
Ilya Olevsky
info at valengames.com
Mon Feb 11 15:08:56 PST 2008
L-28C wrote:
> And the event system works like this (in this case we'll use mouse
> clicks): the main application calls the "OnClick()" method in the GUI
> class with the mouse pointer's position as a parameter. The GUI class
> then sees which control was clicked (based on the mouse's position), and
> calls the "OnClick()" method in that control (in this case we'll use a
> button). But here's the problem; how can this control (button) class let
> the main application know that it was clicked?
What I do in my GUI right now is send a message object in response to an event
(like a mouse click). It's sent as a base class reference that stores the
message type, and is dynamically cast to the appropriate class type when
processed. The message is sent to the widget's parent, and recursively ends up
getting sent all the way to the point where it gets processed (yes, a bit of
stack overhead there).
The nice thing about this is that it doesn't require any callbacks. The not so
nice things are that it requires dynamic casting, and the potentially large
stack size due to recursive sending (for heavily nested widgets). I have some
other ideas that I'll be trying now instead of this, but it's definitely one of
the ways you can do it.
More information about the SDL
mailing list