- Added an empty QListView in the layout, with two splitters

- Also created a class for the main window
This commit is contained in:
Tats
2013-11-25 23:16:32 -05:00
parent 3964f7b7d1
commit 0ff60f6108
9 changed files with 140 additions and 48 deletions
+18 -9
View File
@@ -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,
+3
View File
@@ -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<Mapping> > mappings;
+2 -2
View File
@@ -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 );
}
}
+61
View File
@@ -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 <http://www.gnu.org/licenses/>.
*/
#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() {
}
+44
View File
@@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef MAIN_WINDOW_H_
#define MAIN_WINDOW_H_
#include <QtGui>
#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_ */
+5 -5
View File
@@ -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
+2 -2
View File
@@ -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
+2 -2
View File
@@ -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
+3 -28
View File
@@ -4,16 +4,10 @@
#include <QtGui>
#include "Common.h"
#include "DestinationGLCanvas.h"
#include "SourceGLCanvas.h"
#include "MainWindow.h"
#include <iostream>
#include <QtGui>
#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();
}