diff --git a/src/Commands/MoveSurfaceCommand.cpp b/src/Commands/MoveSurfaceCommand.cpp index cb1779e..afafe04 100644 --- a/src/Commands/MoveSurfaceCommand.cpp +++ b/src/Commands/MoveSurfaceCommand.cpp @@ -12,14 +12,11 @@ namespace ofx{ } void MoveSurfaceCommand::exec(){ - // Store surface location by copying vertices _previousVertices = _surface->getVertices(); + _surface->setMoved(false); } void MoveSurfaceCommand::undo(){ - //for (auto i = 0; i < _previousVertices.size(); i++) { - //_surface->setVertex(i, _previousVertices[i]); - //} _surface->moveBy(_previousVertices[0] - _surface->getVertices()[0]); _projectionEditor->updateJoints(); _previousVertices.clear(); diff --git a/src/Surfaces/BaseSurface.cpp b/src/Surfaces/BaseSurface.cpp index d6a1ce5..8e835ba 100644 --- a/src/Surfaces/BaseSurface.cpp +++ b/src/Surfaces/BaseSurface.cpp @@ -1,90 +1,94 @@ #include "BaseSurface.h" namespace ofx { -namespace piMapper { - -BaseSurface::BaseSurface() { - ofEnableNormalizedTexCoords(); - createDefaultTexture(); -} + namespace piMapper { + + BaseSurface::BaseSurface() { + _moved = false; + ofEnableNormalizedTexCoords(); + createDefaultTexture(); + } - BaseSurface::~BaseSurface() { - delete defaultSource; - defaultSource = NULL; - defaultTexture.clear(); - } - -void BaseSurface::createDefaultTexture() { - ofPixels pixels; - pixels.allocate(500, 500, 1); - for (int i = 0; i < pixels.size(); i++) { - pixels[i] = 255; - } - int squareSize = 10; // size of each test pattern square - bool sy = false; - for (int y = 0; y < pixels.getWidth(); y += squareSize) { - bool sx = false; - for (int x = 0; x < pixels.getHeight(); x += squareSize) { - for (int yi = 0; yi < squareSize; yi++) { - for (int xi = 0; xi < squareSize; xi++) { - if (sx && sy) - pixels[(y + yi) * pixels.getWidth() + x + xi] = 255; - else if (sx && !sy) - pixels[(y + yi) * pixels.getWidth() + x + xi] = 0; - else if (!sx && sy) - pixels[(y + yi) * pixels.getWidth() + x + xi] = 0; - else - pixels[(y + yi) * pixels.getWidth() + x + xi] = 255; + BaseSurface::~BaseSurface() { + delete defaultSource; + defaultSource = NULL; + defaultTexture.clear(); + } + + void BaseSurface::createDefaultTexture() { + ofPixels pixels; + pixels.allocate(500, 500, 1); + for (int i = 0; i < pixels.size(); i++) { + pixels[i] = 255; + } + int squareSize = 10; // size of each test pattern square + bool sy = false; + for (int y = 0; y < pixels.getWidth(); y += squareSize) { + bool sx = false; + for (int x = 0; x < pixels.getHeight(); x += squareSize) { + for (int yi = 0; yi < squareSize; yi++) { + for (int xi = 0; xi < squareSize; xi++) { + if (sx && sy) + pixels[(y + yi) * pixels.getWidth() + x + xi] = 255; + else if (sx && !sy) + pixels[(y + yi) * pixels.getWidth() + x + xi] = 0; + else if (!sx && sy) + pixels[(y + yi) * pixels.getWidth() + x + xi] = 0; + else + pixels[(y + yi) * pixels.getWidth() + x + xi] = 255; + } + } + sx = !sx; + } + sy = !sy; + } + + // load pixels into texture + defaultTexture.loadData(pixels); + // Create new source to be the default + defaultSource = new BaseSource(&defaultTexture); + source = defaultSource; + } + + void BaseSurface::drawTexture(ofVec2f position) { + if (source->getTexture() == NULL) { + ofLogWarning("BaseSurface") << "Source texture empty. Not drawing."; + return; + } + + ofMesh texMesh; + texMesh.addVertex(position); + texMesh.addVertex(position + ofVec2f(source->getTexture()->getWidth(), 0.0f)); + texMesh.addVertex(position + + ofVec2f(source->getTexture()->getWidth(), source->getTexture()->getHeight())); + texMesh.addVertex(position + ofVec2f(0.0f, source->getTexture()->getHeight())); + texMesh.addTriangle(0, 2, 3); + texMesh.addTriangle(0, 1, 2); + texMesh.addTexCoord(ofVec2f(0.0f, 0.0f)); + texMesh.addTexCoord(ofVec2f(1.0f, 0.0f)); + texMesh.addTexCoord(ofVec2f(1.0f, 1.0f)); + texMesh.addTexCoord(ofVec2f(0.0f, 1.0f)); + source->getTexture()->bind(); + texMesh.draw(); + source->getTexture()->unbind(); + } + + //void BaseSurface::setTexture(ofTexture* texturePtr) { texture = texturePtr; } + void BaseSurface::setSource(BaseSource* newSource) { + source = newSource; + } + + //ofTexture* BaseSurface::getTexture() { return texture; } + BaseSource* BaseSurface::getSource() { + return source; } - } - sx = !sx; + + //ofTexture* BaseSurface::getDefaultTexture() { return &defaultTexture; } + BaseSource* BaseSurface::getDefaultSource() { + return defaultSource; + } + + void BaseSurface::setMoved(bool moved){ _moved = moved; } + bool BaseSurface::getMoved(){ return _moved; } } - sy = !sy; - } - - // load pixels into texture - defaultTexture.loadData(pixels); - // Create new source to be the default - defaultSource = new BaseSource(&defaultTexture); - source = defaultSource; -} - -void BaseSurface::drawTexture(ofVec2f position) { - if (source->getTexture() == NULL) { - ofLogWarning("BaseSurface") << "Source texture empty. Not drawing."; - return; - } - - ofMesh texMesh; - texMesh.addVertex(position); - texMesh.addVertex(position + ofVec2f(source->getTexture()->getWidth(), 0.0f)); - texMesh.addVertex(position + - ofVec2f(source->getTexture()->getWidth(), source->getTexture()->getHeight())); - texMesh.addVertex(position + ofVec2f(0.0f, source->getTexture()->getHeight())); - texMesh.addTriangle(0, 2, 3); - texMesh.addTriangle(0, 1, 2); - texMesh.addTexCoord(ofVec2f(0.0f, 0.0f)); - texMesh.addTexCoord(ofVec2f(1.0f, 0.0f)); - texMesh.addTexCoord(ofVec2f(1.0f, 1.0f)); - texMesh.addTexCoord(ofVec2f(0.0f, 1.0f)); - source->getTexture()->bind(); - texMesh.draw(); - source->getTexture()->unbind(); -} - - //void BaseSurface::setTexture(ofTexture* texturePtr) { texture = texturePtr; } - void BaseSurface::setSource(BaseSource* newSource) { - source = newSource; - } - - //ofTexture* BaseSurface::getTexture() { return texture; } - BaseSource* BaseSurface::getSource() { - return source; - } - - //ofTexture* BaseSurface::getDefaultTexture() { return &defaultTexture; } - BaseSource* BaseSurface::getDefaultSource() { - return defaultSource; - } -} } \ No newline at end of file diff --git a/src/Surfaces/BaseSurface.h b/src/Surfaces/BaseSurface.h index 28b8b52..5f5a151 100644 --- a/src/Surfaces/BaseSurface.h +++ b/src/Surfaces/BaseSurface.h @@ -7,41 +7,38 @@ using namespace std; namespace ofx { -namespace piMapper { -class BaseSurface { - public: - BaseSurface(); - ~BaseSurface(); - virtual void setup() {}; - virtual void draw() {}; - virtual void setVertex(int index, ofVec2f p) {}; - virtual void setTexCoord(int index, ofVec2f t) {}; - virtual void moveBy(ofVec2f v) {}; - virtual int getType() {}; - virtual bool hitTest(ofVec2f p) {}; - virtual ofPolyline getHitArea() {}; - virtual ofPolyline getTextureHitArea() {}; - virtual vector& getVertices() {}; - virtual vector& getTexCoords() {}; - - // Draws a texture using ofMesh - void drawTexture(ofVec2f position); - //void setTexture(ofTexture* texturePtr); - void setSource(BaseSource* newSource); - - //ofTexture* getTexture(); - //ofTexture* getDefaultTexture(); - BaseSource* getSource(); - BaseSource* getDefaultSource(); - - protected: - ofMesh mesh; - //ofTexture* texture; - ofTexture defaultTexture; - BaseSource* source; - BaseSource* defaultSource; - - void createDefaultTexture(); -}; -} + namespace piMapper { + class BaseSurface { + public: + BaseSurface(); + ~BaseSurface(); + virtual void setup() {}; + virtual void draw() {}; + virtual void setVertex(int index, ofVec2f p) {}; + virtual void setTexCoord(int index, ofVec2f t) {}; + virtual void moveBy(ofVec2f v) {}; + virtual int getType() {}; + virtual bool hitTest(ofVec2f p) {}; + virtual ofPolyline getHitArea() {}; + virtual ofPolyline getTextureHitArea() {}; + virtual vector& getVertices() {}; + virtual vector& getTexCoords() {}; + + void drawTexture(ofVec2f position); + void setSource(BaseSource* newSource); + BaseSource* getSource(); + BaseSource* getDefaultSource(); + + void setMoved(bool moved); + bool getMoved(); + + protected: + ofMesh mesh; + ofTexture defaultTexture; + BaseSource* source; + BaseSource* defaultSource; + void createDefaultTexture(); + bool _moved; + }; + } } \ No newline at end of file diff --git a/src/Surfaces/QuadSurface.cpp b/src/Surfaces/QuadSurface.cpp index 896f2f1..c61eb10 100644 --- a/src/Surfaces/QuadSurface.cpp +++ b/src/Surfaces/QuadSurface.cpp @@ -117,6 +117,7 @@ void QuadSurface::moveBy(ofVec2f v) { vertices[i] += v; } calculate4dTextureCoords(); + setMoved(true); } int QuadSurface::getType() { return SurfaceType::QUAD_SURFACE; } diff --git a/src/Surfaces/SurfaceManagerGui.cpp b/src/Surfaces/SurfaceManagerGui.cpp index 981e19c..f1b156b 100644 --- a/src/Surfaces/SurfaceManagerGui.cpp +++ b/src/Surfaces/SurfaceManagerGui.cpp @@ -1,262 +1,268 @@ #include "SurfaceManagerGui.h" namespace ofx { -namespace piMapper { -SurfaceManagerGui::SurfaceManagerGui() { - surfaceManager = NULL; - guiMode = GuiMode::NONE; - bDrag = false; - registerMouseEvents(); - ofHideCursor(); - _commandManager = 0; -} - -SurfaceManagerGui::~SurfaceManagerGui() { - unregisterMouseEvents(); - surfaceManager = NULL; - _commandManager = 0; -} - -void SurfaceManagerGui::registerMouseEvents() { - ofAddListener(ofEvents().mousePressed, this, - &SurfaceManagerGui::mousePressed); - ofAddListener(ofEvents().mouseReleased, this, - &SurfaceManagerGui::mouseReleased); - ofAddListener(ofEvents().mouseDragged, this, - &SurfaceManagerGui::mouseDragged); -} - -void SurfaceManagerGui::unregisterMouseEvents() { - ofRemoveListener(ofEvents().mousePressed, this, - &SurfaceManagerGui::mousePressed); - ofRemoveListener(ofEvents().mouseReleased, this, - &SurfaceManagerGui::mouseReleased); - ofRemoveListener(ofEvents().mouseDragged, this, - &SurfaceManagerGui::mouseDragged); -} - -void SurfaceManagerGui::draw() { - if (surfaceManager == NULL) return; - - if (guiMode == GuiMode::NONE) { - surfaceManager->draw(); - } else if (guiMode == GuiMode::TEXTURE_MAPPING) { - // draw the texture of the selected surface - if (surfaceManager->getSelectedSurface() != NULL) { - surfaceManager->getSelectedSurface()->drawTexture(ofVec2f(0, 0)); - } - - // draw surfaces with opacity - ofPushStyle(); - ofSetColor(255, 255, 255, 200); - surfaceManager->draw(); - ofPopStyle(); - - // highlight selected surface - drawSelectedSurfaceHighlight(); - - // hilight selected surface texture - drawSelectedSurfaceTextureHighlight(); - - // draw texture editing GUI on top - textureEditor.draw(); - - } else if (guiMode == GuiMode::PROJECTION_MAPPING) { - // draw projection surfaces first - surfaceManager->draw(); - - // highlight selected surface - drawSelectedSurfaceHighlight(); - - // draw projection mapping editing gui - projectionEditor.draw(); - - } else if (guiMode == GuiMode::SOURCE_SELECTION) { - // draw projection surfaces first - surfaceManager->draw(); - - // highlight selected surface - drawSelectedSurfaceHighlight(); - - sourcesEditor.draw(); - } -} - -void SurfaceManagerGui::mousePressed(ofMouseEventArgs& args) { - if (guiMode == GuiMode::NONE) { - return; - } else if (guiMode == GuiMode::TEXTURE_MAPPING) { - bool bSurfaceSelected = false; - - CircleJoint* hitJoint = - textureEditor.hitTestJoints(ofVec2f(args.x, args.y)); - if (hitJoint != NULL) { - textureEditor.unselectAllJoints(); - hitJoint->select(); - hitJoint->startDrag(); - bSurfaceSelected = true; - } else { - textureEditor.unselectAllJoints(); + namespace piMapper { + SurfaceManagerGui::SurfaceManagerGui() { + surfaceManager = NULL; + guiMode = GuiMode::NONE; + bDrag = false; + registerMouseEvents(); + ofHideCursor(); + _commandManager = 0; + } + + SurfaceManagerGui::~SurfaceManagerGui() { + unregisterMouseEvents(); + surfaceManager = NULL; + _commandManager = 0; + } + + void SurfaceManagerGui::registerMouseEvents() { + ofAddListener(ofEvents().mousePressed, this, + &SurfaceManagerGui::mousePressed); + ofAddListener(ofEvents().mouseReleased, this, + &SurfaceManagerGui::mouseReleased); + ofAddListener(ofEvents().mouseDragged, this, + &SurfaceManagerGui::mouseDragged); + } + + void SurfaceManagerGui::unregisterMouseEvents() { + ofRemoveListener(ofEvents().mousePressed, this, + &SurfaceManagerGui::mousePressed); + ofRemoveListener(ofEvents().mouseReleased, this, + &SurfaceManagerGui::mouseReleased); + ofRemoveListener(ofEvents().mouseDragged, this, + &SurfaceManagerGui::mouseDragged); + } + + void SurfaceManagerGui::draw() { + if (surfaceManager == NULL) return; + + if (guiMode == GuiMode::NONE) { + surfaceManager->draw(); + } else if (guiMode == GuiMode::TEXTURE_MAPPING) { + // draw the texture of the selected surface + if (surfaceManager->getSelectedSurface() != NULL) { + surfaceManager->getSelectedSurface()->drawTexture(ofVec2f(0, 0)); + } + + // draw surfaces with opacity + ofPushStyle(); + ofSetColor(255, 255, 255, 200); + surfaceManager->draw(); + ofPopStyle(); + + // highlight selected surface + drawSelectedSurfaceHighlight(); + + // hilight selected surface texture + drawSelectedSurfaceTextureHighlight(); + + // draw texture editing GUI on top + textureEditor.draw(); + + } else if (guiMode == GuiMode::PROJECTION_MAPPING) { + // draw projection surfaces first + surfaceManager->draw(); + + // highlight selected surface + drawSelectedSurfaceHighlight(); + + // draw projection mapping editing gui + projectionEditor.draw(); + + } else if (guiMode == GuiMode::SOURCE_SELECTION) { + // draw projection surfaces first + surfaceManager->draw(); + + // highlight selected surface + drawSelectedSurfaceHighlight(); + + sourcesEditor.draw(); + } + } + + void SurfaceManagerGui::mousePressed(ofMouseEventArgs& args) { + if (guiMode == GuiMode::NONE) { + return; + } else if (guiMode == GuiMode::TEXTURE_MAPPING) { + bool bSurfaceSelected = false; + + CircleJoint* hitJoint = + textureEditor.hitTestJoints(ofVec2f(args.x, args.y)); + if (hitJoint != NULL) { + textureEditor.unselectAllJoints(); + hitJoint->select(); + hitJoint->startDrag(); + bSurfaceSelected = true; + } else { + textureEditor.unselectAllJoints(); + } + + if (surfaceManager->getSelectedSurface() != NULL && !bSurfaceSelected) { + // hittest texture area to see if we are hitting the texture surface + if (surfaceManager->getSelectedSurface()->getTextureHitArea().inside( + args.x, args.y)) { + clickPosition = ofVec2f(args.x, args.y); + startDrag(); + } + } + + } else if (guiMode == GuiMode::PROJECTION_MAPPING) { + bool bSurfaceSelected = false; + + CircleJoint* hitJoint = + projectionEditor.hitTestJoints(ofVec2f(args.x, args.y)); + if (hitJoint != NULL) { + projectionEditor.unselectAllJoints(); + hitJoint->select(); + hitJoint->startDrag(); + bSurfaceSelected = true; + } + + // attempt to select surface, loop from end to beginning + if (!bSurfaceSelected) { + for (int i = surfaceManager->size() - 1; i >= 0; i--) { + if (surfaceManager->getSurface(i)->hitTest(ofVec2f(args.x, args.y))) { + + // TODO: Do not repeat this command if attempting to select an + // already selected surface. + _commandManager->exec(new SelectSurfaceCommand( + surfaceManager, + surfaceManager->getSurface(i), + &projectionEditor)); + bSurfaceSelected = true; + break; + } + } + } + + if (bSurfaceSelected && hitJoint == NULL) { + // if not hitting the joints, start drag only if we have a selected + // surface + clickPosition = ofVec2f(args.x, args.y); + startDrag(); + + // TODO: Undo this command if surface not moved on mouse release + _commandManager->exec( + new MoveSurfaceCommand( + surfaceManager->getSelectedSurface(), + &projectionEditor)); + } + + if (!bSurfaceSelected) { + // unselect if no surface selected + projectionEditor.clearJoints(); + surfaceManager->deselectSurface(); + } + } else if (guiMode == GuiMode::SOURCE_SELECTION) { + } + } + + void SurfaceManagerGui::mouseReleased(ofMouseEventArgs& args) { + stopDrag(); + projectionEditor.stopDragJoints(); + textureEditor.stopDragJoints(); + + // Check if surface has moved + if (!surfaceManager->getSelectedSurface()->getMoved()) { + _commandManager->undo(); + } + + } + + void SurfaceManagerGui::mouseDragged(ofMouseEventArgs& args) { + if (bDrag) { + ofVec2f mousePosition = ofVec2f(args.x, args.y); + ofVec2f distance = mousePosition - clickPosition; + + if (guiMode == GuiMode::PROJECTION_MAPPING) { + // add this distance to all vertices in surface + projectionEditor.moveSelectedSurface(distance); + } else if (guiMode == GuiMode::TEXTURE_MAPPING) { + textureEditor.moveTexCoords(distance); + } + clickPosition = mousePosition; + } + } + + void SurfaceManagerGui::setSurfaceManager(SurfaceManager* newSurfaceManager) { + surfaceManager = newSurfaceManager; + projectionEditor.setSurfaceManager(surfaceManager); + sourcesEditor.setSurfaceManager(surfaceManager); + } + + // Set external media server so we can access it from wherever we need + void SurfaceManagerGui::setMediaServer(MediaServer* newMediaServer) { + mediaServer = newMediaServer; + // Set the media server of the sources editor here + sourcesEditor.setMediaServer(mediaServer); + } + + void SurfaceManagerGui::setCommandManager(CommandManager * commandManager){ + _commandManager = commandManager; + } + + void SurfaceManagerGui::setMode(int newGuiMode) { + if (newGuiMode != GuiMode::NONE && newGuiMode != GuiMode::TEXTURE_MAPPING && + newGuiMode != GuiMode::PROJECTION_MAPPING && + newGuiMode != GuiMode::SOURCE_SELECTION) { + throw std::runtime_error("Trying to set invalid mode."); + } + + if (newGuiMode == GuiMode::NONE) { + ofHideCursor(); + } else { + ofShowCursor(); + } + + guiMode = newGuiMode; + + if (guiMode == GuiMode::SOURCE_SELECTION) { + sourcesEditor.enable(); + //string sourceName = surfaceManager->getSelectedSurfaceSourceName(); + //sourcesEditor.selectImageSourceRadioButton(sourceName); + } else { + sourcesEditor.disable(); + } + + if (guiMode == GuiMode::TEXTURE_MAPPING) { + textureEditor.enable(); + // refresh texture editor surface reference + textureEditor.setSurface(surfaceManager->getSelectedSurface()); + } else { + textureEditor.disable(); + } + + if (guiMode == GuiMode::PROJECTION_MAPPING) { + projectionEditor.enable(); + } else { + projectionEditor.disable(); + } + } + + void SurfaceManagerGui::drawSelectedSurfaceHighlight() { + if (surfaceManager->getSelectedSurface() == NULL) return; + ofPolyline line = surfaceManager->getSelectedSurface()->getHitArea(); + ofPushStyle(); + ofSetLineWidth(1); + ofSetColor(255, 255, 255, 255); + line.draw(); + ofPopStyle(); + } + + void SurfaceManagerGui::drawSelectedSurfaceTextureHighlight() { + if (surfaceManager->getSelectedSurface() == NULL) return; + ofPolyline line = surfaceManager->getSelectedSurface()->getTextureHitArea(); + ofPushStyle(); + ofSetLineWidth(1); + ofSetColor(255, 255, 0, 255); + line.draw(); + ofPopStyle(); + } + + void SurfaceManagerGui::startDrag() { bDrag = true; } + + void SurfaceManagerGui::stopDrag() { bDrag = false; } } - - if (surfaceManager->getSelectedSurface() != NULL && !bSurfaceSelected) { - // hittest texture area to see if we are hitting the texture surface - if (surfaceManager->getSelectedSurface()->getTextureHitArea().inside( - args.x, args.y)) { - clickPosition = ofVec2f(args.x, args.y); - startDrag(); - } - } - - } else if (guiMode == GuiMode::PROJECTION_MAPPING) { - bool bSurfaceSelected = false; - - CircleJoint* hitJoint = - projectionEditor.hitTestJoints(ofVec2f(args.x, args.y)); - if (hitJoint != NULL) { - projectionEditor.unselectAllJoints(); - hitJoint->select(); - hitJoint->startDrag(); - bSurfaceSelected = true; - } - - // attempt to select surface, loop from end to beginning - if (!bSurfaceSelected) { - for (int i = surfaceManager->size() - 1; i >= 0; i--) { - if (surfaceManager->getSurface(i)->hitTest(ofVec2f(args.x, args.y))) { - _commandManager->exec(new SelectSurfaceCommand( - surfaceManager, - surfaceManager->getSurface(i), - &projectionEditor)); - bSurfaceSelected = true; - break; - } - } - } - - if (bSurfaceSelected && hitJoint == NULL) { - // if not hitting the joints, start drag only if we have a selected - // surface - clickPosition = ofVec2f(args.x, args.y); - startDrag(); - - _commandManager->exec( - new MoveSurfaceCommand( - surfaceManager->getSelectedSurface(), - &projectionEditor)); - } - - if (!bSurfaceSelected) { - // unselect if no surface selected - projectionEditor.clearJoints(); - surfaceManager->deselectSurface(); - } - } else if (guiMode == GuiMode::SOURCE_SELECTION) { - } -} - -void SurfaceManagerGui::mouseReleased(ofMouseEventArgs& args) { - stopDrag(); - projectionEditor.stopDragJoints(); - textureEditor.stopDragJoints(); -} - -void SurfaceManagerGui::mouseDragged(ofMouseEventArgs& args) { - if (bDrag) { - ofVec2f mousePosition = ofVec2f(args.x, args.y); - ofVec2f distance = mousePosition - clickPosition; - - if (guiMode == GuiMode::PROJECTION_MAPPING) { - // add this distance to all vertices in surface - projectionEditor.moveSelectedSurface(distance); - } else if (guiMode == GuiMode::TEXTURE_MAPPING) { - textureEditor.moveTexCoords(distance); - } - clickPosition = mousePosition; - } -} - -void SurfaceManagerGui::setSurfaceManager(SurfaceManager* newSurfaceManager) { - surfaceManager = newSurfaceManager; - projectionEditor.setSurfaceManager(surfaceManager); - sourcesEditor.setSurfaceManager(surfaceManager); -} - - // Set external media server so we can access it from wherever we need - void SurfaceManagerGui::setMediaServer(MediaServer* newMediaServer) { - mediaServer = newMediaServer; - // Set the media server of the sources editor here - sourcesEditor.setMediaServer(mediaServer); - } - - void SurfaceManagerGui::setCommandManager(CommandManager * commandManager){ - _commandManager = commandManager; - } - -void SurfaceManagerGui::setMode(int newGuiMode) { - if (newGuiMode != GuiMode::NONE && newGuiMode != GuiMode::TEXTURE_MAPPING && - newGuiMode != GuiMode::PROJECTION_MAPPING && - newGuiMode != GuiMode::SOURCE_SELECTION) { - throw std::runtime_error("Trying to set invalid mode."); - } - - if (newGuiMode == GuiMode::NONE) { - ofHideCursor(); - } else { - ofShowCursor(); - } - - guiMode = newGuiMode; - - if (guiMode == GuiMode::SOURCE_SELECTION) { - sourcesEditor.enable(); - //string sourceName = surfaceManager->getSelectedSurfaceSourceName(); - //sourcesEditor.selectImageSourceRadioButton(sourceName); - } else { - sourcesEditor.disable(); - } - - if (guiMode == GuiMode::TEXTURE_MAPPING) { - textureEditor.enable(); - // refresh texture editor surface reference - textureEditor.setSurface(surfaceManager->getSelectedSurface()); - } else { - textureEditor.disable(); - } - - if (guiMode == GuiMode::PROJECTION_MAPPING) { - projectionEditor.enable(); - } else { - projectionEditor.disable(); - } -} - -void SurfaceManagerGui::drawSelectedSurfaceHighlight() { - if (surfaceManager->getSelectedSurface() == NULL) return; - - ofPolyline line = surfaceManager->getSelectedSurface()->getHitArea(); - - ofPushStyle(); - ofSetLineWidth(1); - ofSetColor(255, 255, 255, 255); - line.draw(); - ofPopStyle(); -} - -void SurfaceManagerGui::drawSelectedSurfaceTextureHighlight() { - if (surfaceManager->getSelectedSurface() == NULL) return; - - ofPolyline line = surfaceManager->getSelectedSurface()->getTextureHitArea(); - - ofPushStyle(); - ofSetLineWidth(1); - ofSetColor(255, 255, 0, 255); - line.draw(); - ofPopStyle(); -} - -void SurfaceManagerGui::startDrag() { bDrag = true; } - -void SurfaceManagerGui::stopDrag() { bDrag = false; } -} } \ No newline at end of file diff --git a/src/Surfaces/TriangleSurface.cpp b/src/Surfaces/TriangleSurface.cpp index f370080..a5bbcec 100644 --- a/src/Surfaces/TriangleSurface.cpp +++ b/src/Surfaces/TriangleSurface.cpp @@ -76,6 +76,7 @@ void TriangleSurface::moveBy(ofVec2f v) { for (int i = 0; i < vertices.size(); i++) { vertices[i] += v; } + setMoved(true); } int TriangleSurface::getType() { return SurfaceType::TRIANGLE_SURFACE; }