X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/graphlib.git/blobdiff_plain/f41c1c8ff250f095b47fb6d5f7e578279b0c2844..abb9adcc79ad7c8bff8741c19df15e6fad1603c6:/DrawingWindow.h diff --git a/DrawingWindow.h b/DrawingWindow.h index 7dd9bb7..d2ee6de 100644 --- a/DrawingWindow.h +++ b/DrawingWindow.h @@ -1,29 +1,108 @@ #ifndef DRAWING_WINDOW_H #define DRAWING_WINDOW_H -#include "DrawingArea.h" -#include -#include +#define USE_PIXMAP_CACHE + +#include +#include +#include +#include +#include +#ifdef USE_PIXMAP_CACHE +# include +#endif +#include #include +#include class DrawingWindow: public QWidget { /* Q_OBJECT */ public: - DrawingWindow(DrawingArea &a); - DrawingWindow(QWidget *parent, DrawingArea &a); - DrawingWindow(QWidget *parent, Qt::WindowFlags flags, DrawingArea &a); + typedef int (*ThreadFunction)(DrawingWindow &); + + static const int DEFAULT_WIDTH = 640; + static const int DEFAULT_HEIGHT = 480; + + DrawingWindow(ThreadFunction fun, + int width = DEFAULT_WIDTH, int height = DEFAULT_HEIGHT); + DrawingWindow(QWidget *parent, + ThreadFunction fun, + int width = DEFAULT_WIDTH, int height = DEFAULT_HEIGHT); + DrawingWindow(QWidget *parent, Qt::WindowFlags flags, + ThreadFunction fun, + int width = DEFAULT_WIDTH, int height = DEFAULT_HEIGHT); + + ~DrawingWindow(); + + int width() const; + int height() const; + + void setColor(float red, float green, float blue); + void setColor(const QColor &color); + + void drawPoint(int x, int y); + void drawLine(int x1, int y1, int x2, int y2); protected: void paintEvent(QPaintEvent *ev); + void showEvent(QShowEvent *ev); void timerEvent(QTimerEvent *ev); private: - DrawingArea &drawingArea; - QPixmap pixmap; + class DrawingThread; + + static const int paintInterval = 33; + QBasicTimer timer; - void initialize(); + QImage *image; + QPainter *painter; +#ifdef USE_PIXMAP_CACHE + QPixmap *pixmap; +#endif + + DrawingThread *thread; + bool thread_started; + + bool dirtyFlag; + QRect dirtyRect; + + QMutex mutex; + + void initialize(ThreadFunction fun, int width, int height); + + void lock(); + void unlock(); + + void setDirtyRect(); + void setDirtyRect(int x, int y); + void setDirtyRect(int x1, int y1, int x2, int y2); + void setDirtyRect(const QRect &rect); }; +inline +int DrawingWindow::width() const +{ + return image->width(); +} + +inline +int DrawingWindow::height() const +{ + return image->height(); +} + +inline +void DrawingWindow::lock() +{ + mutex.lock(); +} + +inline +void DrawingWindow::unlock() +{ + mutex.unlock(); +} + #endif // !DRAWING_WINDOW_H