Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
.
[graphlib.git] / DrawingWindow.h
index 66fc445..17253ba 100644 (file)
@@ -1,10 +1,16 @@
 #ifndef DRAWING_WINDOW_H
 #define DRAWING_WINDOW_H
 
 #ifndef DRAWING_WINDOW_H
 #define DRAWING_WINDOW_H
 
+#include <QBasicTimer>
+#include <QColor>
+#include <QImage>
+#include <QMutex>
+#include <QRect>
+#include <QWaitCondition>
 #include <QWidget>
 #include <Qt>
 
 #include <QWidget>
 #include <Qt>
 
-class DrawingWindowPrivate;
+class DrawingThread;
 
 class DrawingWindow: public QWidget {
 public:
 
 class DrawingWindow: public QWidget {
 public:
@@ -27,17 +33,27 @@ public:
     const int width;
     const int height;
 
     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(float red, float green, float blue);
+    void setColor(const char *name);
     void setBgColor(float red, float green, float blue);
     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 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);
 
 
     bool sync(unsigned long time = ULONG_MAX);
 
+    void closeGraph();
+
     void sleep(unsigned long secs);
     void msleep(unsigned long msecs);
     void usleep(unsigned long usecs);
     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:
     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
 };
 
 #endif // !DRAWING_WINDOW_H