From 81885d72df1919fe7c93d5f480a0732b1493ff33 Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Sun, 28 Aug 2016 10:46:36 +0200 Subject: [PATCH] Improve ClearSurfaceCmd with surface deselection --- src/Application/Application.cpp | 12 ++++++++++++ src/Application/Application.h | 3 +++ src/Commands/ClearSurfacesCmd.cpp | 6 +++++- src/Commands/ClearSurfacesCmd.h | 5 ++++- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/Application/Application.cpp b/src/Application/Application.cpp index 6c8819c..02a2d46 100644 --- a/src/Application/Application.cpp +++ b/src/Application/Application.cpp @@ -5,6 +5,8 @@ namespace ofx { namespace piMapper { Application::Application(){ + _keySequence = ""; + _surfaceManager.setMediaServer(&_mediaServer); _gui.setMediaServer(&_mediaServer); _gui.setCmdManager(&_cmdManager); @@ -55,6 +57,16 @@ void Application::draw(){ // Here we handle application state changes only void Application::onKeyPressed(ofKeyEventArgs & args){ + + // Key sequence based commands. Last three keys are taken into account. + _keySequence += args.key; + if(_keySequence.size() >= 3){ + _keySequence = _keySequence.substr(_keySequence.size() - 3, 3); + if(_keySequence == "new"){ + _cmdManager.exec(new ClearSurfacesCmd()); + return; + } + } // For now we set the state of the new system and also the old // before it is completely ported to the state system. diff --git a/src/Application/Application.h b/src/Application/Application.h index c44b395..f3bf50c 100644 --- a/src/Application/Application.h +++ b/src/Application/Application.h @@ -4,6 +4,7 @@ #include "ofLog.h" #include "SetApplicationStateCmd.h" +#include "ClearSurfacesCmd.h" #include "ApplicationBaseState.h" #include "PresentationState.h" @@ -84,6 +85,8 @@ class Application : public KeyListener { bool _shiftKeyDown; bool _isSSHConnection; + + string _keySequence; }; diff --git a/src/Commands/ClearSurfacesCmd.cpp b/src/Commands/ClearSurfacesCmd.cpp index 96246b4..1aad483 100644 --- a/src/Commands/ClearSurfacesCmd.cpp +++ b/src/Commands/ClearSurfacesCmd.cpp @@ -3,11 +3,14 @@ namespace ofx { namespace piMapper { -ClearSurfacesCmd::ClearSurfacesCmd(){ +ClearSurfacesCmd::ClearSurfacesCmd(SurfaceManager * sm){ + _surfaceManager = sm; + _selectedSurface = _surfaceManager->getSelectedSurface(); _surfaces = SurfaceStack::instance()->getSurfaces(); } void ClearSurfacesCmd::exec(){ + _surfaceManager->deselectSurface(); SurfaceStack::instance()->clear(); } @@ -16,6 +19,7 @@ void ClearSurfacesCmd::undo(){ for(unsigned int i = 0; i < _surfaces.size(); ++i){ SurfaceStack::instance()->push_back(_surfaces[i]); } + _surfaceManager->selectSurface(_selectedSurface); } } // namespace piMapper diff --git a/src/Commands/ClearSurfacesCmd.h b/src/Commands/ClearSurfacesCmd.h index 458539e..c24f603 100644 --- a/src/Commands/ClearSurfacesCmd.h +++ b/src/Commands/ClearSurfacesCmd.h @@ -7,6 +7,7 @@ #include "BaseCmd.h" #include "BaseSurface.h" #include "SurfaceStack.h" +#include "SurfaceManager.h" #include "Gui.h" namespace ofx { @@ -15,13 +16,15 @@ namespace piMapper { class ClearSurfacesCmd : public BaseUndoCmd { public: - ClearSurfacesCmd(); + ClearSurfacesCmd(SurfaceManager * sm); void exec(); void undo(); private: // Here it would make sense to have another instance of SurfaceStack vector _surfaces; + SurfaceManager * _surfaceManager; + BaseSurface * _selectedSurface; };