1 #ifndef DRAWING_WINDOW_H
2 #define DRAWING_WINDOW_H
12 #include <QWaitCondition>
19 class DrawingWindow: public QWidget {
21 typedef void (*ThreadFunction)(DrawingWindow &);
23 static const int DEFAULT_WIDTH = 640;
24 static const int DEFAULT_HEIGHT = 480;
26 DrawingWindow(ThreadFunction fun,
27 int width_ = DEFAULT_WIDTH, int height_ = DEFAULT_HEIGHT);
28 DrawingWindow(QWidget *parent,
30 int width_ = DEFAULT_WIDTH, int height_ = DEFAULT_HEIGHT);
31 DrawingWindow(QWidget *parent, Qt::WindowFlags flags,
33 int width_ = DEFAULT_WIDTH, int height_ = DEFAULT_HEIGHT);
40 void setColor(unsigned int color);
41 void setColor(const char *name);
42 void setColor(float red, float green, float blue);
44 void setBgColor(unsigned int color);
45 void setBgColor(const char *name);
46 void setBgColor(float red, float green, float blue);
48 void setPenWidth(int width);
50 const QFont &getFont() const;
51 void setFont(const QFont &font);
53 void setAntialiasing(bool state);
57 void drawPoint(int x, int y);
58 void drawLine(int x1, int y1, int x2, int y2);
59 void drawRect(int x1, int y1, int x2, int y2);
60 void fillRect(int x1, int y1, int x2, int y2);
61 void drawCircle(int x, int y, int r);
62 void fillCircle(int x, int y, int r);
63 void drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3);
64 void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3);
66 void drawText(int x, int y, const char *text, int flags = 0);
67 void drawText(int x, int y, const std::string &text, int flags = 0);
68 void drawTextBg(int x, int y, const char *text, int flags = 0);
69 void drawTextBg(int x, int y, const std::string &text, int flags = 0);
71 unsigned int getPointColor(int x, int y) const;
73 bool waitMousePress(int &x, int &y, int &button,
74 unsigned long time = ULONG_MAX);
75 bool sync(unsigned long time = ULONG_MAX);
79 static void sleep(unsigned long secs);
80 static void msleep(unsigned long msecs);
81 static void usleep(unsigned long usecs);
84 void closeEvent(QCloseEvent *ev);
85 void customEvent(QEvent *ev);
86 void mousePressEvent(QMouseEvent *ev);
87 void keyPressEvent(QKeyEvent *ev);
88 void paintEvent(QPaintEvent *ev);
89 void showEvent(QShowEvent *ev);
90 void timerEvent(QTimerEvent *ev);
93 //! Intervalle de temps entre deux rendus (ms)
94 static const int paintInterval = 33;
99 QWaitCondition mouseCondition;
101 QWaitCondition syncCondition;
102 bool terminateThread;
109 Qt::MouseButton mouseButton;
114 DrawingThread *thread;
116 void initialize(ThreadFunction fun);
118 void setColor(const QColor &color);
119 void setBgColor(const QColor &color);
123 void safeLock(QMutex &mutex);
124 void safeUnlock(QMutex &mutex);
127 void dirty(int x, int y);
128 void dirty(int x1, int y1, int x2, int y2);
129 void dirty(const QRect &rect);
133 void realDrawText(int x, int y, const char *text, int flags);
136 #endif // !DRAWING_WINDOW_H