动画的窗口图标

时间:2014-12-01 03:44:43

标签: c animation icons gtk

我看过很少的节目,有动画窗口图标。 从遥远的角度来看,这可能是有利的,不是它..

我在发明一个功能的过程中采用了方向舵。 它完成了您可能想到的并使用Sleep()来模拟每个“帧”之后的间隔。 我不必说在主要程序中使用WinAPI是一个坏主意,以及程序将冻结直到函数终止的事实。

回到正轨。我正在寻找避免这种行为的可能性。 这是可以理解的,因此没有人想要一个非功能性的,但请注意动画ICON程序。

1 个答案:

答案 0 :(得分:2)

您可能正在使用Main Event Loop调用您的函数。这是处理所有类型的GUI事件的线程,包括鼠标单击和按键。如果您从此主题中调用Sleep,则所有这些处理任务都将处于暂挂状态,您的程序将冻结。

要避免此行为,请使用g_timeout_add。此函数将在主事件循环内定期调用函数(因此无需自行完成)。你需要定义一个这样的函数:

// define this function somewhere
gboolean animate(gpointer user_data) {
    // cast user_data to appropriate type
    // supposing you have a AnimationParameters class with everything you need...
    AnimationParameters* animParams = (AnimationParameters*)user_data;

    // update animation
    // ...

    return TRUE; // return TRUE to call function again, FALSE to stop
}

在代码的其他地方,要启动动画:

AnimationParameters* animationParameters = new AnimationParameters(...);
g_timeout_add (30,  // call every 30 milliseconds
           animate,
           animationParameters);

希望它有所帮助。