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 //! \cond show_protected
85 void closeEvent(QCloseEvent *ev);
86 void customEvent(QEvent *ev);
87 void mousePressEvent(QMouseEvent *ev);
88 void keyPressEvent(QKeyEvent *ev);
89 void paintEvent(QPaintEvent *ev);
90 void showEvent(QShowEvent *ev);
91 void timerEvent(QTimerEvent *ev);
95 //! Intervalle de temps entre deux rendus (ms)
96 static const int paintInterval = 33;
101 QWaitCondition inputCondition;
103 QWaitCondition syncCondition;
104 bool terminateThread;
111 Qt::MouseButton mouseButton;
116 DrawingThread *thread;
118 void initialize(ThreadFunction fun);
120 void setColor(const QColor &color);
121 void setBgColor(const QColor &color);
125 void safeLock(QMutex &mutex);
126 void safeUnlock(QMutex &mutex);
129 void dirty(int x, int y);
130 void dirty(int x1, int y1, int x2, int y2);
131 void dirty(const QRect &rect);
135 void realDrawText(int x, int y, const char *text, int flags);
138 #endif // !DRAWING_WINDOW_H