1 #ifndef DRAWING_WINDOW_H
2 #define DRAWING_WINDOW_H
12 #include <QWaitCondition>
18 class DrawingWindow: public QWidget {
20 typedef void (*ThreadFunction)(DrawingWindow &);
22 static const int DEFAULT_WIDTH = 640;
23 static const int DEFAULT_HEIGHT = 480;
25 DrawingWindow(ThreadFunction fun,
26 int width_ = DEFAULT_WIDTH, int height_ = DEFAULT_HEIGHT);
27 DrawingWindow(QWidget *parent,
29 int width_ = DEFAULT_WIDTH, int height_ = DEFAULT_HEIGHT);
30 DrawingWindow(QWidget *parent, Qt::WindowFlags flags,
32 int width_ = DEFAULT_WIDTH, int height_ = DEFAULT_HEIGHT);
39 void setColor(unsigned int color);
40 void setColor(const char *name);
41 void setColor(float red, float green, float blue);
43 void setBgColor(unsigned int color);
44 void setBgColor(const char *name);
45 void setBgColor(float red, float green, float blue);
47 const QFont& getFont() const;
48 void setFont(const QFont& font);
52 void drawPoint(int x, int y);
53 void drawLine(int x1, int y1, int x2, int y2);
54 void drawRect(int x1, int y1, int x2, int y2);
55 void fillRect(int x1, int y1, int x2, int y2);
56 void drawCircle(int x, int y, int r);
57 void fillCircle(int x, int y, int r);
58 void drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3);
59 void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3);
61 void drawText(int x, int y, const char *text, int flags = 0);
62 void drawTextBg(int x, int y, const char *text, int flags = 0);
64 unsigned int getPointColor(int x, int y);
66 bool waitMousePress(int &x, int &y, int &button,
67 unsigned long time = ULONG_MAX);
68 bool sync(unsigned long time = ULONG_MAX);
72 static void sleep(unsigned long secs);
73 static void msleep(unsigned long msecs);
74 static void usleep(unsigned long usecs);
77 void closeEvent(QCloseEvent *ev);
78 void customEvent(QEvent *ev);
79 void mousePressEvent(QMouseEvent *ev);
80 void keyPressEvent(QKeyEvent *ev);
81 void paintEvent(QPaintEvent *ev);
82 void showEvent(QShowEvent *ev);
83 void timerEvent(QTimerEvent *ev);
86 //! Intervalle de temps entre deux rendus (ms)
87 static const int paintInterval = 33;
92 QWaitCondition mouseCondition;
94 QWaitCondition syncCondition;
102 Qt::MouseButton mouseButton;
107 DrawingThread *thread;
109 void initialize(ThreadFunction fun);
111 void setColor(const QColor& color);
112 void setBgColor(const QColor& color);
116 void safeLock(QMutex &mutex);
117 void safeUnlock(QMutex &mutex);
120 void dirty(int x, int y);
121 void dirty(int x1, int y1, int x2, int y2);
122 void dirty(const QRect &rect);
126 void realDrawText(int x, int y, const char *text, int flags);
129 #endif // !DRAWING_WINDOW_H