X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/graphlib.git/blobdiff_plain/7badda6845696cab7209c13aad6ede58aed61acd..a7346f12e37f808491a76b2465de8ae8cd951d51:/DrawingWindow.h diff --git a/DrawingWindow.h b/DrawingWindow.h index 66fc445..17253ba 100644 --- a/DrawingWindow.h +++ b/DrawingWindow.h @@ -1,10 +1,16 @@ #ifndef DRAWING_WINDOW_H #define DRAWING_WINDOW_H +#include +#include +#include +#include +#include +#include #include #include -class DrawingWindowPrivate; +class DrawingThread; class DrawingWindow: public QWidget { public: @@ -27,17 +33,27 @@ public: const int width; const int height; + // http://www.w3.org/TR/SVG/types.html#ColorKeywords void setColor(float red, float green, float blue); + void setColor(const char *name); void setBgColor(float red, float green, float blue); + void setBgColor(const char *name); void clearGraph(); void drawPoint(int x, int y); void drawLine(int x1, int y1, int x2, int y2); void drawRect(int x1, int y1, int x2, int y2); + void fillRect(int x1, int y1, int x2, int y2); + void drawCircle(int x, int y, int r); + void fillCircle(int x, int y, int r); + + void drawText(int x, int y, const char *text); bool sync(unsigned long time = ULONG_MAX); + void closeGraph(); + void sleep(unsigned long secs); void msleep(unsigned long msecs); void usleep(unsigned long usecs); @@ -51,9 +67,39 @@ protected: void timerEvent(QTimerEvent *ev); private: - DrawingWindowPrivate * const d; + static const int paintInterval = 33; + + QBasicTimer timer; + QMutex imageMutex; + QMutex syncMutex; + QWaitCondition syncCondition; + bool terminateThread; + int lockCount; + + QImage *image; + QPainter *painter; + + QColor fgColor; + QColor bgColor; + + bool dirtyFlag; + QRect dirtyRect; + + DrawingThread *thread; + + void initialize(ThreadFunction f); + + void applyColor(); + + void safeLock(QMutex &mutex); + void safeUnlock(QMutex &mutex); + + void dirty(); + void dirty(int x, int y); + void dirty(int x1, int y1, int x2, int y2); + void dirty(const QRect &rect); - friend class DrawingWindowPrivate; + void mayUpdate(); }; #endif // !DRAWING_WINDOW_H