Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-03-04 08:39:15


Vladimir Prus wrote:
>
> So, if I want to create a widget for drawing graph, I'll have to
> write:
>
> void draw_the_graph(window w, ....)
> {
> .....
> }
>
> void handle_click(window w, ....)
> {
> // Add new vertex
> }
>
> void handle_right_click(window w, ...)
> {
> // show vertex properties, if mouse points
> // to a vertex
> }
>
> window make_graph_widget()
> {
> windows w;
> w.on_draw = &draw_the_graph;
> w.on_mouse_click = &handle_click;
> w.on_mouse_right_click = &handle_right_click;
> return w;
> }
>
> ? What are the chances that handle_right_click can be reused anywhere
> else,

Slim, but possible.

> is it really independent from GUI,

No, but irrelevant.

> and isn't this too complex a solution?

No. The alternative solution is comparable in complexity, and as soon as you
add another graph widget that has different left or right click behaviors,
or make w change its appearance dynamically on response to a combo box cb
(by just assigning different drawing functions to w.on_draw in
cb.on_change), you'll see why the event-based model is superior. It's not a
new invention, just look at Delphi.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk