[SDL] Making a GUI system in SDL
Iain Bethune
iain at pyramid-productions.net
Mon Feb 11 08:48:08 PST 2008
An often used solution to this problem (which applies generally to all
sorts of callbacks) is to define the callback function as
OnClickEvent(Application *data){
data->OnClickEvent();
}
And have it as a static method, or a function outside of a class (C-
style), but inside the function you call the instance method on the
supplied object.
In general(e.g. in a library), the data would be a void* and you could
cast it down to whatever class you want to call a method on.
Cheers
- Iain
On 11 Feb 2008, at 16:39, L-28C wrote:
> Hello everyone!
>
> My system works like this:
>
> Control (base class)
> -- GUI (control container)
> -- Button (sample control)
> -- ...other controls
>
> 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?
>
> I tried to place a function pointer called "m_pfnOnClickEvent" and let
> the main application set a function to it when it creates the
> button...
> but C++ doesn't let you put member methods onto function pointers, and
> my program is 100% object-oriented.
>
> Any ideas? Thanks!
>
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
More information about the SDL
mailing list