diff --git a/Controller.cpp b/Controller.cpp index c7863fd..be37339 100644 --- a/Controller.cpp +++ b/Controller.cpp @@ -35,6 +35,7 @@ bool Controller::createObject(const char* objType, const char* objName) if (meta) { _mControllerObjects[objName] = meta->newInstance(); + //std::cout << "object creation " << objName << " succeeded\n"; return true; } //std::cout << "object creation " << objName << " failed\n"; @@ -49,6 +50,7 @@ bool Controller::setObjectProperty(const char* objName, const char* propName, { if (obj->setProperty(propName, value)) { + //std::cout << "setproperty succeeded " << propName << "\n"; return true; } else @@ -119,5 +121,6 @@ Controller::Controller(MainWindow *owner) * FIXME, we can provide a method for other classes to register types of their * properties instead of doing it in the controller constructor */ qRegisterMetaType("int"); - qRegisterMetaType("double"); + qRegisterMetaType("qreal"); + registerObjType("Point"); } diff --git a/DestinationGLCanvas.cpp b/DestinationGLCanvas.cpp index d240e86..7a9dc88 100644 --- a/DestinationGLCanvas.cpp +++ b/DestinationGLCanvas.cpp @@ -98,8 +98,8 @@ void DestinationGLCanvas::doDraw() for (int i = 0; i < shape->nVertices()+1; i++) { glVertex2f( - shape->getVertex(i % shape->nVertices()).x, - shape->getVertex(i % shape->nVertices()).y + GLfloat(shape->getVertex(i % shape->nVertices())->x()), + GLfloat(shape->getVertex(i % shape->nVertices())->y()) ); } } diff --git a/Mapper.cpp b/Mapper.cpp index 4591c4f..939784a 100644 --- a/Mapper.cpp +++ b/Mapper.cpp @@ -66,11 +66,11 @@ void TextureMapper::draw() for (int i = 0; i < inputShape->nVertices(); i++) { Util::correctGlTexCoord( - (inputShape->getVertex(i).x - texture->getX()) / (GLfloat) texture->getWidth(), - (inputShape->getVertex(i).y - texture->getY()) / (GLfloat) texture->getHeight()); + (inputShape->getVertex(i)->x() - texture->getX()) / (GLfloat) texture->getWidth(), + (inputShape->getVertex(i)->y() - texture->getY()) / (GLfloat) texture->getHeight()); glVertex2f( - outputShape->getVertex(i).x, - outputShape->getVertex(i).y + outputShape->getVertex(i)->x(), + outputShape->getVertex(i)->y() ); } } diff --git a/Mapper.h b/Mapper.h index 0ce24cc..abee11f 100644 --- a/Mapper.h +++ b/Mapper.h @@ -91,8 +91,8 @@ public: // glBegin (GL_LINE_STRIP); // { // for (int i=0; i<5; i++) { -// glVertex3f(quad->getVertex(i % 4).x / (GLfloat)texture->getWidth(), -// quad->getVertex(i % 4).y / (GLfloat)texture->getHeight(), +// glVertex3f(quad->getVertex(i % 4)->x / (GLfloat)texture->getWidth(), +// quad->getVertex(i % 4)->y / (GLfloat)texture->getHeight(), // 0); // } // } diff --git a/MapperGLCanvas.cpp b/MapperGLCanvas.cpp index 363f8bc..b06b280 100644 --- a/MapperGLCanvas.cpp +++ b/MapperGLCanvas.cpp @@ -109,8 +109,8 @@ void MapperGLCanvas::mousePressEvent(QMouseEvent* event) { for (i = 0; i < shape->nVertices(); i++) { - Point p = shape->getVertex(i); - dist = abs(xmouse - p.x) + abs(ymouse - p.y); + Point *p = shape->getVertex(i); + dist = abs(xmouse - p->x()) + abs(ymouse - p->y()); if (dist < maxdist && dist < mindist) { _active_vertex = i; @@ -137,9 +137,9 @@ void MapperGLCanvas::mouseMoveEvent(QMouseEvent* event) Shape* shape = getCurrentShape(); if (shape) { - Point p = shape->getVertex(_active_vertex); - p.x = event->x(); - p.y = event->y(); + Point *p = shape->getVertex(_active_vertex); + p->setX(event->x()); + p->setY(event->y()); shape->setVertex(_active_vertex, p); update(); @@ -182,9 +182,9 @@ void MapperGLCanvas::keyPressEvent(QKeyEvent* event) // } // // Quad& quad = getQuad(); -// Point p = quad.getVertex(_active_vertex); -// p.x += xMove; -// p.y += yMove; +// Point *p = quad.getVertex(_active_vertex); +// p->x += xMove; +// p->y += yMove; // quad.setVertex(_active_vertex, p); // // update(); diff --git a/ProjectWriter.cpp b/ProjectWriter.cpp index 881e970..66c8f5d 100644 --- a/ProjectWriter.cpp +++ b/ProjectWriter.cpp @@ -80,16 +80,16 @@ void ProjectWriter::writeShapeVertices(Shape *shape) { for (int i = 0; i < shape->nVertices(); i++) { - const Point & point = shape->getVertex(i); + Point *point = shape->getVertex(i); _xml.writeStartElement("vertex"); { std::ostringstream os; - os << point.x; + os << point->x(); _xml.writeAttribute("x", os.str().c_str()); } { std::ostringstream os; - os << point.y; + os << point->y(); _xml.writeAttribute("y", os.str().c_str()); } _xml.writeEndElement(); // vertex diff --git a/Shape.h b/Shape.h index 259569a..0b631fe 100644 --- a/Shape.h +++ b/Shape.h @@ -22,18 +22,43 @@ #include #include - +#include +#include +#include +#include +#include /** * Point (or vertex) on the 2-D canvas. */ -struct Point -{ -public: - double x; - double y; - Point(double x_, double y_) : x(x_), y(y_) {} -}; + +Q_DECLARE_METATYPE (qreal) + +class Point: public QObject, public QPointF +{ + Q_OBJECT +public: + Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged) + Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged) + Q_INVOKABLE Point(qreal x, qreal y): QPointF(x,y) {} + Q_INVOKABLE Point(): QPointF(0,0) {} +signals: + void xChanged(); + void yChanged(); + +public slots: + void setX(qreal x) + { + QPointF::setX(x); + emit xChanged(); + } + void setY(qreal y) + { + QPointF::setY(y); + emit yChanged(); + } + +}; /** * Series of vertices. (points) */ @@ -41,9 +66,9 @@ class Shape { public: typedef std::tr1::shared_ptr ptr; - std::vector vertices; + std::vector vertices; Shape() {} - Shape(std::vector vertices_) : + Shape(std::vector vertices_) : vertices(vertices_) {} virtual ~Shape() {} @@ -52,18 +77,18 @@ public: int nVertices() const { return vertices.size(); } - const Point& getVertex(int i) + Point* getVertex(int i) { return vertices[i]; } - void setVertex(int i, Point v) + void setVertex(int i, Point *v) { vertices[i] = v; } void setVertex(int i, double x, double y) { - vertices[i].x = x; - vertices[i].y = y; + vertices[i]->setX(x); + vertices[i]->setY(y); } virtual const char * getShapeType() = 0; }; @@ -75,7 +100,7 @@ class Quad : public Shape { public: Quad() {} - Quad(Point p1, Point p2, Point p3, Point p4) + Quad(Point *p1, Point *p2, Point *p3, Point *p4) { vertices.push_back(p1); vertices.push_back(p2); @@ -94,7 +119,7 @@ class Triangle : public Shape { public: Triangle() {} - Triangle(Point p1, Point p2, Point p3) + Triangle(Point *p1, Point *p2, Point *p3) { vertices.push_back(p1); vertices.push_back(p2); diff --git a/SourceGLCanvas.cpp b/SourceGLCanvas.cpp index ff4ec78..48bed9f 100644 --- a/SourceGLCanvas.cpp +++ b/SourceGLCanvas.cpp @@ -149,8 +149,8 @@ void SourceGLCanvas::doDraw() for (int i = 0; i < inputShape->nVertices()+1; i++) { glVertex2f( - inputShape->getVertex(i % inputShape->nVertices()).x, - inputShape->getVertex(i % inputShape->nVertices()).y + GLfloat(inputShape->getVertex(i % inputShape->nVertices())->x()), + GLfloat(inputShape->getVertex(i % inputShape->nVertices())->y()) ); } } diff --git a/Util.cpp b/Util.cpp index 78126e3..066fa71 100644 --- a/Util.cpp +++ b/Util.cpp @@ -60,19 +60,19 @@ int map_int(int value, int istart, int istop, int ostart, int ostop) Quad* createQuadForTexture(Texture* texture, int frameWidth, int frameHeight) { return new Quad( - 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()) + new Point(qreal(texture->getX()), qreal(texture->getY())), + new Point(qreal(texture->getX() + texture->getWidth()), qreal(texture->getY())), + new Point(qreal(texture->getX() + texture->getWidth()), qreal(texture->getY() + texture->getHeight())), + new Point(qreal(texture->getX()), qreal(texture->getY() + texture->getHeight())) ); } Triangle* createTriangleForTexture(Texture* texture, int frameWidth, int frameHeight) { return new Triangle( - Point(texture->getX(), texture->getY()), - Point(texture->getX() + texture->getWidth(), texture->getY()), - Point(texture->getX() + texture->getWidth() / 2, texture->getY() + texture->getHeight()) + new Point(qreal(texture->getX()), qreal(texture->getY())), + new Point(qreal(texture->getX() + texture->getWidth()), qreal(texture->getY())), + new Point(qreal(texture->getX() + texture->getWidth() / 2), qreal(texture->getY() + texture->getHeight())) ); } diff --git a/libremapping.pro b/libremapping.pro index d3b0141..7ea5912 100644 --- a/libremapping.pro +++ b/libremapping.pro @@ -14,7 +14,7 @@ macx:LIBS += -framework OpenGL -framework GLUT macx:QMAKE_CXXFLAGS += -D__MACOSX_CORE__ # not mac -!macx:LIBS += -lglut -lGLU +!macx:LIBS += -lglut -lGLU -lboost_system # detect osc # unix { diff --git a/main.cpp b/main.cpp index f87cb6f..04c4d2c 100644 --- a/main.cpp +++ b/main.cpp @@ -5,6 +5,8 @@ #include #include "Common.h" #include "MainWindow.h" +#include "Controller.h" +#include #include @@ -19,6 +21,19 @@ int main(int argc, char *argv[]) return 1; } + // some examples, commented out + /* Controller *control = new Controller(&MainWindow::getInstance()); + control->createObject("Point", "point1"); + control->createObject("Point", "point2"); + QVariant var(1.55), var2; + QList names, objs; + QVariantList values; + control->setObjectProperty("point1","x", QVariant(1.23)); + control->setObjectProperty("point1","y", QVariant(3.14)); + control->getObjectProperty("point1","y", var2); + control->getObjectProperty("point1","x", var2); + control->listObjectProperties("point1", names, values); + control->listObjects("QObject", objs);*/ MainWindow::getInstance().show(); return app.exec();