diff --git a/DestinationGLCanvas.cpp b/DestinationGLCanvas.cpp index fe90313..286f2a4 100644 --- a/DestinationGLCanvas.cpp +++ b/DestinationGLCanvas.cpp @@ -24,6 +24,16 @@ DestinationGLCanvas::DestinationGLCanvas(QWidget* parent, const QGLWidget * shar { } +Quad& DestinationGLCanvas::getQuad() { + std::tr1::shared_ptr textureMapping = std::tr1::static_pointer_cast(Common::currentMapping); + Q_CHECK_PTR(textureMapping); + + std::tr1::shared_ptr quad = std::tr1::static_pointer_cast(Common::currentMapping->getShape()); + Q_CHECK_PTR(quad); + + return (*quad); +} + void DestinationGLCanvas::doDraw() { // TODO: Ceci est un hack necessaire car tout est en fonction de la width/height de la texture. // Il faut changer ca. diff --git a/DestinationGLCanvas.h b/DestinationGLCanvas.h index 2d25eb2..587a063 100644 --- a/DestinationGLCanvas.h +++ b/DestinationGLCanvas.h @@ -26,20 +26,13 @@ class DestinationGLCanvas: public MapperGLCanvas { -// Q_OBJECT + Q_OBJECT public: DestinationGLCanvas(QWidget* parent = 0, const QGLWidget * shareWidget = 0); +// virtual ~DestinationGLCanvas(); - virtual Quad& getQuad() { - std::tr1::shared_ptr textureMapping = std::tr1::static_pointer_cast(Common::currentMapping); - Q_CHECK_PTR(textureMapping); - - std::tr1::shared_ptr quad = std::tr1::static_pointer_cast(Common::currentMapping->getShape()); - Q_CHECK_PTR(quad); - - return (*quad); - } + virtual Quad& getQuad(); private: virtual void doDraw(); diff --git a/MapperGLCanvas.cpp b/MapperGLCanvas.cpp index 76b0248..47153ed 100644 --- a/MapperGLCanvas.cpp +++ b/MapperGLCanvas.cpp @@ -108,7 +108,10 @@ void MapperGLCanvas::keyPressEvent(QKeyEvent* event) switch (event->key()) { case Qt::Key_Tab: if (event->modifiers() & Qt::ControlModifier) + { Common::nextImage(); + emit quadSwitched(); + } else current = (current + 1) % 4; break; @@ -136,15 +139,15 @@ void MapperGLCanvas::keyPressEvent(QKeyEvent* event) p.y += yMove; quad.setVertex(current, p); - updateGL(); update(); + + emit quadChanged(); } void MapperGLCanvas::paintEvent(QPaintEvent* event) { std::cout << "Paint event" << std::endl; updateGL(); - update(); } void MapperGLCanvas::exitDraw() @@ -153,4 +156,8 @@ void MapperGLCanvas::exitDraw() swapBuffers(); } - +void MapperGLCanvas::updateCanvas() +{ + std::cout << "Update me!" << std::endl; + update(); +} diff --git a/MapperGLCanvas.h b/MapperGLCanvas.h index d8fa584..7142562 100644 --- a/MapperGLCanvas.h +++ b/MapperGLCanvas.h @@ -31,6 +31,8 @@ class MapperGLCanvas: public QGLWidget { + Q_OBJECT + public: MapperGLCanvas(QWidget* parent = 0, const QGLWidget * shareWidget = 0); virtual ~MapperGLCanvas() {} @@ -38,18 +40,25 @@ public: virtual Quad& getQuad() = 0; protected: - virtual void initializeGL(); - virtual void resizeGL(int width, int height); - virtual void paintGL(); + void initializeGL(); + void resizeGL(int width, int height); + void paintGL(); - virtual void keyPressEvent(QKeyEvent* event); - virtual void paintEvent(QPaintEvent* event); + void keyPressEvent(QKeyEvent* event); + void paintEvent(QPaintEvent* event); private: - virtual void draw(); - virtual void enterDraw(); + void draw(); + void enterDraw(); virtual void doDraw() = 0; - virtual void exitDraw(); + void exitDraw(); + +signals: + void quadChanged(); + void quadSwitched(); + +public slots: + void updateCanvas(); }; #endif /* MAPPERGLCANVAS_H_ */ diff --git a/SourceGLCanvas.cpp b/SourceGLCanvas.cpp index c34740c..fea83ce 100644 --- a/SourceGLCanvas.cpp +++ b/SourceGLCanvas.cpp @@ -24,6 +24,16 @@ SourceGLCanvas::SourceGLCanvas(QWidget* parent) { } +Quad& SourceGLCanvas::getQuad() { + std::tr1::shared_ptr textureMapping = std::tr1::static_pointer_cast(Common::currentMapping); + Q_CHECK_PTR(textureMapping); + + std::tr1::shared_ptr inputQuad = std::tr1::static_pointer_cast(textureMapping->getInputShape()); + Q_CHECK_PTR(inputQuad); + + return (*inputQuad); +} + void SourceGLCanvas::doDraw() { // TODO: Ceci est un hack necessaire car tout est en fonction de la width/height de la texture. // Il faut changer ca. diff --git a/SourceGLCanvas.h b/SourceGLCanvas.h index 053efca..b806db6 100644 --- a/SourceGLCanvas.h +++ b/SourceGLCanvas.h @@ -27,18 +27,13 @@ class SourceGLCanvas: public MapperGLCanvas { + Q_OBJECT + public: SourceGLCanvas(QWidget* parent = 0); +// virtual ~SourceGLCanvas() {} - virtual Quad& getQuad() { - std::tr1::shared_ptr textureMapping = std::tr1::static_pointer_cast(Common::currentMapping); - Q_CHECK_PTR(textureMapping); - - std::tr1::shared_ptr inputQuad = std::tr1::static_pointer_cast(textureMapping->getInputShape()); - Q_CHECK_PTR(inputQuad); - - return (*inputQuad); - } + virtual Quad& getQuad(); private: virtual void doDraw(); diff --git a/libremapping.pro b/libremapping.pro index 551edc4..a2df701 100644 --- a/libremapping.pro +++ b/libremapping.pro @@ -1,6 +1,7 @@ CONFIG += qt debug TEMPLATE = app -SOURCES = main.cpp Common.cpp MapperGLCanvas.cpp SourceGLCanvas.cpp DestinationGLCanvas.cpp +HEADERS = Common.h SourceGLCanvas.h DestinationGLCanvas.h MapperGLCanvas.h +SOURCES = main.cpp Common.cpp SourceGLCanvas.cpp DestinationGLCanvas.cpp MapperGLCanvas.cpp QT += gui opengl LIBS += -lSOIL -lglut diff --git a/main.cpp b/main.cpp index 72369bd..31ab41d 100644 --- a/main.cpp +++ b/main.cpp @@ -24,6 +24,12 @@ int main(int argc, char *argv[]) SourceGLCanvas sourceCanvas; DestinationGLCanvas destinationCanvas(0, &sourceCanvas); + QObject::connect(&sourceCanvas, SIGNAL(quadChanged()), + &destinationCanvas, SLOT(updateCanvas())); + + QObject::connect(&destinationCanvas, SIGNAL(quadSwitched()), + &sourceCanvas, SLOT(updateCanvas())); + Common::initializeLibremapper(320, 480); QSplitter splitter(Qt::Horizontal);