求助: gtk+如何让窗口持续redraw?[已解决]

软件和网站开发以及相关技术探讨
回复
johnnr
帖子: 40
注册时间: 2013-02-19 6:28

求助: gtk+如何让窗口持续redraw?[已解决]

#1

帖子 johnnr » 2013-04-24 9:03

“We will draw inside the on_expose_event() callback. The callback is connected to the expose-event signal. The signal is emitted, when the window is going to be redrawn. ”

为了做动画,用了时钟。时间到,计算新图,重画图。
问题是,我的计算很费时间,比如定时2秒间隔,计算要用1.5秒。计算新图,重画图后,要再等0.5秒才能进行下一次计算。
如何节约那0.5秒,持续不断地计算画图呢?
可以不用定时么?如何让window持续发出redraw的信号,触发on_expose_event()进行计算画图?

谢谢
上次由 johnnr 在 2013-04-27 18:26,总共编辑 1 次。
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: 求助: gtk+如何让窗口持续redraw?

#2

帖子 eexpress » 2013-04-24 14:48

可以触发expose事件。
● 鸣学
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: 求助: gtk+如何让窗口持续redraw?

#3

帖子 eexpress » 2013-04-24 15:13

GLib.Timeout.add(50,()=>{
step++;
queue_draw();
if(step<zoom.length)return true; else return false;
});
● 鸣学
johnnr
帖子: 40
注册时间: 2013-02-19 6:28

Re: 求助: gtk+如何让窗口持续redraw?

#4

帖子 johnnr » 2013-04-25 11:40

eexpress 写了:GLib.Timeout.add(50,()=>{
step++;
queue_draw();
if(step<zoom.length)return true; else return false;
});
看不懂。我用的是:

代码: 全选

    g_timeout_add    (1000,  (GSourceFunc) drawarea1_timeout, (gpointer) drawarea1);
drawarea1_timeout如下:

代码: 全选

static gboolean drawarea1_timeout (GtkWidget *widget)
{
    static GdkPoint points[360];    /* test */
    static int flag = 0;
    int i;
    int  x1 = widget->allocation.width;
    int  y1 = widget->allocation.height;
	
	Tnow=Tnow+10.0/180.0*M_PI;
    if (pixmap_drawarea1 == NULL){
        return(TRUE);
    }
    if (flag != 0){
        gdk_draw_points(pixmap_drawarea1, widget->style->black_gc, points, 360);
    }
	float a=100.0;
	float pi=3.1415926;
	float f=1.0;
	int pp;
    for (i=0; i < 360; i++) {
        points[i].x = i % x1;
		pp=(int) (a*sin(pi*i/180.0-Tnow));
        points[i].y = (pp+y1/2) % y1;
    }
    gdk_draw_points(pixmap_drawarea1, widget->style->white_gc, points, 360);
    gtk_widget_queue_draw_area (widget, 0, 0, x1, y1);
    flag = 1;
    return (TRUE);
}
怎么改呀?
johnnr
帖子: 40
注册时间: 2013-02-19 6:28

Re: 求助: gtk+如何让窗口持续redraw?[已解决]

#5

帖子 johnnr » 2013-04-27 18:26

找到了。
我要的是g_idle_add函数。
回复