1 #ifndef DRAWING_WINDOW_H
2 #define DRAWING_WINDOW_H
9 #include <QWaitCondition>
15 class DrawingWindow: public QWidget {
17 typedef void (*ThreadFunction)(DrawingWindow &);
19 static const int DEFAULT_WIDTH = 640;
20 static const int DEFAULT_HEIGHT = 480;
22 DrawingWindow(ThreadFunction fun,
23 int width = DEFAULT_WIDTH, int height = DEFAULT_HEIGHT);
24 DrawingWindow(QWidget *parent,
26 int width = DEFAULT_WIDTH, int height = DEFAULT_HEIGHT);
27 DrawingWindow(QWidget *parent, Qt::WindowFlags flags,
29 int width = DEFAULT_WIDTH, int height = DEFAULT_HEIGHT);
36 // http://www.w3.org/TR/SVG/types.html#ColorKeywords
37 void setColor(float red, float green, float blue);
38 void setColor(const char *name);
39 void setBgColor(float red, float green, float blue);
40 void setBgColor(const char *name);
44 void drawPoint(int x, int y);
45 void drawLine(int x1, int y1, int x2, int y2);
46 void drawRect(int x1, int y1, int x2, int y2);
47 void fillRect(int x1, int y1, int x2, int y2);
48 void drawCircle(int x, int y, int r);
49 void fillCircle(int x, int y, int r);
51 bool sync(unsigned long time = ULONG_MAX);
53 void sleep(unsigned long secs);
54 void msleep(unsigned long msecs);
55 void usleep(unsigned long usecs);
58 void closeEvent(QCloseEvent *ev);
59 void customEvent(QEvent *ev);
60 void keyPressEvent(QKeyEvent *ev);
61 void paintEvent(QPaintEvent *ev);
62 void showEvent(QShowEvent *ev);
63 void timerEvent(QTimerEvent *ev);
66 static const int paintInterval = 33;
71 QWaitCondition syncCondition;
84 DrawingThread *thread;
86 void initialize(ThreadFunction f);
90 void safeLock(QMutex &mutex);
91 void safeUnlock(QMutex &mutex);
94 void dirty(int x, int y);
95 void dirty(int x1, int y1, int x2, int y2);
96 void dirty(const QRect &rect);
101 #endif // !DRAWING_WINDOW_H