diff --git a/example/example.xcodeproj/project.pbxproj b/example/example.xcodeproj/project.pbxproj index 5035830..2d54e5e 100644 --- a/example/example.xcodeproj/project.pbxproj +++ b/example/example.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ 391717EF1B08FFDA00F9A484 /* SetGuiModeCmd.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 391717ED1B08FFDA00F9A484 /* SetGuiModeCmd.cpp */; }; 391717F31B0A8A7300F9A484 /* MvAllTexCoordsCmd.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 391717F11B0A8A7300F9A484 /* MvAllTexCoordsCmd.cpp */; }; + 391717F71B0BCBB500F9A484 /* MvTexCoordCmd.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 391717F51B0BCBB500F9A484 /* MvTexCoordCmd.cpp */; }; 3926483B192224DA0008A7F5 /* ofxXmlSettings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 39264839192224DA0008A7F5 /* ofxXmlSettings.cpp */; }; 39264841192224F90008A7F5 /* tinyxml.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3926483D192224F90008A7F5 /* tinyxml.cpp */; }; 39264842192224F90008A7F5 /* tinyxmlerror.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3926483F192224F90008A7F5 /* tinyxmlerror.cpp */; }; @@ -126,6 +127,8 @@ 391717EE1B08FFDA00F9A484 /* SetGuiModeCmd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SetGuiModeCmd.h; path = Commands/SetGuiModeCmd.h; sourceTree = ""; }; 391717F11B0A8A7300F9A484 /* MvAllTexCoordsCmd.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MvAllTexCoordsCmd.cpp; path = Commands/MvAllTexCoordsCmd.cpp; sourceTree = ""; }; 391717F21B0A8A7300F9A484 /* MvAllTexCoordsCmd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MvAllTexCoordsCmd.h; path = Commands/MvAllTexCoordsCmd.h; sourceTree = ""; }; + 391717F51B0BCBB500F9A484 /* MvTexCoordCmd.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MvTexCoordCmd.cpp; path = Commands/MvTexCoordCmd.cpp; sourceTree = ""; }; + 391717F61B0BCBB500F9A484 /* MvTexCoordCmd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MvTexCoordCmd.h; path = Commands/MvTexCoordCmd.h; sourceTree = ""; }; 39264839192224DA0008A7F5 /* ofxXmlSettings.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ofxXmlSettings.cpp; path = ../../ofxXmlSettings/src/ofxXmlSettings.cpp; sourceTree = ""; }; 3926483A192224DA0008A7F5 /* ofxXmlSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ofxXmlSettings.h; path = ../../ofxXmlSettings/src/ofxXmlSettings.h; sourceTree = ""; }; 3926483D192224F90008A7F5 /* tinyxml.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = tinyxml.cpp; sourceTree = ""; }; @@ -669,6 +672,8 @@ 391717ED1B08FFDA00F9A484 /* SetGuiModeCmd.cpp */, 391717F21B0A8A7300F9A484 /* MvAllTexCoordsCmd.h */, 391717F11B0A8A7300F9A484 /* MvAllTexCoordsCmd.cpp */, + 391717F61B0BCBB500F9A484 /* MvTexCoordCmd.h */, + 391717F51B0BCBB500F9A484 /* MvTexCoordCmd.cpp */, ); name = Commands; sourceTree = ""; @@ -906,6 +911,7 @@ 39C1243B19EE9589005DF557 /* DeviceFilter.cpp in Sources */, 39C1243E19EE9589005DF557 /* DirectoryWatcher.cpp in Sources */, 39C1248119F187D5005DF557 /* TextureEditor.cpp in Sources */, + 391717F71B0BCBB500F9A484 /* MvTexCoordCmd.cpp in Sources */, E4B69E210A3A1BDC003C02F2 /* ofApp.cpp in Sources */, 39C1244B19EE9589005DF557 /* snappy.cc in Sources */, 3933D5D719BB87BD000ACA55 /* ofxPanel.cpp in Sources */, diff --git a/src/Commands/MvAllTexCoordsCmd.h b/src/Commands/MvAllTexCoordsCmd.h index 1d5f972..578c29d 100644 --- a/src/Commands/MvAllTexCoordsCmd.h +++ b/src/Commands/MvAllTexCoordsCmd.h @@ -1,6 +1,6 @@ // MvAllTexCoordsCmd // Move all texture coordinates of a selected surface undoable command -// Created by Krisjanis Rijnieks 2015-05-15 +// Created by Krisjanis Rijnieks 2015-05-18 #pragma once diff --git a/src/Commands/MvTexCoordCmd.cpp b/src/Commands/MvTexCoordCmd.cpp new file mode 100644 index 0000000..be364a3 --- /dev/null +++ b/src/Commands/MvTexCoordCmd.cpp @@ -0,0 +1,26 @@ +#include "MvTexCoordCmd.h" + +namespace ofx{ + namespace piMapper{ + + MvTexCoordCmd::MvTexCoordCmd(int jointIndex, TextureEditor * texEditor){ + _jointIndex = jointIndex; + _texEditor = texEditor; + } + + void MvTexCoordCmd::exec(){ + ofLogNotice("MvTexCoordCmd", "exec"); + _jointPosition = _texEditor->getJoints()[_jointIndex]->position; + } + + void MvTexCoordCmd::undo(){ + ofLogNotice("MvTexCoordCmd", "undo"); + _texEditor->unselectAllJoints(); + _texEditor->getJoints()[_jointIndex]->select(); + _texEditor->getJoints()[_jointIndex]->position = _jointPosition; + _texEditor = 0; + } + + } // namespace piMapper +} // namespace ofx + diff --git a/src/Commands/MvTexCoordCmd.h b/src/Commands/MvTexCoordCmd.h new file mode 100644 index 0000000..2b24372 --- /dev/null +++ b/src/Commands/MvTexCoordCmd.h @@ -0,0 +1,29 @@ +// MvTexCoordCmd +// Move texture coordinate of a selected surface and be able to undo it +// Created by Krisjanis Rijnieks 2015-05-19 + +#pragma once + +#include "BaseCmd.h" +#include "CircleJoint.h" +#include "TextureEditor.h" + +namespace ofx{ + namespace piMapper{ + + class MvTexCoordCmd : public BaseUndoCmd{ + + public: + MvTexCoordCmd(int jointIndex, TextureEditor * texEditor); + void exec(); + void undo(); + + private: + ofVec2f _jointPosition; + int _jointIndex; + TextureEditor * _texEditor; + }; + + } // namespace piMapper +} // namespace ofx + diff --git a/src/Surfaces/SurfaceManagerGui.cpp b/src/Surfaces/SurfaceManagerGui.cpp index d1f7d3b..a7250c3 100644 --- a/src/Surfaces/SurfaceManagerGui.cpp +++ b/src/Surfaces/SurfaceManagerGui.cpp @@ -91,11 +91,23 @@ namespace ofx { textureEditor.hitTestJoints(ofVec2f(args.x, args.y)); if (hitJoint != NULL) { textureEditor.unselectAllJoints(); - // TODO: Add texture coord move command - // MvTexCoordCmd + hitJoint->select(); hitJoint->startDrag(); bSurfaceSelected = true; + + int jointIndex = -1; + for (auto i = 0; i < textureEditor.getJoints().size(); i++) { + if (textureEditor.getJoints()[i] == hitJoint) { + jointIndex = i; + break; + } + } + + if (jointIndex != -1) { + _cmdManager->exec(new MvTexCoordCmd(jointIndex, &textureEditor)); + } + } else { textureEditor.unselectAllJoints(); } diff --git a/src/Surfaces/SurfaceManagerGui.h b/src/Surfaces/SurfaceManagerGui.h index f23230c..725027c 100644 --- a/src/Surfaces/SurfaceManagerGui.h +++ b/src/Surfaces/SurfaceManagerGui.h @@ -16,6 +16,7 @@ #include "SelSurfaceCmd.h" #include "MvSurfaceVertCmd.h" #include "MvAllTexCoordsCmd.h" +#include "MvTexCoordCmd.h" namespace ofx { namespace piMapper { diff --git a/src/UserInterface/TextureEditor.cpp b/src/UserInterface/TextureEditor.cpp index 9e409a4..8d80668 100755 --- a/src/UserInterface/TextureEditor.cpp +++ b/src/UserInterface/TextureEditor.cpp @@ -230,5 +230,10 @@ CircleJoint* TextureEditor::hitTestJoints(ofVec2f pos) { } return NULL; } + + vector & TextureEditor::getJoints(){ + return joints; + } + } } \ No newline at end of file diff --git a/src/UserInterface/TextureEditor.h b/src/UserInterface/TextureEditor.h index 5e49a12..e09bfdf 100644 --- a/src/UserInterface/TextureEditor.h +++ b/src/UserInterface/TextureEditor.h @@ -34,6 +34,7 @@ class TextureEditor { void moveSelection(ofVec2f by); void constrainJointsToQuad(int selectedJointIndex); CircleJoint* hitTestJoints(ofVec2f pos); + vector & getJoints(); private: BaseSurface* surface;