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 const QFont &getFont() const;
49 void setFont(const QFont &font);
53 void drawPoint(int x, int y);
54 void drawLine(int x1, int y1, int x2, int y2);
55 void drawRect(int x1, int y1, int x2, int y2);
56 void fillRect(int x1, int y1, int x2, int y2);
57 void drawCircle(int x, int y, int r);
58 void fillCircle(int x, int y, int r);
59 void drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3);
60 void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3);
62 void drawText(int x, int y, const char *text, int flags = 0);
63 void drawText(int x, int y, const std::string &text, int flags = 0);
64 void drawTextBg(int x, int y, const char *text, int flags = 0);
65 void drawTextBg(int x, int y, const std::string &text, int flags = 0);
67 unsigned int getPointColor(int x, int y);
69 bool waitMousePress(int &x, int &y, int &button,
70 unsigned long time = ULONG_MAX);
71 bool sync(unsigned long time = ULONG_MAX);
75 static void sleep(unsigned long secs);
76 static void msleep(unsigned long msecs);
77 static void usleep(unsigned long usecs);
80 void closeEvent(QCloseEvent *ev);
81 void customEvent(QEvent *ev);
82 void mousePressEvent(QMouseEvent *ev);
83 void keyPressEvent(QKeyEvent *ev);
84 void paintEvent(QPaintEvent *ev);
85 void showEvent(QShowEvent *ev);
86 void timerEvent(QTimerEvent *ev);
89 //! Intervalle de temps entre deux rendus (ms)
90 static const int paintInterval = 33;
95 QWaitCondition mouseCondition;
97 QWaitCondition syncCondition;
105 Qt::MouseButton mouseButton;
110 DrawingThread *thread;
112 void initialize(ThreadFunction fun);
114 void setColor(const QColor &color);
115 void setBgColor(const QColor &color);
119 void safeLock(QMutex &mutex);
120 void safeUnlock(QMutex &mutex);
123 void dirty(int x, int y);
124 void dirty(int x1, int y1, int x2, int y2);
125 void dirty(const QRect &rect);
129 void realDrawText(int x, int y, const char *text, int flags);
132 #endif // !DRAWING_WINDOW_H