mirror of
https://github.com/mapmapteam/mapmap.git
synced 2026-06-16 12:33:19 +02:00
- Put all mappings and paints in a single MappingManager class
- Basic compiling / running program (no quads for now)
This commit is contained in:
+58
-57
@@ -18,78 +18,79 @@
|
||||
*/
|
||||
|
||||
#include "DestinationGLCanvas.h"
|
||||
#include "MainWindow.h"
|
||||
|
||||
DestinationGLCanvas::DestinationGLCanvas(QWidget* parent, const QGLWidget * shareWidget)
|
||||
: MapperGLCanvas(parent, shareWidget)
|
||||
{
|
||||
}
|
||||
|
||||
Quad& DestinationGLCanvas::getQuad()
|
||||
{
|
||||
std::tr1::shared_ptr<TextureMapping> textureMapping = std::tr1::static_pointer_cast<TextureMapping>(Common::currentMapping);
|
||||
Q_CHECK_PTR(textureMapping);
|
||||
|
||||
std::tr1::shared_ptr<Quad> quad = std::tr1::static_pointer_cast<Quad>(Common::currentMapping->getShape());
|
||||
Q_CHECK_PTR(quad);
|
||||
|
||||
return (*quad);
|
||||
}
|
||||
//Quad& DestinationGLCanvas::getQuad()
|
||||
//{
|
||||
// std::tr1::shared_ptr<TextureMapping> textureMapping = std::tr1::static_pointer_cast<TextureMapping>(Common::currentMapping);
|
||||
// Q_CHECK_PTR(textureMapping);
|
||||
//
|
||||
// std::tr1::shared_ptr<Quad> quad = std::tr1::static_pointer_cast<Quad>(Common::currentMapping->getShape());
|
||||
// Q_CHECK_PTR(quad);
|
||||
//
|
||||
// return (*quad);
|
||||
//}
|
||||
|
||||
void DestinationGLCanvas::doDraw()
|
||||
{
|
||||
// No sources = nothing to do.
|
||||
if (Common::nImages() == 0)
|
||||
return;
|
||||
// // No sources = nothing to do.
|
||||
// if (Common::nImages() == 0)
|
||||
// return;
|
||||
//
|
||||
// // TODO: Ceci est un hack necessaire car tout est en fonction de la width/height de la texture.
|
||||
// // Il faut changer ca.
|
||||
// std::tr1::shared_ptr<TextureMapping> textureMapping = std::tr1::static_pointer_cast<TextureMapping>(Common::currentMapping);
|
||||
// Q_CHECK_PTR(textureMapping);
|
||||
//
|
||||
// std::tr1::shared_ptr<Texture> texture = std::tr1::static_pointer_cast<Texture>(textureMapping->getPaint());
|
||||
// Q_CHECK_PTR(texture);
|
||||
//
|
||||
// for (int i=0; i < Common::nImages(); i++)
|
||||
// {
|
||||
// std::tr1::shared_ptr<Texture> tex = std::tr1::static_pointer_cast<Texture>(Common::mappings[i]->getPaint());
|
||||
// Q_CHECK_PTR(tex);
|
||||
//
|
||||
// // FIXME: maybe the texture id is actually 0 and it's ok, no?
|
||||
// // we should use a boolean is_texture_loaded, or so
|
||||
// if (tex->getTextureId() == 0)
|
||||
// {
|
||||
// tex->loadTexture();
|
||||
// }
|
||||
// }
|
||||
|
||||
// TODO: Ceci est un hack necessaire car tout est en fonction de la width/height de la texture.
|
||||
// Il faut changer ca.
|
||||
std::tr1::shared_ptr<TextureMapping> textureMapping = std::tr1::static_pointer_cast<TextureMapping>(Common::currentMapping);
|
||||
Q_CHECK_PTR(textureMapping);
|
||||
|
||||
std::tr1::shared_ptr<Texture> texture = std::tr1::static_pointer_cast<Texture>(textureMapping->getPaint());
|
||||
Q_CHECK_PTR(texture);
|
||||
|
||||
for (int i=0; i < Common::nImages(); i++)
|
||||
{
|
||||
std::tr1::shared_ptr<Texture> tex = std::tr1::static_pointer_cast<Texture>(Common::mappings[i]->getPaint());
|
||||
Q_CHECK_PTR(tex);
|
||||
|
||||
// FIXME: maybe the texture id is actually 0 and it's ok, no?
|
||||
// we should use a boolean is_texture_loaded, or so
|
||||
if (tex->getTextureId() == 0)
|
||||
{
|
||||
tex->loadTexture();
|
||||
}
|
||||
}
|
||||
|
||||
// Now, draw
|
||||
// DRAW THE TEXTURE
|
||||
glPushMatrix();
|
||||
|
||||
for (int i=0; i < Common::nImages(); i++)
|
||||
MappingManager& mappingManager = MainWindow::getInstance().getMappingManager();
|
||||
for (int i=0; i<mappingManager.nMappings(); i++)
|
||||
{
|
||||
// Draw the mappings.
|
||||
Common::mappers[i]->draw();
|
||||
QuadTextureMapper mapper((TextureMapping*)mappingManager.getMapping(i).get());
|
||||
mapper.draw();
|
||||
}
|
||||
|
||||
// Draw the quad.
|
||||
Quad& quad = getQuad();
|
||||
|
||||
glColor4f(1.0, 0.0, 0.0, 1.0);
|
||||
|
||||
// Destination quad.
|
||||
// Source quad.
|
||||
glLineWidth(5);
|
||||
glBegin (GL_LINE_STRIP);
|
||||
{
|
||||
for (int i=0; i<5; i++)
|
||||
{
|
||||
glVertex2f(
|
||||
quad.getVertex(i % 4).x,
|
||||
quad.getVertex(i % 4).y);
|
||||
}
|
||||
}
|
||||
glEnd ();
|
||||
//
|
||||
// // Draw the quad.
|
||||
// Quad& quad = getQuad();
|
||||
//
|
||||
// glColor4f(1.0, 0.0, 0.0, 1.0);
|
||||
//
|
||||
// // Destination quad.
|
||||
// // Source quad.
|
||||
// glLineWidth(5);
|
||||
// glBegin (GL_LINE_STRIP);
|
||||
// {
|
||||
// for (int i=0; i<5; i++)
|
||||
// {
|
||||
// glVertex2f(
|
||||
// quad.getVertex(i % 4).x,
|
||||
// quad.getVertex(i % 4).y);
|
||||
// }
|
||||
// }
|
||||
// glEnd ();
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
#define DESTINATIONGLCANVAS_H_
|
||||
|
||||
#include "MapperGLCanvas.h"
|
||||
#include "MappingManager.h"
|
||||
|
||||
#include "Mapper.h"
|
||||
|
||||
class DestinationGLCanvas: public MapperGLCanvas
|
||||
{
|
||||
@@ -30,7 +33,7 @@ public:
|
||||
DestinationGLCanvas(QWidget* parent = 0, const QGLWidget * shareWidget = 0);
|
||||
// virtual ~DestinationGLCanvas();
|
||||
|
||||
virtual Quad& getQuad();
|
||||
// virtual Quad& getQuad();
|
||||
|
||||
private:
|
||||
virtual void doDraw();
|
||||
|
||||
+44
-7
@@ -21,6 +21,9 @@
|
||||
|
||||
MainWindow::MainWindow()
|
||||
{
|
||||
mappingManager = new MappingManager;
|
||||
currentPaintId = -1;
|
||||
|
||||
createLayout();
|
||||
|
||||
createActions();
|
||||
@@ -35,6 +38,17 @@ MainWindow::MainWindow()
|
||||
setCurrentFile("");
|
||||
}
|
||||
|
||||
MainWindow& MainWindow::getInstance()
|
||||
{
|
||||
static MainWindow instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete mappingManager;
|
||||
}
|
||||
|
||||
void MainWindow::handleSourceItemSelectionChanged()
|
||||
{
|
||||
std::cout << "selection changed" << std::endl;
|
||||
@@ -121,6 +135,11 @@ void MainWindow::import()
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::addQuad()
|
||||
{
|
||||
qDebug() << "add quad" << endl;
|
||||
}
|
||||
|
||||
void MainWindow::about()
|
||||
{
|
||||
QMessageBox::about(this, tr("About Libremapping"),
|
||||
@@ -150,14 +169,18 @@ void MainWindow::createLayout()
|
||||
sourceList->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
sourceList->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
||||
|
||||
shapeList = new QListWidget;
|
||||
shapeList->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
shapeList->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
||||
|
||||
sourceCanvas = new SourceGLCanvas;
|
||||
destinationCanvas = new DestinationGLCanvas(0, sourceCanvas);
|
||||
|
||||
connect(sourceCanvas, SIGNAL(quadChanged()), destinationCanvas,
|
||||
SLOT(updateCanvas()));
|
||||
connect(sourceCanvas, SIGNAL(quadChanged()),
|
||||
destinationCanvas, SLOT(updateCanvas()));
|
||||
|
||||
connect(destinationCanvas, SIGNAL(quadSwitched()), sourceCanvas,
|
||||
SLOT(updateCanvas()));
|
||||
connect(destinationCanvas, SIGNAL(imageChanged()),
|
||||
sourceCanvas, SLOT(updateCanvas()));
|
||||
|
||||
sourceCanvas->setFocusPolicy(Qt::ClickFocus);
|
||||
destinationCanvas->setFocusPolicy(Qt::ClickFocus);
|
||||
@@ -174,7 +197,11 @@ void MainWindow::createLayout()
|
||||
canvasSplitter->addWidget(sourceCanvas);
|
||||
canvasSplitter->addWidget(destinationCanvas);
|
||||
|
||||
mainSplitter->addWidget(sourceList);
|
||||
sourceSplitter = new QSplitter(Qt::Vertical);
|
||||
sourceSplitter->addWidget(sourceList);
|
||||
sourceSplitter->addWidget(shapeList);
|
||||
|
||||
mainSplitter->addWidget(sourceSplitter);
|
||||
mainSplitter->addWidget(canvasSplitter);
|
||||
mainSplitter->setStretchFactor(1, 1); // Upon resizing window, give the extra stretch expansion to canvasSplitter.
|
||||
|
||||
@@ -268,6 +295,11 @@ void MainWindow::createActions()
|
||||
aboutAction = new QAction(tr("&About"), this);
|
||||
aboutAction->setStatusTip(tr("Show the application's About box"));
|
||||
connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
|
||||
|
||||
addQuadAction = new QAction(tr("&Add quad"), this);
|
||||
addQuadAction->setIcon(QIcon(":/images/draw-rectangle-2.png"));
|
||||
addQuadAction->setStatusTip(tr("Add quad"));
|
||||
connect(addQuadAction, SIGNAL(triggered()), this, SLOT(addQuad()));
|
||||
}
|
||||
|
||||
void MainWindow::createMenus()
|
||||
@@ -326,6 +358,8 @@ void MainWindow::createToolBars()
|
||||
fileToolBar->addAction(newAction);
|
||||
fileToolBar->addAction(openAction);
|
||||
fileToolBar->addAction(saveAction);
|
||||
fileToolBar->addSeparator();
|
||||
fileToolBar->addAction(addQuadAction);
|
||||
|
||||
// editToolBar = addToolBar(tr("&Edit"));
|
||||
// editToolBar->addAction(cutAction);
|
||||
@@ -447,10 +481,13 @@ bool MainWindow::importFile(const QString &fileName)
|
||||
}
|
||||
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
Common::addImage(fileName, sourceCanvas->width(), sourceCanvas->height());
|
||||
|
||||
// Add image to model.
|
||||
int imageId = mappingManager->addImage(fileName, sourceCanvas->width(), sourceCanvas->height());
|
||||
|
||||
// Add image to sourceList widget.
|
||||
QListWidgetItem* item = new QListWidgetItem(strippedName(fileName));
|
||||
item->setData(Qt::UserRole, Common::nImages()-1);
|
||||
item->setData(Qt::UserRole, imageId); // TODO: could possibly be replaced by a Paint pointer
|
||||
item->setIcon(QIcon(fileName));
|
||||
item->setSizeHint(QSize(item->sizeHint().width(), MainWindow::SOURCE_LIST_ITEM_HEIGHT));
|
||||
sourceList->addItem(item);
|
||||
|
||||
+34
-3
@@ -22,17 +22,25 @@
|
||||
|
||||
#include <QtGui>
|
||||
|
||||
#include "Common.h"
|
||||
|
||||
#include "DestinationGLCanvas.h"
|
||||
#include "SourceGLCanvas.h"
|
||||
#include "DestinationGLCanvas.h"
|
||||
|
||||
#include "MappingManager.h"
|
||||
|
||||
#define LIBREMAPPING_VERSION "0.1"
|
||||
|
||||
class MainWindow: public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
~MainWindow();
|
||||
static MainWindow& getInstance();
|
||||
|
||||
private:
|
||||
MainWindow();
|
||||
MainWindow(MainWindow const&);
|
||||
void operator=(MainWindow const&);
|
||||
|
||||
protected:
|
||||
// Events.
|
||||
@@ -47,7 +55,9 @@ private slots:
|
||||
void import();
|
||||
void about();
|
||||
void updateStatusBar();
|
||||
|
||||
void handleSourceItemSelectionChanged();
|
||||
void addQuad();
|
||||
|
||||
void windowModified();
|
||||
|
||||
@@ -95,14 +105,35 @@ private:
|
||||
// QAction *deleteAction;
|
||||
QAction *aboutAction;
|
||||
|
||||
QAction *addQuadAction;
|
||||
|
||||
QListWidget* sourceList;
|
||||
QListWidget* shapeList;
|
||||
|
||||
SourceGLCanvas* sourceCanvas;
|
||||
DestinationGLCanvas* destinationCanvas;
|
||||
|
||||
QSplitter* mainSplitter;
|
||||
QSplitter* sourceSplitter;
|
||||
QSplitter* canvasSplitter;
|
||||
|
||||
private:
|
||||
// Model.
|
||||
MappingManager* mappingManager;
|
||||
|
||||
// View.
|
||||
int currentPaintId;
|
||||
|
||||
public:
|
||||
MappingManager& getMappingManager() { return *mappingManager; }
|
||||
int getCurrentPaintId() const { return currentPaintId; }
|
||||
void setPaint(int id)
|
||||
{
|
||||
currentPaintId = id;
|
||||
}
|
||||
|
||||
public:
|
||||
// Constants.
|
||||
static const int DEFAULT_WIDTH = 1600;
|
||||
static const int DEFAULT_HEIGHT = 800;
|
||||
static const int SOURCE_LIST_ITEM_HEIGHT = 40;
|
||||
|
||||
@@ -23,67 +23,19 @@
|
||||
#define MAPPER_H_
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
#include <tr1/memory>
|
||||
#include <GL/gl.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "Shape.h"
|
||||
#include "Paint.h"
|
||||
#include "Mapping.h"
|
||||
|
||||
#include "Util.h"
|
||||
|
||||
/**
|
||||
* One object in the scene that is a shape with some paint on it.
|
||||
*
|
||||
* A Mapping is an area of the rendering window that is drawn with
|
||||
* either some texture, or any special effect that might animate a
|
||||
* polygon or a line.
|
||||
*/
|
||||
class Mapping
|
||||
{
|
||||
protected:
|
||||
Paint::ptr _paint;
|
||||
Shape::ptr _shape;
|
||||
|
||||
public:
|
||||
typedef std::tr1::shared_ptr<Mapping> ptr;
|
||||
Mapping(Paint* paint, Shape* shape)
|
||||
: _paint(paint), _shape(shape)
|
||||
{}
|
||||
|
||||
virtual void build() {
|
||||
_paint->build();
|
||||
_shape->build();
|
||||
}
|
||||
|
||||
public:
|
||||
Paint::ptr getPaint() const { return _paint; }
|
||||
Shape::ptr getShape() const { return _shape; }
|
||||
};
|
||||
|
||||
/**
|
||||
* Object whose paint is an image texture.
|
||||
*/
|
||||
class TextureMapping : public Mapping
|
||||
{
|
||||
private:
|
||||
Shape::ptr _inputShape;
|
||||
|
||||
public:
|
||||
TextureMapping(Paint* paint,
|
||||
Shape* shape,
|
||||
Shape* inputShape)
|
||||
: Mapping(paint, shape),
|
||||
_inputShape(inputShape)
|
||||
{}
|
||||
|
||||
virtual void build() {
|
||||
Mapping::build();
|
||||
_inputShape->build();
|
||||
}
|
||||
public:
|
||||
Shape::ptr getInputShape() const { return _inputShape; }
|
||||
};
|
||||
|
||||
/**
|
||||
* A way to draw on some kind of shape.
|
||||
*
|
||||
|
||||
+87
-75
@@ -19,6 +19,8 @@
|
||||
|
||||
#include "MapperGLCanvas.h"
|
||||
|
||||
#include "MainWindow.h"
|
||||
|
||||
MapperGLCanvas::MapperGLCanvas(QWidget* parent, const QGLWidget * shareWidget)
|
||||
: QGLWidget(parent, shareWidget), _mousepressed(false)
|
||||
{
|
||||
@@ -95,26 +97,26 @@ void MapperGLCanvas::enterDraw()
|
||||
|
||||
void MapperGLCanvas::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
int i, dist, maxdist, mindist;
|
||||
int xmouse = event->x();
|
||||
int ymouse = event->y();
|
||||
maxdist = mindist = 50;
|
||||
if (event->buttons() & Qt::LeftButton)
|
||||
{
|
||||
// std::cout << "Left Mouse key pressed" << std::endl;
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
Quad& quad = getQuad();
|
||||
Point p = quad.getVertex(i);
|
||||
dist = abs(xmouse - p.x) + abs(ymouse - p.y);
|
||||
if (dist < maxdist && dist < mindist)
|
||||
{
|
||||
quad.setActiveVertex(i);
|
||||
mindist = dist;
|
||||
}
|
||||
}
|
||||
_mousepressed = true;
|
||||
}
|
||||
// int i, dist, maxdist, mindist;
|
||||
// int xmouse = event->x();
|
||||
// int ymouse = event->y();
|
||||
// maxdist = mindist = 50;
|
||||
// if (event->buttons() & Qt::LeftButton)
|
||||
// {
|
||||
// // std::cout << "Left Mouse key pressed" << std::endl;
|
||||
// for (i = 0; i < 4; i++)
|
||||
// {
|
||||
// Quad& quad = getQuad();
|
||||
// Point p = quad.getVertex(i);
|
||||
// dist = abs(xmouse - p.x) + abs(ymouse - p.y);
|
||||
// if (dist < maxdist && dist < mindist)
|
||||
// {
|
||||
// quad.setActiveVertex(i);
|
||||
// mindist = dist;
|
||||
// }
|
||||
// }
|
||||
// _mousepressed = true;
|
||||
// }
|
||||
}
|
||||
|
||||
void MapperGLCanvas::mouseReleaseEvent(QMouseEvent* event)
|
||||
@@ -125,63 +127,63 @@ void MapperGLCanvas::mouseReleaseEvent(QMouseEvent* event)
|
||||
|
||||
void MapperGLCanvas::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
|
||||
if (_mousepressed)
|
||||
{
|
||||
// std::cout << "Move event " << std::endl;
|
||||
Quad& quad = getQuad();
|
||||
Point p = quad.getVertex(quad.getActiveVertex());
|
||||
p.x = event->x();
|
||||
p.y = event->y();
|
||||
|
||||
quad.setVertex(quad.getActiveVertex(), p);
|
||||
update();
|
||||
emit quadChanged();
|
||||
}
|
||||
//
|
||||
// if (_mousepressed)
|
||||
// {
|
||||
// // std::cout << "Move event " << std::endl;
|
||||
// Quad& quad = getQuad();
|
||||
// Point p = quad.getVertex(quad.getActiveVertex());
|
||||
// p.x = event->x();
|
||||
// p.y = event->y();
|
||||
//
|
||||
// quad.setVertex(quad.getActiveVertex(), p);
|
||||
// update();
|
||||
// emit quadChanged();
|
||||
// }
|
||||
}
|
||||
|
||||
void MapperGLCanvas::keyPressEvent(QKeyEvent* event)
|
||||
{
|
||||
std::cout << "Key pressed" << std::endl;
|
||||
int xMove = 0;
|
||||
int yMove = 0;
|
||||
switch (event->key()) {
|
||||
case Qt::Key_Tab:
|
||||
if (event->modifiers() & Qt::ControlModifier)
|
||||
switchImage( (Common::getCurrentSourceId() + 1) % Common::nImages());
|
||||
else
|
||||
{
|
||||
Quad& quad = getQuad();
|
||||
quad.setActiveVertex((quad.getActiveVertex() + 1) % 4);
|
||||
}
|
||||
break;
|
||||
case Qt::Key_Up:
|
||||
yMove = -1;
|
||||
break;
|
||||
case Qt::Key_Down:
|
||||
yMove = +1;
|
||||
break;
|
||||
case Qt::Key_Left:
|
||||
xMove = -1;
|
||||
break;
|
||||
case Qt::Key_Right:
|
||||
xMove = +1;
|
||||
break;
|
||||
default:
|
||||
std::cerr << "Unhandled key" << std::endl;
|
||||
QWidget::keyPressEvent(event);
|
||||
break;
|
||||
}
|
||||
|
||||
Quad& quad = getQuad();
|
||||
Point p = quad.getVertex(quad.getActiveVertex());
|
||||
p.x += xMove;
|
||||
p.y += yMove;
|
||||
quad.setVertex(quad.getActiveVertex(), p);
|
||||
|
||||
update();
|
||||
|
||||
emit quadChanged();
|
||||
// std::cout << "Key pressed" << std::endl;
|
||||
// int xMove = 0;
|
||||
// int yMove = 0;
|
||||
// switch (event->key()) {
|
||||
// case Qt::Key_Tab:
|
||||
// if (event->modifiers() & Qt::ControlModifier)
|
||||
// switchImage( (Common::getCurrentSourceId() + 1) % Common::nImages());
|
||||
// else
|
||||
// {
|
||||
// Quad& quad = getQuad();
|
||||
// quad.setActiveVertex((quad.getActiveVertex() + 1) % 4);
|
||||
// }
|
||||
// break;
|
||||
// case Qt::Key_Up:
|
||||
// yMove = -1;
|
||||
// break;
|
||||
// case Qt::Key_Down:
|
||||
// yMove = +1;
|
||||
// break;
|
||||
// case Qt::Key_Left:
|
||||
// xMove = -1;
|
||||
// break;
|
||||
// case Qt::Key_Right:
|
||||
// xMove = +1;
|
||||
// break;
|
||||
// default:
|
||||
// std::cerr << "Unhandled key" << std::endl;
|
||||
// QWidget::keyPressEvent(event);
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// Quad& quad = getQuad();
|
||||
// Point p = quad.getVertex(quad.getActiveVertex());
|
||||
// p.x += xMove;
|
||||
// p.y += yMove;
|
||||
// quad.setVertex(quad.getActiveVertex(), p);
|
||||
//
|
||||
// update();
|
||||
//
|
||||
// emit quadChanged();
|
||||
}
|
||||
|
||||
void MapperGLCanvas::paintEvent(QPaintEvent* /* event */)
|
||||
@@ -192,10 +194,20 @@ void MapperGLCanvas::paintEvent(QPaintEvent* /* event */)
|
||||
|
||||
void MapperGLCanvas::switchImage(int imageId)
|
||||
{
|
||||
Common::switchImage(imageId);
|
||||
emit quadSwitched();
|
||||
MainWindow::getInstance().setPaint(imageId);
|
||||
emit imageChanged();
|
||||
}
|
||||
|
||||
//QSize MapperGLCanvas::sizeHint() const
|
||||
//{
|
||||
// return QSize( 640, 480 );
|
||||
//}
|
||||
//
|
||||
//QSize MapperGLCanvas::minimumSizeHint() const
|
||||
//{
|
||||
// return QSize( 320, 240 );
|
||||
//}
|
||||
|
||||
void MapperGLCanvas::exitDraw()
|
||||
{
|
||||
glFlush();
|
||||
|
||||
+7
-6
@@ -26,9 +26,11 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "Common.h"
|
||||
//#include "Common.h"
|
||||
#include "Shape.h"
|
||||
|
||||
//#include "MainWindow.h"
|
||||
|
||||
/**
|
||||
* Qt GUI widget that draws a mapper, which is a shape with some paint.
|
||||
*/
|
||||
@@ -37,12 +39,12 @@ class MapperGLCanvas: public QGLWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MapperGLCanvas(QWidget* parent = 0, const QGLWidget * shareWidget = 0);
|
||||
MapperGLCanvas(QWidget* parent = 0, const QGLWidget* shareWidget = 0);
|
||||
virtual ~MapperGLCanvas() {}
|
||||
|
||||
virtual Quad& getQuad() = 0;
|
||||
|
||||
void switchImage(int imageId);
|
||||
// QSize sizeHint() const;
|
||||
// QSize minimumSizeHint() const;
|
||||
|
||||
protected:
|
||||
void initializeGL();
|
||||
@@ -55,7 +57,6 @@ protected:
|
||||
void mouseReleaseEvent(QMouseEvent* event);
|
||||
void paintEvent(QPaintEvent* event);
|
||||
|
||||
|
||||
private:
|
||||
void draw();
|
||||
void enterDraw();
|
||||
@@ -65,7 +66,7 @@ private:
|
||||
|
||||
signals:
|
||||
void quadChanged();
|
||||
void quadSwitched();
|
||||
void imageChanged();
|
||||
|
||||
public slots:
|
||||
void updateCanvas();
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Mapping.h
|
||||
*
|
||||
* (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MAPPING_H_
|
||||
#define MAPPING_H_
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <tr1/memory>
|
||||
|
||||
#include "Shape.h"
|
||||
#include "Paint.h"
|
||||
|
||||
/**
|
||||
* One object in the scene that is a shape with some paint on it.
|
||||
*
|
||||
* A Mapping is an area of the rendering window that is drawn with
|
||||
* either some texture, or any special effect that might animate a
|
||||
* polygon or a line.
|
||||
*/
|
||||
class Mapping
|
||||
{
|
||||
protected:
|
||||
Paint::ptr _paint;
|
||||
Shape::ptr _shape;
|
||||
|
||||
public:
|
||||
typedef std::tr1::shared_ptr<Mapping> ptr;
|
||||
Mapping(Paint* paint, Shape* shape)
|
||||
: _paint(paint), _shape(shape)
|
||||
{}
|
||||
virtual ~Mapping() {}
|
||||
|
||||
virtual void build() {
|
||||
_paint->build();
|
||||
_shape->build();
|
||||
}
|
||||
|
||||
public:
|
||||
Paint::ptr getPaint() const { return _paint; }
|
||||
Shape::ptr getShape() const { return _shape; }
|
||||
};
|
||||
|
||||
/**
|
||||
* Object whose paint is an image texture. In the case of a texture mapping we require
|
||||
* an additional input shape to specify the area on the image where we pick the pixels.
|
||||
*/
|
||||
class TextureMapping : public Mapping
|
||||
{
|
||||
private:
|
||||
Shape::ptr _inputShape;
|
||||
|
||||
public:
|
||||
TextureMapping(Paint* paint,
|
||||
Shape* shape,
|
||||
Shape* inputShape)
|
||||
: Mapping(paint, shape),
|
||||
_inputShape(inputShape)
|
||||
{}
|
||||
|
||||
virtual void build() {
|
||||
Mapping::build();
|
||||
_inputShape->build();
|
||||
}
|
||||
public:
|
||||
Shape::ptr getInputShape() const { return _inputShape; }
|
||||
};
|
||||
|
||||
#endif /* MAPPING_H_ */
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* MappingManager.cpp
|
||||
*
|
||||
* (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "MappingManager.h"
|
||||
|
||||
MappingManager::MappingManager()
|
||||
{
|
||||
// TODO Auto-generated constructor stub
|
||||
|
||||
}
|
||||
|
||||
std::vector<Mapping::ptr> MappingManager::getPaintMappings(const Paint::ptr paint) const
|
||||
{
|
||||
std::vector<Mapping::ptr> paintMappings;
|
||||
for (std::vector<Mapping::ptr>::const_iterator it = mappings.begin(); it != mappings.end(); ++it)
|
||||
{
|
||||
if ((*it)->getPaint() == paint)
|
||||
paintMappings.push_back(*it);
|
||||
}
|
||||
return paintMappings;
|
||||
}
|
||||
|
||||
std::vector<Mapping::ptr> MappingManager::getPaintMappings(int i) const
|
||||
{
|
||||
return getPaintMappings( paints[i] );
|
||||
}
|
||||
|
||||
int MappingManager::addPaint(Paint::ptr paint)
|
||||
{
|
||||
paints.push_back(paint);
|
||||
return paints.size()-1;
|
||||
}
|
||||
|
||||
int MappingManager::addImage(const QString imagePath, int frameWidth, int frameHeight)
|
||||
{
|
||||
Image* img = new Image(imagePath);
|
||||
|
||||
img->setPosition( (frameWidth - img->getWidth() ) / 2.0f,
|
||||
(frameHeight - img->getHeight()) / 2.0f );
|
||||
|
||||
return addPaint(Paint::ptr(img));
|
||||
}
|
||||
|
||||
//bool MappingManager::removePaint(Paint::ptr paint)
|
||||
//{
|
||||
//
|
||||
//}
|
||||
|
||||
int MappingManager::addMapping(Mapping::ptr mapping)
|
||||
{
|
||||
if (std::find(paints.begin(), paints.end(), mapping->getPaint()) != paints.end())
|
||||
{
|
||||
mappings.push_back(mapping);
|
||||
return mappings.size()-1;
|
||||
}
|
||||
else
|
||||
return (-1);
|
||||
}
|
||||
|
||||
//bool MappingManager::removeMapping(Mapping::ptr mapping)
|
||||
//{
|
||||
//}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* MappingManager.h
|
||||
*
|
||||
* (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MAPPINGMANAGER_H_
|
||||
#define MAPPINGMANAGER_H_
|
||||
|
||||
#include "Paint.h"
|
||||
#include "Mapping.h"
|
||||
|
||||
/**
|
||||
* This is a container class for all the paints and mappings. It is on the model
|
||||
* side.
|
||||
*/
|
||||
class MappingManager
|
||||
{
|
||||
public:
|
||||
MappingManager();
|
||||
|
||||
private:
|
||||
// Model.
|
||||
std::vector<Paint::ptr> paints;
|
||||
std::vector<Mapping::ptr> mappings;
|
||||
|
||||
public:
|
||||
/// Returns the list of mappings associated with given paint.
|
||||
std::vector<Mapping::ptr> getPaintMappings(const Paint::ptr paint) const;
|
||||
std::vector<Mapping::ptr> getPaintMappings(int id) const;
|
||||
|
||||
int addPaint(Paint::ptr paint);
|
||||
// bool removePaint(Paint::ptr paint);
|
||||
int nPaints() const { return paints.size(); }
|
||||
Paint::ptr getPaint(int i) { return paints[i]; }
|
||||
|
||||
int addImage(const QString imagePath, int frameWidth, int frameHeight);
|
||||
|
||||
int addMapping(Mapping::ptr mapping);
|
||||
// bool removeMapping(Mapping::ptr mapping);
|
||||
int nMappings() const { return mappings.size(); }
|
||||
Mapping::ptr getMapping(int i) { return mappings[i]; }
|
||||
};
|
||||
|
||||
#endif /* MAPPINGMANAGER_H_ */
|
||||
@@ -51,6 +51,8 @@ public:
|
||||
|
||||
virtual void build() {}
|
||||
|
||||
int nVertices() const { return vertices.size(); }
|
||||
|
||||
const Point& getVertex(int i)
|
||||
{
|
||||
return vertices[i];
|
||||
|
||||
+47
-35
@@ -19,43 +19,44 @@
|
||||
|
||||
#include "SourceGLCanvas.h"
|
||||
|
||||
#include "MainWindow.h"
|
||||
|
||||
|
||||
SourceGLCanvas::SourceGLCanvas(QWidget* parent)
|
||||
: MapperGLCanvas(parent)
|
||||
{
|
||||
}
|
||||
|
||||
Quad& SourceGLCanvas::getQuad()
|
||||
{
|
||||
std::tr1::shared_ptr<TextureMapping> textureMapping = std::tr1::static_pointer_cast<TextureMapping>(Common::currentMapping);
|
||||
Q_CHECK_PTR(textureMapping);
|
||||
|
||||
std::tr1::shared_ptr<Quad> inputQuad = std::tr1::static_pointer_cast<Quad>(textureMapping->getInputShape());
|
||||
Q_CHECK_PTR(inputQuad);
|
||||
|
||||
return (*inputQuad);
|
||||
}
|
||||
//Quad& SourceGLCanvas::getQuad()
|
||||
//{
|
||||
// std::tr1::shared_ptr<TextureMapping> textureMapping = std::tr1::static_pointer_cast<TextureMapping>(Common::currentMapping);
|
||||
// Q_CHECK_PTR(textureMapping);
|
||||
//
|
||||
// std::tr1::shared_ptr<Quad> inputQuad = std::tr1::static_pointer_cast<Quad>(textureMapping->getInputShape());
|
||||
// Q_CHECK_PTR(inputQuad);
|
||||
//
|
||||
// return (*inputQuad);
|
||||
//}
|
||||
|
||||
void SourceGLCanvas::doDraw()
|
||||
{
|
||||
// No sources = nothing to do.
|
||||
if (Common::nImages() == 0)
|
||||
int paintId = MainWindow::getInstance().getCurrentPaintId();
|
||||
|
||||
if (paintId < 0)
|
||||
return;
|
||||
|
||||
// TODO: Ceci est un hack necessaire car tout est en fonction de la width/height de la texture.
|
||||
// Il faut changer ca.
|
||||
std::tr1::shared_ptr<TextureMapping> textureMapping = std::tr1::static_pointer_cast<TextureMapping>(Common::currentMapping);
|
||||
Q_CHECK_PTR(textureMapping);
|
||||
|
||||
std::tr1::shared_ptr<Texture> texture = std::tr1::static_pointer_cast<Texture>(textureMapping->getPaint());
|
||||
// Retrieve paint (as texture) and draw it.
|
||||
Paint::ptr paint = MainWindow::getInstance().getMappingManager().getPaint(paintId);
|
||||
Q_CHECK_PTR(paint);
|
||||
std::tr1::shared_ptr<Texture> texture = std::tr1::static_pointer_cast<Texture>(paint);
|
||||
Q_CHECK_PTR(texture);
|
||||
|
||||
std::cout << width() << " " << height() << std::endl;
|
||||
// Load texture if needed.
|
||||
if (texture->getTextureId() == 0) {
|
||||
texture->loadTexture();
|
||||
}
|
||||
|
||||
// Now, draw
|
||||
// DRAW THE TEXTURE
|
||||
// Draw the texture.
|
||||
glPushMatrix();
|
||||
|
||||
// Enable blending mode (for alphas).
|
||||
@@ -86,7 +87,7 @@ void SourceGLCanvas::doDraw()
|
||||
// float textureHalfWidth = (float) texture->getWidth() / 2.0f;
|
||||
// float textureHalfHeight = (float) texture->getHeight() / 2.0f;
|
||||
|
||||
//printf("SRC: %f %f %f %f\n", centerX, centerY, textureHalfWidth, textureHalfHeight);
|
||||
|
||||
glColor4f (1.0f, 1.0f, 1.0f, 1.0f);
|
||||
// FIXME: Does this draw the quad counterclockwise?
|
||||
glBegin (GL_QUADS);
|
||||
@@ -107,24 +108,35 @@ void SourceGLCanvas::doDraw()
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
// Draw the quad.
|
||||
Quad& quad = getQuad();
|
||||
// Retrieve all mappings associated to paint.
|
||||
std::vector<Mapping::ptr> mappings = MainWindow::getInstance().getMappingManager().getPaintMappings(paintId);
|
||||
|
||||
glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
// Source quad.
|
||||
glLineWidth(5);
|
||||
glBegin (GL_LINE_STRIP);
|
||||
for (std::vector<Mapping::ptr>::iterator it = mappings.begin(); it != mappings.end(); ++it)
|
||||
{
|
||||
for (int i = 0; i < 5; i++)
|
||||
// TODO: Ceci est un hack necessaire car tout est en fonction de la width/height de la texture.
|
||||
// Il faut changer ca.
|
||||
std::tr1::shared_ptr<TextureMapping> textureMapping = std::tr1::static_pointer_cast<TextureMapping>(*it);
|
||||
Q_CHECK_PTR(textureMapping);
|
||||
|
||||
std::tr1::shared_ptr<Shape> inputShape = std::tr1::static_pointer_cast<Quad>(textureMapping->getInputShape());
|
||||
Q_CHECK_PTR(inputShape);
|
||||
|
||||
glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
// Source shape.
|
||||
glLineWidth(5);
|
||||
glBegin (GL_LINE_STRIP);
|
||||
{
|
||||
glVertex2f(
|
||||
quad.getVertex(i % 4).x,
|
||||
quad.getVertex(i % 4).y
|
||||
);
|
||||
for (int i = 0; i < inputShape->nVertices()+1; i++)
|
||||
{
|
||||
glVertex2f(
|
||||
inputShape->getVertex(i % inputShape->nVertices()).x,
|
||||
inputShape->getVertex(i % inputShape->nVertices()).y
|
||||
);
|
||||
}
|
||||
}
|
||||
glEnd ();
|
||||
}
|
||||
glEnd ();
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ public:
|
||||
SourceGLCanvas(QWidget* parent = 0);
|
||||
// virtual ~SourceGLCanvas() {}
|
||||
|
||||
virtual Quad& getQuad();
|
||||
// virtual Quad& getQuad();
|
||||
|
||||
private:
|
||||
virtual void doDraw();
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
CONFIG += qt debug
|
||||
TEMPLATE = app
|
||||
HEADERS = MainWindow.h Common.h Util.h SourceGLCanvas.h DestinationGLCanvas.h MapperGLCanvas.h Mapper.h Shape.h Paint.h
|
||||
SOURCES = main.cpp MainWindow.cpp Common.cpp Util.cpp Mapper.cpp SourceGLCanvas.cpp DestinationGLCanvas.cpp MapperGLCanvas.cpp
|
||||
HEADERS = MainWindow.h Util.h MapperGLCanvas.h SourceGLCanvas.h DestinationGLCanvas.h Mapper.h Mapping.h Shape.h Paint.h MappingManager.h
|
||||
SOURCES = main.cpp MainWindow.cpp Util.cpp Mapper.cpp MapperGLCanvas.cpp SourceGLCanvas.cpp DestinationGLCanvas.cpp MappingManager.cpp
|
||||
QT += gui opengl
|
||||
LIBS += -lglut -lGLU
|
||||
RESOURCES = libremapping.qrc
|
||||
|
||||
Reference in New Issue
Block a user