Iain Staffell schrieb:
> I am trying to add a timeout to a program that draws something,
> so that I can make an animated drawing.
try smthng like this:
-------- draw-timeout.cxx ---------
// compile with $ fltk2-config --compile drawtimeout.cxx
#include <fltk/run.h>
#include <fltk/Window.h>
#include <fltk/Widget.h>
#include <fltk/draw.h>
#include <stdio.h>
using namespace fltk;
class BlackBox : public Widget
{
void draw()
{
setcolor(BLACK);
fillrect(0,0,w(),h());
push_matrix();
scale(w()/2.0f, h()/2.0f);
translate(1,1);
rotate(deg);
setcolor(RED);
drawline(0.0f, -0.5f, 0.0f, 0.5f);
drawline(-0.5f, 0.0f, 0.5f, 0.0f);
pop_matrix();
}
public:
BlackBox(int x,int y,int w,int h,const char *l=0) : Widget(x,y,w,h,l)
{deg=0;}
float deg;
};
float time=0.1;
BlackBox* pB=0;
void callback(void*)
{
pB->deg++;
pB->redraw();
repeat_timeout(time, callback);
}
int main(int argc, char ** argv)
{
Window window(400, 300, "Blarter");
window.begin();
BlackBox bb(0, 0, 400, 300);
window.resizable(pB=&bb);
window.end();
window.show();
add_timeout(time,callback);
while (Window::first())
wait();
return 0;
}
// --- eof ---
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk