SDL Digest, Vol 14, Issue 15

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!

libsigc++, boost::signals library, etc. Provide ways of binding the object
and member
function pointer toegether and storing it, connecting more signals.

struct button
{
sigc::signal<void(int)> signal_clicked;
button(){ signal_clicked.connect(sigc::bind(*this, &button::on_clicked));
};
virtual void on_clicked(int){}
virtual ~button(){}
};

struct mybutton: button
{
void on_clicked(int i){ cout<< i; }
}

and somewhere in the event loop you dispatch the signal_clicked signal like:
signal_clicked(3);

That’s essentially how gtkmm works.

If you can read Pascal syntax, try downloading a free copy of either Turbo Delphi or Lazarus and examining the code to the system’s visual control library. As long as you’ve gotta reinvent the wheel, why not study some existing wheel blueprints? ;)>But here’s the problem; how can this control (button) class let the main application know that it was

clicked?

As long as you’ve gotta reinvent the wheel, why not study some existing
wheel blueprints? :wink:

That’s easy for you to say… Wheeler! :wink:

–GOn Feb 12, 2008 1:48 PM, Mason Wheeler wrote:

This is getting pretty far off topic for SDL.

Bob PendletonOn 2/12/08, Mason Wheeler wrote:

If you can read Pascal syntax, try downloading a free copy of either Turbo
Delphi or Lazarus and examining the code to the system’s visual control
library. As long as you’ve gotta reinvent the wheel, why not study some
existing wheel blueprints? :wink:

But here’s the problem; how can this control (button) class let the main
application know that it was

clicked?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org