Re: [gtkmm] Design quetstion



> I'm thinking:
> 
> 1) create a separate thread for the start/stop requirement. The spline
> loop should have a "stopped" flag, which is set by the "stop" button. Is
> that right?
> 
> 2) Display the spline in a drawing area. How do I do the display though?
> Do I use a timer which calls a display callback every 20ms, say,
> independently of the spline loop? Or do I tell my spline program about gtk
> and drawing area, and make it draw the current spline every so many
> iterations? I would rather keep the spline code separated from the gui.

I think the sensible thing would be to create a Spline class with an
update(int iterations=50) method that emits a signal update_done_signal when
it is done. The gui could connect a update_display() function to this
signal. Then update_display() would call Spline::get_representation() which
is a vector of coordinates or something, and draw it.

If you dont want to call Spline::update at timed intervals, you should let
Spline::update() start a private method in a Glib::Thread that when done
should emit a private Glib::Dispatcher signal connected to a method that in
turn emits the update_done_signal. (You shouldn't emit the signal from the
thread directly.)

Simple, isn't it?

/Fredrik Arnerup
e97_far e kth se



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]