diff --git a/example/example.xcodeproj/project.pbxproj b/example/example.xcodeproj/project.pbxproj index 7ad9003..5035830 100644 --- a/example/example.xcodeproj/project.pbxproj +++ b/example/example.xcodeproj/project.pbxproj @@ -8,6 +8,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 */; }; 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 */; }; @@ -123,6 +124,8 @@ /* Begin PBXFileReference section */ 391717ED1B08FFDA00F9A484 /* SetGuiModeCmd.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SetGuiModeCmd.cpp; path = Commands/SetGuiModeCmd.cpp; sourceTree = ""; }; 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 = ""; }; 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 = ""; }; @@ -664,6 +667,8 @@ 39A9AADE1B04E78600AA83BC /* RmSurfaceCmd.cpp */, 391717EE1B08FFDA00F9A484 /* SetGuiModeCmd.h */, 391717ED1B08FFDA00F9A484 /* SetGuiModeCmd.cpp */, + 391717F21B0A8A7300F9A484 /* MvAllTexCoordsCmd.h */, + 391717F11B0A8A7300F9A484 /* MvAllTexCoordsCmd.cpp */, ); name = Commands; sourceTree = ""; @@ -886,6 +891,7 @@ 39C1244A19EE9589005DF557 /* snappy-stubs-internal.cc in Sources */, 39C1245F19F08965005DF557 /* VideoSource.cpp in Sources */, 39C1244119EE9589005DF557 /* HexBinaryEncoding.cpp in Sources */, + 391717F31B0A8A7300F9A484 /* MvAllTexCoordsCmd.cpp in Sources */, 397EFC7C1A08E7680009286E /* ofxPiMapper.cpp in Sources */, 39C1244219EE9589005DF557 /* HiddenFileFilter.cpp in Sources */, 39C1244819EE9589005DF557 /* SearchPath.cpp in Sources */, diff --git a/src/Commands/MvAllTexCoordsCmd.cpp b/src/Commands/MvAllTexCoordsCmd.cpp new file mode 100644 index 0000000..1b29e06 --- /dev/null +++ b/src/Commands/MvAllTexCoordsCmd.cpp @@ -0,0 +1,27 @@ +#include "MvAllTexCoordsCmd.h" + +namespace ofx{ + namespace piMapper{ + + MvAllTexCoordsCmd::MvAllTexCoordsCmd(BaseSurface * surface, TextureEditor * texEditor){ + _surface = surface; + _texEditor = texEditor; + } + + void MvAllTexCoordsCmd::exec(){ + ofLogNotice("MvAllTexCoordsCmd", "exec"); + _texCoords = _surface->getTexCoords(); + } + + void MvAllTexCoordsCmd::undo(){ + ofLogNotice("MvAllTexCoordsCmd", "undo"); + ofVec2f dist = _texCoords[0] - _surface->getTexCoords()[0]; + dist.x = _surface->getSource()->getTexture()->getWidth() * dist.x; + dist.y = _surface->getSource()->getTexture()->getHeight() * dist.y; + _texEditor->moveTexCoords(dist); + _surface = 0; + } + + } // namespace piMapper +} // namespace ofx + diff --git a/src/Commands/MvAllTexCoordsCmd.h b/src/Commands/MvAllTexCoordsCmd.h new file mode 100644 index 0000000..1d5f972 --- /dev/null +++ b/src/Commands/MvAllTexCoordsCmd.h @@ -0,0 +1,29 @@ +// MvAllTexCoordsCmd +// Move all texture coordinates of a selected surface undoable command +// Created by Krisjanis Rijnieks 2015-05-15 + +#pragma once + +#include "BaseCmd.h" +#include "BaseSurface.h" +#include "TextureEditor.h" + +namespace ofx{ + namespace piMapper{ + + class MvAllTexCoordsCmd : public BaseUndoCmd{ + + public: + MvAllTexCoordsCmd(BaseSurface * surface, TextureEditor * texEditor); + void exec(); + void undo(); + + private: + vector _texCoords; + BaseSurface * _surface; + TextureEditor * _texEditor; + }; + + } // namespace piMapper +} // namespace ofx + diff --git a/src/Surfaces/SurfaceManagerGui.cpp b/src/Surfaces/SurfaceManagerGui.cpp index daf2b2e..d1f7d3b 100644 --- a/src/Surfaces/SurfaceManagerGui.cpp +++ b/src/Surfaces/SurfaceManagerGui.cpp @@ -91,6 +91,8 @@ 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; @@ -101,9 +103,16 @@ namespace ofx { 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)) { + args.x, args.y)) { + + // TODO: move these to a separate routine clickPosition = ofVec2f(args.x, args.y); startDrag(); + + _cmdManager->exec(new MvAllTexCoordsCmd( + surfaceManager->getSelectedSurface(), + &textureEditor)); + } } diff --git a/src/Surfaces/SurfaceManagerGui.h b/src/Surfaces/SurfaceManagerGui.h index c76c48b..f23230c 100644 --- a/src/Surfaces/SurfaceManagerGui.h +++ b/src/Surfaces/SurfaceManagerGui.h @@ -15,6 +15,7 @@ #include "MvSurfaceCmd.h" #include "SelSurfaceCmd.h" #include "MvSurfaceVertCmd.h" +#include "MvAllTexCoordsCmd.h" namespace ofx { namespace piMapper {