From c69ca799b4ffea1c437e798b0bf07e421f9e34b4 Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Sun, 17 May 2015 20:18:23 +0300 Subject: [PATCH] Add gui mode/state switch undo command --- example/example.xcodeproj/project.pbxproj | 6 +++++ src/Commands/SetGuiModeCmd.cpp | 24 +++++++++++++++++++ src/Commands/SetGuiModeCmd.h | 28 +++++++++++++++++++++++ src/Surfaces/SurfaceManagerGui.cpp | 4 ++++ src/Surfaces/SurfaceManagerGui.h | 1 + src/ofxPiMapper.cpp | 20 ++++++++++++---- src/ofxPiMapper.h | 1 + 7 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 src/Commands/SetGuiModeCmd.cpp create mode 100644 src/Commands/SetGuiModeCmd.h diff --git a/example/example.xcodeproj/project.pbxproj b/example/example.xcodeproj/project.pbxproj index d9dfcd7..7ad9003 100644 --- a/example/example.xcodeproj/project.pbxproj +++ b/example/example.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 391717EF1B08FFDA00F9A484 /* SetGuiModeCmd.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 391717ED1B08FFDA00F9A484 /* SetGuiModeCmd.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 */; }; @@ -120,6 +121,8 @@ /* End PBXCopyFilesBuildPhase section */ /* 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 = ""; }; 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 = ""; }; @@ -659,6 +662,8 @@ 39A9AAE71B0518FC00AA83BC /* MvSurfaceCmd.cpp */, 39A9AADF1B04E78600AA83BC /* RmSurfaceCmd.h */, 39A9AADE1B04E78600AA83BC /* RmSurfaceCmd.cpp */, + 391717EE1B08FFDA00F9A484 /* SetGuiModeCmd.h */, + 391717ED1B08FFDA00F9A484 /* SetGuiModeCmd.cpp */, ); name = Commands; sourceTree = ""; @@ -885,6 +890,7 @@ 39C1244219EE9589005DF557 /* HiddenFileFilter.cpp in Sources */, 39C1244819EE9589005DF557 /* SearchPath.cpp in Sources */, 39C1248019F187D5005DF557 /* SourcesEditor.cpp in Sources */, + 391717EF1B08FFDA00F9A484 /* SetGuiModeCmd.cpp in Sources */, 39C1243F19EE9589005DF557 /* DirectoryWatcherManager.cpp in Sources */, 39C1243519EE9589005DF557 /* ByteBuffer.cpp in Sources */, 39C1246B19F0AB96005DF557 /* TriangleSurface.cpp in Sources */, diff --git a/src/Commands/SetGuiModeCmd.cpp b/src/Commands/SetGuiModeCmd.cpp new file mode 100644 index 0000000..20a27b3 --- /dev/null +++ b/src/Commands/SetGuiModeCmd.cpp @@ -0,0 +1,24 @@ +#include "SetGuiModeCmd.h" + +namespace ofx{ + namespace piMapper{ + + SetGuiModeCmd::SetGuiModeCmd(SurfaceManagerGui * gui, int mode){ + _gui = gui; + _prevGuiMode = -1; + _mode = mode; + } + + void SetGuiModeCmd::exec(){ + _prevGuiMode = _gui->getMode(); + _gui->setMode(_mode); + } + + void SetGuiModeCmd::undo(){ + ofLogNotice("SetGuiModeCmd", "undo"); + _gui->setMode(_prevGuiMode); + } + + } // namespace piMapper +} // namespace ofx + diff --git a/src/Commands/SetGuiModeCmd.h b/src/Commands/SetGuiModeCmd.h new file mode 100644 index 0000000..f397a13 --- /dev/null +++ b/src/Commands/SetGuiModeCmd.h @@ -0,0 +1,28 @@ +// SetGuiModeCmd +// Provides undo operation for setting the GUI mode/state +// Created by Krisjanis Rijnieks 2015-05-14 + +#pragma once + +#include "SurfaceManagerGui.h" +#include "BaseCmd.h" + +namespace ofx{ + namespace piMapper{ + + class SetGuiModeCmd : public BaseUndoCmd{ + + public: + SetGuiModeCmd(SurfaceManagerGui * gui, int mode); + void exec(); + void undo(); + + private: + SurfaceManagerGui * _gui; + int _prevGuiMode; + int _mode; + }; + + } // namespace piMapper +} // namespace ofx + diff --git a/src/Surfaces/SurfaceManagerGui.cpp b/src/Surfaces/SurfaceManagerGui.cpp index 88c340a..daf2b2e 100644 --- a/src/Surfaces/SurfaceManagerGui.cpp +++ b/src/Surfaces/SurfaceManagerGui.cpp @@ -254,6 +254,10 @@ namespace ofx { } } + int SurfaceManagerGui::getMode(){ + return guiMode; + } + void SurfaceManagerGui::drawSelectedSurfaceHighlight() { if (surfaceManager->getSelectedSurface() == NULL) return; ofPolyline line = surfaceManager->getSelectedSurface()->getHitArea(); diff --git a/src/Surfaces/SurfaceManagerGui.h b/src/Surfaces/SurfaceManagerGui.h index 64c09a3..c76c48b 100644 --- a/src/Surfaces/SurfaceManagerGui.h +++ b/src/Surfaces/SurfaceManagerGui.h @@ -36,6 +36,7 @@ namespace ofx { void setCmdManager(CmdManager * cmdManager); void setMode(int newGuiMode); + int getMode(); void drawSelectedSurfaceHighlight(); void drawSelectedSurfaceTextureHighlight(); void startDrag(); diff --git a/src/ofxPiMapper.cpp b/src/ofxPiMapper.cpp index 402b6be..a35c197 100644 --- a/src/ofxPiMapper.cpp +++ b/src/ofxPiMapper.cpp @@ -72,16 +72,28 @@ void ofxPiMapper::keyPressed(ofKeyEventArgs &args){ switch (args.key) { case '1': - gui.setMode(ofx::piMapper::GuiMode::NONE); + if (gui.getMode() != ofx::piMapper::GuiMode::NONE) { + cmdManager.exec(new ofx::piMapper::SetGuiModeCmd(&gui, + ofx::piMapper::GuiMode::NONE)); + } break; case '2': - gui.setMode(ofx::piMapper::GuiMode::TEXTURE_MAPPING); + if (gui.getMode() != ofx::piMapper::GuiMode::TEXTURE_MAPPING) { + cmdManager.exec(new ofx::piMapper::SetGuiModeCmd(&gui, + ofx::piMapper::GuiMode::TEXTURE_MAPPING)); + } break; case '3': - gui.setMode(ofx::piMapper::GuiMode::PROJECTION_MAPPING); + if (gui.getMode() != ofx::piMapper::GuiMode::PROJECTION_MAPPING) { + cmdManager.exec(new ofx::piMapper::SetGuiModeCmd(&gui, + ofx::piMapper::GuiMode::PROJECTION_MAPPING)); + } break; case '4': - gui.setMode(ofx::piMapper::GuiMode::SOURCE_SELECTION); + if (gui.getMode() != ofx::piMapper::GuiMode::SOURCE_SELECTION) { + cmdManager.exec(new ofx::piMapper::SetGuiModeCmd(&gui, + ofx::piMapper::GuiMode::SOURCE_SELECTION)); + } break; case 'i': bShowInfo = !bShowInfo; diff --git a/src/ofxPiMapper.h b/src/ofxPiMapper.h index 7e3ce4c..29a4291 100644 --- a/src/ofxPiMapper.h +++ b/src/ofxPiMapper.h @@ -16,6 +16,7 @@ #include "BaseCmd.h" #include "CmdManager.h" #include "RmSurfaceCmd.h" +#include "SetGuiModeCmd.h" #define PIMAPPER_DEF_SURFACES_XML_FILE "defaultSurfaces.xml" #define PIMAPPER_USER_SURFACES_XML_FILE "surfaces.xml"