[C++] Event system suggestion (for a GUI library)?

Started by
12 comments, last by _goat 15 years, 9 months ago
Have you looked at Qt? That would be a good source of inspiration. They go to great lengths (including code generation) to implement a signal/slot system in C++. Here is what it looks like. It works really well.
Advertisement
Quote:Original post by pinacolada
Have you looked at Qt? That would be a good source of inspiration. They go to great lengths (including code generation) to implement a signal/slot system in C++. Here is what it looks like. It works really well.


That looks good at first glance, will read it, thanks! :)

EDIT: deeper glance: looks like a wonderful system! I am actually thinking of rebuilding the library from scratch...I had to change a lot anyways, so I can just aswell start fresh.

Also, I will need to think of a way to build the signal and slot system myself...

[Edited by - Decrius on July 25, 2008 5:03:13 PM]
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
This might give you some ideas to play with, even though it is specific to Windows: http://www.codeproject.com/KB/library/DWinLib.aspx. The interesting section is the one titled 'Button and menu clicks'.
Have you thought about Boost.Signals?

class button{public:    boost::signal< void(int, int) > on_mouse_move;    void handle_operating_system_message(const osmessage& m)    {        if (m.type == MOUSE_MOVE)            if (on_mouse_move) // test to make sure at least one thing's connected                on_mouse_move(m.x, m.y); // probably HIWORD/LOWORD, but whatever    }};class listbox{public:    void add_entry(int x, int y)    {        // put x and y into your list as a std::pair<>, perhaps    }};int main(){    // we'll forget about their dimensions/positions, etc    button b;    listbox L;    b.on_mouse_move.connect( boost::bind(&listbox::add_entry, &L, _1, _2) );}


Now whenever the operating system sends a mouse-move message to the button (or however you've implemented this), everything that's connected to the buttons on_mouse_move signal is notified. For a comparison to the MVC, the View is the GUI, the Model is the aggregate of the class instances, and the Controller is made up of the interaction between the bound functions. It's served me well in the past. Just thought I'd give another method.
[ search: google ][ programming: msdn | boost | opengl ][ languages: nihongo ]

This topic is closed to new replies.

Advertisement