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 void drawText(int x, int y, const char *text);
53 bool sync(unsigned long time = ULONG_MAX);
57 void sleep(unsigned long secs);
58 void msleep(unsigned long msecs);
59 void usleep(unsigned long usecs);
62 void closeEvent(QCloseEvent *ev);
63 void customEvent(QEvent *ev);
64 void keyPressEvent(QKeyEvent *ev);
65 void paintEvent(QPaintEvent *ev);
66 void showEvent(QShowEvent *ev);
67 void timerEvent(QTimerEvent *ev);
70 static const int paintInterval = 33;
75 QWaitCondition syncCondition;
88 DrawingThread *thread;
90 void initialize(ThreadFunction f);
94 void safeLock(QMutex &mutex);
95 void safeUnlock(QMutex &mutex);
98 void dirty(int x, int y);
99 void dirty(int x1, int y1, int x2, int y2);
100 void dirty(const QRect &rect);
105 #endif // !DRAWING_WINDOW_H