1 #ifndef DRAWING_WINDOW_H
2 #define DRAWING_WINDOW_H
11 #include <QWaitCondition>
21 class DrawingWindow: public QWidget {
23 //! Type de la fonction de dessin, passée en paramètre de construction.
24 typedef void (*ThreadFunction)(DrawingWindow &);
26 //! Largeur par défaut de la fenêtre.
27 static const int DEFAULT_WIDTH = 640;
28 //! Hauteur par défaut de la fenêtre.
29 static const int DEFAULT_HEIGHT = 480;
31 DrawingWindow(ThreadFunction fun,
32 int width_ = DEFAULT_WIDTH, int height_ = DEFAULT_HEIGHT);
33 DrawingWindow(QWidget *parent,
35 int width_ = DEFAULT_WIDTH, int height_ = DEFAULT_HEIGHT);
36 DrawingWindow(QWidget *parent, Qt::WindowFlags flags,
38 int width_ = DEFAULT_WIDTH, int height_ = DEFAULT_HEIGHT);
42 //! Largeur de la fenêtre.
44 //! Hauteur de la fenêtre.
47 void setColor(unsigned int color);
48 void setColor(const char *name);
49 void setColor(float red, float green, float blue);
51 void setBgColor(unsigned int color);
52 void setBgColor(const char *name);
53 void setBgColor(float red, float green, float blue);
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);
64 void drawText(int x, int y, const char *text, int flags = 0);
65 void drawTextBg(int x, int y, const char *text, int flags = 0);
67 unsigned int getPointColor(int x, int y);
69 bool sync(unsigned long time = ULONG_MAX);
73 void sleep(unsigned long secs);
74 void msleep(unsigned long msecs);
75 void usleep(unsigned long usecs);
78 void closeEvent(QCloseEvent *ev);
79 void customEvent(QEvent *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 syncCondition;
102 DrawingThread *thread;
104 void initialize(ThreadFunction fun);
106 void setColor(const QColor& color);
107 void setBgColor(const QColor& color);
111 void safeLock(QMutex &mutex);
112 void safeUnlock(QMutex &mutex);
115 void dirty(int x, int y);
116 void dirty(int x1, int y1, int x2, int y2);
117 void dirty(const QRect &rect);
121 void realDrawText(int x, int y, const char *text, int flags);
124 #endif // !DRAWING_WINDOW_H