diff --git a/Common.cpp b/Common.cpp index 1f0af5b..fc1ef20 100644 --- a/Common.cpp +++ b/Common.cpp @@ -28,22 +28,31 @@ int Common::currentSourceIdx = 0; Quad* Common::createQuadForTexture(Texture* texture, int frameWidth, int frameHeight) { - float centerX = frameWidth / 2.0f; - float centerY = frameHeight / 2.0f; - float textureHalfWidth = texture->getWidth() / 2.0f; - float textureHalfHeight = texture->getHeight() / 2.0f; - return new Quad( - Point(centerX-textureHalfWidth, centerY-textureHalfHeight), - Point(centerX+textureHalfWidth, centerY-textureHalfHeight), - Point(centerX+textureHalfWidth, centerY+textureHalfHeight), - Point(centerX-textureHalfWidth, centerY+textureHalfHeight)); + Point(texture->getX(), texture->getY()), + Point(texture->getX() + texture->getWidth(), texture->getY()), + Point(texture->getX() + texture->getWidth(), texture->getY() + texture->getHeight()), + Point(texture->getX(), texture->getY() + texture->getHeight()) + ); +// float centerX = frameWidth / 2.0f; +// float centerY = frameHeight / 2.0f; +// float textureHalfWidth = texture->getWidth() / 2.0f; +// float textureHalfHeight = texture->getHeight() / 2.0f; +// +// return new Quad( +// Point(centerX-textureHalfWidth, centerY-textureHalfHeight), +// Point(centerX+textureHalfWidth, centerY-textureHalfHeight), +// Point(centerX+textureHalfWidth, centerY+textureHalfHeight), +// Point(centerX-textureHalfWidth, centerY+textureHalfHeight)); } void Common::addImage(const std::string imagePath, int frameWidth, int frameHeight) { Image* img = new Image(imagePath); + img->setPosition( (frameWidth - img->getWidth() ) / 2.0f, + (frameHeight - img->getHeight()) / 2.0f ); + TextureMapping* tm = new TextureMapping( img, diff --git a/Common.h b/Common.h index ab7fe26..8faeb84 100644 --- a/Common.h +++ b/Common.h @@ -27,6 +27,9 @@ #include "Shape.h" #include "Mapper.h" +#define DEFAULT_WIDTH 1600 +#define DEFAULT_HEIGHT 800 + class Common { public: static std::vector< std::tr1::shared_ptr > mappings; diff --git a/DestinationGLCanvas.cpp b/DestinationGLCanvas.cpp index 286f2a4..7c40717 100644 --- a/DestinationGLCanvas.cpp +++ b/DestinationGLCanvas.cpp @@ -51,8 +51,8 @@ void DestinationGLCanvas::doDraw() { if (tex->getTextureId() == 0) { tex->loadTexture(); - tex->setPosition( (width() - tex->getWidth()) / 2, - (height() - tex->getHeight()) / 2 ); +// tex->setPosition( (width() - tex->getWidth()) / 2, +// (height() - tex->getHeight()) / 2 ); } } diff --git a/MainWindow.cpp b/MainWindow.cpp new file mode 100644 index 0000000..224fd16 --- /dev/null +++ b/MainWindow.cpp @@ -0,0 +1,61 @@ +/* + * MainWindow.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 . + */ + +#include "MainWindow.h" + +MainWindow::MainWindow() +{ + sourceList = new QListView; + sourceCanvas = new SourceGLCanvas; + destinationCanvas = new DestinationGLCanvas(0, sourceCanvas); + + QObject::connect(sourceCanvas, SIGNAL(quadChanged()), + destinationCanvas, SLOT(updateCanvas())); + + QObject::connect(destinationCanvas, SIGNAL(quadSwitched()), + sourceCanvas, SLOT(updateCanvas())); + + sourceCanvas->setFocusPolicy(Qt::ClickFocus); + destinationCanvas->setFocusPolicy(Qt::ClickFocus); + + QSplitter* mainSplitter = new QSplitter(Qt::Horizontal); + + QSplitter* canvasSplitter = new QSplitter(Qt::Horizontal); + canvasSplitter->addWidget(sourceCanvas); + canvasSplitter->addWidget(destinationCanvas); + canvasSplitter->setMinimumWidth(DEFAULT_WIDTH * 2/3); + + //canvasSplitter->resize(DEFAULT_WIDTH, DEFAULT_HEIGHT); +// QSplitter* mainSplitter = canvasSplitter; + + mainSplitter->addWidget(sourceList); + mainSplitter->addWidget(canvasSplitter); + + this->setWindowTitle(QObject::tr("Libremapping")); + this->resize(DEFAULT_WIDTH, DEFAULT_HEIGHT); + this->setCentralWidget(mainSplitter); +// mainSplitter->show(); + +// sourceList->setFixedWidth(100); + Common::initializeLibremapper(sourceCanvas->width(), sourceCanvas->height()); +} + +MainWindow::~MainWindow() { +} + diff --git a/MainWindow.h b/MainWindow.h new file mode 100644 index 0000000..e25725d --- /dev/null +++ b/MainWindow.h @@ -0,0 +1,44 @@ +/* + * MainWindow.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 . + */ + +#ifndef MAIN_WINDOW_H_ +#define MAIN_WINDOW_H_ + +#include + +#include "Common.h" + +#include "DestinationGLCanvas.h" +#include "SourceGLCanvas.h" + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + virtual ~MainWindow(); + +private: + QListView* sourceList; + SourceGLCanvas* sourceCanvas; + DestinationGLCanvas* destinationCanvas; +}; + +#endif /* MAIN_WINDOW_H_ */ diff --git a/Paint.h b/Paint.h index 448bd79..fc1f0af 100644 --- a/Paint.h +++ b/Paint.h @@ -41,8 +41,8 @@ class Texture : public Paint { protected: GLuint textureId; - int x; - int y; + GLfloat x; + GLfloat y; Texture(GLuint textureId_=0) : textureId(textureId_), x(-1), y(-1) {} virtual ~Texture() {} @@ -54,12 +54,12 @@ public: virtual int getHeight() const = 0; virtual const uchar* getBits() const = 0; - virtual void setPosition(int xPos, int yPos) { + virtual void setPosition(GLfloat xPos, GLfloat yPos) { x = xPos; y = yPos; } - virtual int getX() const { return x; } - virtual int getY() const { return y; } + virtual GLfloat getX() const { return x; } + virtual GLfloat getY() const { return y; } }; class Image : public Texture diff --git a/SourceGLCanvas.cpp b/SourceGLCanvas.cpp index b06d891..6028c33 100644 --- a/SourceGLCanvas.cpp +++ b/SourceGLCanvas.cpp @@ -46,8 +46,8 @@ void SourceGLCanvas::doDraw() { std::cout << width() << " " << height() << std::endl; if (texture->getTextureId() == 0) { texture->loadTexture(); - texture->setPosition( (width() - texture->getWidth()) / 2, - (height() - texture->getHeight()) / 2 ); +// texture->setPosition( (width() - texture->getWidth() ) / 2.0f, +// (height() - texture->getHeight()) / 2.0f ); } // Now, draw diff --git a/libremapping.pro b/libremapping.pro index d1e1137..7a0c8a6 100644 --- a/libremapping.pro +++ b/libremapping.pro @@ -1,7 +1,7 @@ CONFIG += qt debug TEMPLATE = app -HEADERS = Common.h Util.h SourceGLCanvas.h DestinationGLCanvas.h MapperGLCanvas.h Mapper.h Shape.h Paint.h -SOURCES = main.cpp Common.cpp Util.cpp Mapper.cpp SourceGLCanvas.cpp DestinationGLCanvas.cpp MapperGLCanvas.cpp +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 QT += gui opengl LIBS += -lSOIL -lglut diff --git a/main.cpp b/main.cpp index b51855d..c8e8c23 100644 --- a/main.cpp +++ b/main.cpp @@ -4,16 +4,10 @@ #include #include "Common.h" -#include "DestinationGLCanvas.h" -#include "SourceGLCanvas.h" +#include "MainWindow.h" #include -#include - -#define DEFAULT_WIDTH 800 -#define DEFAULT_HEIGHT 600 - int main(int argc, char *argv[]) { QApplication app(argc, argv); @@ -24,28 +18,9 @@ int main(int argc, char *argv[]) return 1; } - SourceGLCanvas sourceCanvas; - DestinationGLCanvas destinationCanvas(0, &sourceCanvas); + MainWindow window; + window.show(); - QObject::connect(&sourceCanvas, SIGNAL(quadChanged()), - &destinationCanvas, SLOT(updateCanvas())); - - QObject::connect(&destinationCanvas, SIGNAL(quadSwitched()), - &sourceCanvas, SLOT(updateCanvas())); - - QSplitter splitter(Qt::Horizontal); - splitter.addWidget(&sourceCanvas); - splitter.addWidget(&destinationCanvas); - - sourceCanvas.setFocusPolicy(Qt::ClickFocus); - destinationCanvas.setFocusPolicy(Qt::ClickFocus); - - - splitter.setWindowTitle(QObject::tr("Libremapping")); - splitter.resize(DEFAULT_WIDTH, DEFAULT_HEIGHT); - splitter.show(); - - Common::initializeLibremapper(sourceCanvas.width(), sourceCanvas.height()); return app.exec(); }