Re: [gtkmm] Design quetstion
- From: ZHOU DX <zhou_dx yahoo com>
- To: Silviu D Minut <minutsil cse msu edu>, gtkmm-list gnome org
- Subject: Re: [gtkmm] Design quetstion
- Date: Thu, 15 May 2003 17:36:57 -0700 (PDT)
--- Silviu D Minut <minutsil cse msu edu> wrote:
> This is not strictly a gtkmm question, but I'm sure
> someone will know how
> to do this.
>
> I need to build a gui for a program that updates a
> spline (in some
> meaningful way), iteratively. Right now I run the
> spline program at the
> prompt, and I save the spline to a file every 50
> iterations.
>
> Instead of that, I want to display the updated
> spline and I don't want to
> see the old updates, just the current one. It must
> look like a moving
> snake. Also, the algorithm must be started/stopped
> from a toggle button.
> What is the general plan for that?
>
> 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.
> Thanks for any advice!
> Silviu Minut
Let the thread do the calculation. After 50 iterations
or so, the thread saves the latest result into an
array or whatever that the GUI can see, and then
notify gui about the change. (gui->notify() or
gui->notify(data)???)
The thread have to keep a reference to the GUI object.
The working thread may sleep for a while, to let the
GUI have chance to take over CPU.
Then GUI may call something like queue_draw() to
update the display. In the expose event handler of the
drawing_area, you just write some codes to draw the
spline based on the content of the buffer where the
thread put data into. To draw the spline, you can just
draw some line segments as a start. And then think
about better digitalisation scheme to make it smooth.
I am not sure if you need to protect the notify call
with things like "g_thread_enter/leave". It depends on
how the queue_draw is implemented in this case. (if
the drawing still happens inside thread.)
Btw, I have a question to everyone about the pthread
callback. How can I use a class member function
(non-static) as the callback?
Can I do it like this?
pthread_create(&m_the_thread, NULL,
SigC::slot(myclass, &CMyClass::listen),NULL)
Dan
=====
----------------------------------------------------------
Have fun!
__________________________________________________________
__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]