From ac32484445717a010fdb17bc0f4092ce79a466a3 Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Wed, 24 Aug 2016 21:04:20 +0300 Subject: [PATCH] Add ScaleSurfaceFromToCmd and integrate it --- example/example.xcodeproj/project.pbxproj | 6 +++++ src/Application/GuiBaseWidget.h | 2 +- src/Application/ProjectionMappingState.cpp | 20 +++++++++++++---- src/Application/ProjectionMappingState.h | 5 +++++ src/Application/ScaleWidget.cpp | 2 +- src/Application/ScaleWidget.h | 4 ++-- src/Commands/ScaleSurfaceFromToCmd.cpp | 24 ++++++++++++++++++++ src/Commands/ScaleSurfaceFromToCmd.h | 26 ++++++++++++++++++++++ 8 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 src/Commands/ScaleSurfaceFromToCmd.cpp create mode 100644 src/Commands/ScaleSurfaceFromToCmd.h diff --git a/example/example.xcodeproj/project.pbxproj b/example/example.xcodeproj/project.pbxproj index 2432f4e..8488519 100644 --- a/example/example.xcodeproj/project.pbxproj +++ b/example/example.xcodeproj/project.pbxproj @@ -40,6 +40,7 @@ 0130C9831CE65AA600911E17 /* snappy-stubs-internal.cc in Sources */ = {isa = PBXBuildFile; fileRef = 0130C94B1CE65AA600911E17 /* snappy-stubs-internal.cc */; }; 0130C9841CE65AA600911E17 /* snappy.cc in Sources */ = {isa = PBXBuildFile; fileRef = 0130C94E1CE65AA600911E17 /* snappy.cc */; }; 0177D5511D0B05230096A920 /* ToggleAnimatedSourceCmd.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0177D5501D0B05230096A920 /* ToggleAnimatedSourceCmd.cpp */; }; + 01CD67871D6E15ED00CAE633 /* ScaleSurfaceFromToCmd.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 01CD67861D6E15ED00CAE633 /* ScaleSurfaceFromToCmd.cpp */; }; 01F9EB1D1D624702009CA5E8 /* MvLayerDnCmd.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 01F9EB1B1D624702009CA5E8 /* MvLayerDnCmd.cpp */; }; 01F9EB1E1D624702009CA5E8 /* MvLayerUpCmd.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 01F9EB1C1D624702009CA5E8 /* MvLayerUpCmd.cpp */; }; 391717EF1B08FFDA00F9A484 /* SetApplicationStateCmd.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 391717ED1B08FFDA00F9A484 /* SetApplicationStateCmd.cpp */; }; @@ -240,6 +241,8 @@ 0130C95B1CE65AA600911E17 /* ofxIO.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ofxIO.h; sourceTree = ""; }; 0177D54F1D0B05230096A920 /* ToggleAnimatedSourceCmd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ToggleAnimatedSourceCmd.h; path = Commands/ToggleAnimatedSourceCmd.h; sourceTree = ""; }; 0177D5501D0B05230096A920 /* ToggleAnimatedSourceCmd.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ToggleAnimatedSourceCmd.cpp; path = Commands/ToggleAnimatedSourceCmd.cpp; sourceTree = ""; }; + 01CD67851D6E15ED00CAE633 /* ScaleSurfaceFromToCmd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ScaleSurfaceFromToCmd.h; path = Commands/ScaleSurfaceFromToCmd.h; sourceTree = ""; }; + 01CD67861D6E15ED00CAE633 /* ScaleSurfaceFromToCmd.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ScaleSurfaceFromToCmd.cpp; path = Commands/ScaleSurfaceFromToCmd.cpp; sourceTree = ""; }; 01F9EB191D624702009CA5E8 /* MvLayerDnCmd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MvLayerDnCmd.h; path = Commands/MvLayerDnCmd.h; sourceTree = ""; }; 01F9EB1A1D624702009CA5E8 /* MvLayerUpCmd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MvLayerUpCmd.h; path = Commands/MvLayerUpCmd.h; sourceTree = ""; }; 01F9EB1B1D624702009CA5E8 /* MvLayerDnCmd.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MvLayerDnCmd.cpp; path = Commands/MvLayerDnCmd.cpp; sourceTree = ""; }; @@ -928,6 +931,8 @@ 0117D7091D64EBB4008FECEB /* ScaleSurfaceUpCmd.cpp */, 0117D7061D64EBB4008FECEB /* ScaleSurfaceDnCmd.h */, 0117D7081D64EBB4008FECEB /* ScaleSurfaceDnCmd.cpp */, + 01CD67851D6E15ED00CAE633 /* ScaleSurfaceFromToCmd.h */, + 01CD67861D6E15ED00CAE633 /* ScaleSurfaceFromToCmd.cpp */, ); name = Commands; sourceTree = ""; @@ -1216,6 +1221,7 @@ 392651711C5429C600C54844 /* HomographyHelper.cpp in Sources */, 39C1247D19F187D5005DF557 /* CircleJoint.cpp in Sources */, 39264842192224F90008A7F5 /* tinyxmlerror.cpp in Sources */, + 01CD67871D6E15ED00CAE633 /* ScaleSurfaceFromToCmd.cpp in Sources */, 3926483B192224DA0008A7F5 /* ofxXmlSettings.cpp in Sources */, 0130C9681CE65AA600911E17 /* README.md in Sources */, 39C1245119EE95DD005DF557 /* DirectoryWatcher.cpp in Sources */, diff --git a/src/Application/GuiBaseWidget.h b/src/Application/GuiBaseWidget.h index b16da44..b553e41 100644 --- a/src/Application/GuiBaseWidget.h +++ b/src/Application/GuiBaseWidget.h @@ -20,7 +20,7 @@ class GuiBaseWidget { virtual void onMouseDragged(ofMouseEventArgs & e) = 0; virtual bool inside(float x, float y) = 0; - + virtual float getScale(){} ofEvent guiWidgetEvent; diff --git a/src/Application/ProjectionMappingState.cpp b/src/Application/ProjectionMappingState.cpp index aa713c8..4024ccc 100644 --- a/src/Application/ProjectionMappingState.cpp +++ b/src/Application/ProjectionMappingState.cpp @@ -3,6 +3,10 @@ namespace ofx { namespace piMapper { +ProjectionMappingState::ProjectionMappingState(){ + _surfaceScaleBeforeTransform = 1.0f; +} + ProjectionMappingState * ProjectionMappingState::_instance = 0; ProjectionMappingState * ProjectionMappingState::instance(){ @@ -337,14 +341,22 @@ void ProjectionMappingState::onBackgroundPressed(Application * app, GuiBackgroun } void ProjectionMappingState::onGuiEvent(Application * app, GuiEvent & e){ + + // Scale widget now. More later. if(e.widget == &Gui::instance()->getScaleWidget()){ if(e.args.type == e.args.Pressed){ - cout << "Scale Pressed" << endl; + _surfaceScaleBeforeTransform = + app->getSurfaceManager()->getSelectedSurface()->getScale(); }else if(e.args.type == e.args.Released){ - cout << "Scale Released" << endl; + if(_surfaceScaleBeforeTransform != + app->getSurfaceManager()->getSelectedSurface()->getScale()){ + + app->getCmdManager()->exec(new ScaleSurfaceFromToCmd( + app->getSurfaceManager()->getSelectedSurface(), + _surfaceScaleBeforeTransform, + app->getSurfaceManager()->getSelectedSurface()->getScale())); + } }else if(e.args.type == e.args.Dragged){ - cout << "Scale Dragged" << endl; - cout << "Scale: " << e.widget->getScale() << endl; app->getSurfaceManager()->getSelectedSurface()->scaleTo(e.widget->getScale()); } } diff --git a/src/Application/ProjectionMappingState.h b/src/Application/ProjectionMappingState.h index c806f8f..5071b4b 100644 --- a/src/Application/ProjectionMappingState.h +++ b/src/Application/ProjectionMappingState.h @@ -27,6 +27,7 @@ #include "MvLayerDnCmd.h" #include "ScaleSurfaceUpCmd.h" #include "ScaleSurfaceDnCmd.h" +#include "ScaleSurfaceFromToCmd.h" #include "SurfaceType.h" #include "Gui.h" @@ -52,8 +53,12 @@ class ProjectionMappingState : public ApplicationBaseState { void onGuiEvent(Application * app, GuiEvent & e); private: + ProjectionMappingState(); + static ProjectionMappingState * _instance; + float _surfaceScaleBeforeTransform; + }; } // namespace piMapper diff --git a/src/Application/ScaleWidget.cpp b/src/Application/ScaleWidget.cpp index 5354f0f..ff268bc 100644 --- a/src/Application/ScaleWidget.cpp +++ b/src/Application/ScaleWidget.cpp @@ -9,7 +9,7 @@ ScaleWidget::ScaleWidget(){ _handle.width = 20; _handle.height = 20; - + _scale = 1.0f; _surface = 0; } diff --git a/src/Application/ScaleWidget.h b/src/Application/ScaleWidget.h index 146ad50..39b7ee6 100644 --- a/src/Application/ScaleWidget.h +++ b/src/Application/ScaleWidget.h @@ -25,7 +25,7 @@ class ScaleWidget : public GuiBaseWidget { // This should be the size of the objet's bounding box void setSurface(BaseSurface * s); - + float getScale(){ return _scale; } @@ -34,7 +34,7 @@ class ScaleWidget : public GuiBaseWidget { ofRectangle _handle; ofPolyline _line; - + float _scale; bool _dragging; diff --git a/src/Commands/ScaleSurfaceFromToCmd.cpp b/src/Commands/ScaleSurfaceFromToCmd.cpp new file mode 100644 index 0000000..03f909a --- /dev/null +++ b/src/Commands/ScaleSurfaceFromToCmd.cpp @@ -0,0 +1,24 @@ +#include "ScaleSurfaceFromToCmd.h" + +namespace ofx { +namespace piMapper { + +ScaleSurfaceFromToCmd::ScaleSurfaceFromToCmd(BaseSurface * selectedSurface, float from, float to){ + _selectedSurface = selectedSurface; + _scaleFrom = from; + _scaleTo = to; +} + +void ScaleSurfaceFromToCmd::exec(){ + ofLogNotice("ScaleSurfaceFromToCmd", "exec"); + _selectedSurface->scaleTo(_scaleTo); +} + +void ScaleSurfaceFromToCmd::undo(){ + ofLogNotice("ScaleSurfaceFromToCmd", "undo"); + _selectedSurface->scaleTo(_scaleFrom); +} + +} // namespace piMapper +} // namespace ofx + diff --git a/src/Commands/ScaleSurfaceFromToCmd.h b/src/Commands/ScaleSurfaceFromToCmd.h new file mode 100644 index 0000000..20ac959 --- /dev/null +++ b/src/Commands/ScaleSurfaceFromToCmd.h @@ -0,0 +1,26 @@ +#pragma once + +#include "BaseCmd.h" +#include "BaseSurface.h" + +namespace ofx { +namespace piMapper { + +class ScaleSurfaceFromToCmd : public BaseUndoCmd { + + public: + ScaleSurfaceFromToCmd(BaseSurface * selectedSurface, float from, float to); + void exec(); + void undo(); + + private: + BaseSurface * _selectedSurface; + + float _scaleFrom; + float _scaleTo; + +}; + +} // namespace piMapper +} // namespace ofx +