From 9996554b2f4df60d033174b69fd9361891c500b7 Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Sat, 28 Jan 2017 18:26:05 +0100 Subject: [PATCH] Move surface command executors to Application --- src/Application/Application.cpp | 50 ++++++++++++ src/Application/Application.h | 14 ++++ src/Application/Modes/ApplicationBaseMode.h | 8 -- .../Modes/ProjectionMappingMode.cpp | 78 ++++--------------- src/Application/Modes/ProjectionMappingMode.h | 16 ---- src/ofxPiMapper.cpp | 12 +-- 6 files changed, 83 insertions(+), 95 deletions(-) diff --git a/src/Application/Application.cpp b/src/Application/Application.cpp index ec7205b..cb7c995 100644 --- a/src/Application/Application.cpp +++ b/src/Application/Application.cpp @@ -308,6 +308,56 @@ bool Application::loadXmlSettings(string fileName){ return true; } +void Application::selectSurface(int i){ + if(getSurfaceManager()->size()){ + if(getSurfaceManager()->getSelectedSurfaceIndex() == i){ + return; + } + getCmdManager()->exec( + new SelSurfaceCmd( + getSurfaceManager(), + getSurfaceManager()->getSurface(i))); + } +} + +void Application::selectNextSurface(){ + if(getSurfaceManager()->size()){ + if(getSurfaceManager()->size() == 1 && + getSurfaceManager()->getSelectedSurface() == + getSurfaceManager()->getSurface(0)){ + return; + } + getCmdManager()->exec(new SelNextSurfaceCmd(getSurfaceManager())); + } +} + +void Application::selectPrevSurface(){ + if(getSurfaceManager()->size()){ + if(getSurfaceManager()->size() == 1 && + getSurfaceManager()->getSelectedSurface() == + getSurfaceManager()->getSurface(0)){ + return; + } + getCmdManager()->exec(new SelPrevSurfaceCmd(getSurfaceManager())); + } +} + +void Application::selectNextVertex(){ + if(getSurfaceManager()->getSelectedSurface() != 0){ + getCmdManager()->exec(new SelNextVertexCmd(getSurfaceManager())); + } +} + +void Application::selectPrevVertex(){ + if(getSurfaceManager()->getSelectedSurface() != 0){ + getCmdManager()->exec(new SelPrevVertexCmd(getSurfaceManager())); + } +} + +void Application::moveSelection(ofVec2f by){ + getCmdManager()->exec(new MvSelectionCmd(getSurfaceManager(), by)); +} + void Application::setPresentationMode(){ _cmdManager.exec( new ofx::piMapper::SetApplicationModeCmd( diff --git a/src/Application/Application.h b/src/Application/Application.h index ca0f258..28e2652 100644 --- a/src/Application/Application.h +++ b/src/Application/Application.h @@ -27,6 +27,13 @@ #include "RmGridRowCmd.h" #include "AddGridColCmd.h" #include "RmGridColCmd.h" +#include "SelNextSurfaceCmd.h" +#include "SelPrevSurfaceCmd.h" +#include "SelNextVertexCmd.h" +#include "SelPrevVertexCmd.h" +#include "SelVertexCmd.h" +#include "SelSurfaceCmd.h" +#include "MvSelectionCmd.h" // Modes #include "ApplicationBaseMode.h" @@ -92,6 +99,13 @@ class Application : public KeyListener { TerminalListener consoleListener; // Command executors + void selectSurface(int i); + void selectNextSurface(); + void selectPrevSurface(); + void selectNextVertex(); + void selectPrevVertex(); + void moveSelection(ofVec2f by); + void setPresentationMode(); void setTextureMode(); void setProjectionMode(); diff --git a/src/Application/Modes/ApplicationBaseMode.h b/src/Application/Modes/ApplicationBaseMode.h index b809b04..c454e52 100644 --- a/src/Application/Modes/ApplicationBaseMode.h +++ b/src/Application/Modes/ApplicationBaseMode.h @@ -31,14 +31,6 @@ class ApplicationBaseMode { // These are only used by TextureMappingMode for now. virtual ofPoint getTranslation(){ return ofPoint(0, 0); } virtual void setTranslation(ofPoint p){} - - // Undoable public methods - virtual void selectSurface(Application * app, int i){} - virtual void selectNextSurface(Application * app){} - virtual void selectPrevSurface(Application * app){} - virtual void selectNextVertex(Application * app){} - virtual void selectPrevVertex(Application * app){} - virtual void moveSelection(Application * app, ofVec2f by){} }; diff --git a/src/Application/Modes/ProjectionMappingMode.cpp b/src/Application/Modes/ProjectionMappingMode.cpp index b015ecf..afe916b 100644 --- a/src/Application/Modes/ProjectionMappingMode.cpp +++ b/src/Application/Modes/ProjectionMappingMode.cpp @@ -93,50 +93,50 @@ void ProjectionMappingMode::onKeyPressed(Application * app, ofKeyEventArgs & arg break; case '.': - selectNextSurface(app); + app->selectNextSurface(); break; case ',': - selectPrevSurface(app); + app->selectPrevSurface(); break; case '>': - selectNextVertex(app); + app->selectNextVertex(); break; case '<': - selectPrevVertex(app); + app->selectPrevVertex(); break; case OF_KEY_UP: if(app->isShiftKeyDown()){ - moveSelection(app, ofVec2f(0.0f, -10.0f)); + app->moveSelection(ofVec2f(0.0f, -10.0f)); }else{ - moveSelection(app, ofVec2f(0.0f, -1.0f)); + app->moveSelection(ofVec2f(0.0f, -1.0f)); } break; case OF_KEY_DOWN: if(app->isShiftKeyDown()){ - moveSelection(app, ofVec2f(0.0f, 10.0f)); + app->moveSelection(ofVec2f(0.0f, 10.0f)); }else{ - moveSelection(app, ofVec2f(0.0f, 1.0f)); + app->moveSelection(ofVec2f(0.0f, 1.0f)); } break; case OF_KEY_LEFT: if(app->isShiftKeyDown()){ - moveSelection(app, ofVec2f(-10.0f, 0.0f)); + app->moveSelection(ofVec2f(-10.0f, 0.0f)); }else{ - moveSelection(app, ofVec2f(-1.0f, 0.0f)); + app->moveSelection(ofVec2f(-1.0f, 0.0f)); } break; case OF_KEY_RIGHT: if(app->isShiftKeyDown()){ - moveSelection(app, ofVec2f(10.0f, 0.0f)); + app->moveSelection(ofVec2f(10.0f, 0.0f)); }else{ - moveSelection(app, ofVec2f(1.0f, 0.0f)); + app->moveSelection(ofVec2f(1.0f, 0.0f)); } break; @@ -239,7 +239,7 @@ void ProjectionMappingMode::onMouseReleased(Application * app, ofMouseEventArgs Gui::instance()->getProjectionEditorWidget().stopDragJoints(); } -void ProjectionMappingMode::onMouseDragged(Application * app, ofMouseEventArgs & args){ +void ProjectionMappingMode::onMouseDragged(Application * app, ofMouseEventArgs & args){ Gui::instance()->onMouseDragged(args); Gui::instance()->getProjectionEditorWidget().mouseDragged(args); @@ -303,57 +303,5 @@ void ProjectionMappingMode::onGuiEvent(Application * app, GuiEvent & e){ } } -void ProjectionMappingMode::selectSurface(Application * app, int i){ - if(app->getSurfaceManager()->size()){ - if(app->getSurfaceManager()->getSelectedSurfaceIndex() == i){ - return; - } - app->getCmdManager()->exec( - new SelSurfaceCmd( - app->getSurfaceManager(), - app->getSurfaceManager()->getSurface(i) )); - } -} - -void ProjectionMappingMode::selectNextSurface(Application * app){ - if(app->getSurfaceManager()->size()){ - if( app->getSurfaceManager()->size() == 1 && - app->getSurfaceManager()->getSelectedSurface() == - app->getSurfaceManager()->getSurface(0)){ - return; - } - app->getCmdManager()->exec(new SelNextSurfaceCmd(app->getSurfaceManager())); - } -} - -void ProjectionMappingMode::selectPrevSurface(Application * app){ - if(app->getSurfaceManager()->size()){ - if( app->getSurfaceManager()->size() == 1 && - app->getSurfaceManager()->getSelectedSurface() == - app->getSurfaceManager()->getSurface(0)){ - return; - } - app->getCmdManager()->exec(new SelPrevSurfaceCmd(app->getSurfaceManager())); - } -} - -void ProjectionMappingMode::selectNextVertex(Application * app){ - if(app->getSurfaceManager()->getSelectedSurface() != 0){ - app->getCmdManager()->exec(new SelNextVertexCmd(app->getSurfaceManager())); - } -} - -void ProjectionMappingMode::selectPrevVertex(Application * app){ - if(app->getSurfaceManager()->getSelectedSurface() != 0){ - app->getCmdManager()->exec(new SelPrevVertexCmd(app->getSurfaceManager())); - } -} - -void ProjectionMappingMode::moveSelection(Application * app, ofVec2f by){ - app->getCmdManager()->exec( - new MvSelectionCmd( - app->getSurfaceManager(), by)); -} - } // namespace piMapper } // namespace ofx \ No newline at end of file diff --git a/src/Application/Modes/ProjectionMappingMode.h b/src/Application/Modes/ProjectionMappingMode.h index e082180..c739aec 100644 --- a/src/Application/Modes/ProjectionMappingMode.h +++ b/src/Application/Modes/ProjectionMappingMode.h @@ -3,20 +3,12 @@ #include "Application.h" #include "ofLog.h" #include "ofGraphics.h" -#include "SelNextSurfaceCmd.h" -#include "SelPrevSurfaceCmd.h" -#include "SelNextVertexCmd.h" -#include "SelPrevVertexCmd.h" -#include "SelVertexCmd.h" -#include "SelSurfaceCmd.h" -#include "MvSelectionCmd.h" #include "StartDragSurfaceCmd.h" #include "DeselectSurfaceCmd.h" #include "ToggleAnimatedSourceCmd.h" #include "MvSurfaceVertCmd.h" #include "SurfaceType.h" #include "Gui.h" - #include "ScaleWidget.h" namespace ofx { @@ -39,14 +31,6 @@ class ProjectionMappingMode : public ApplicationBaseMode { void onBackgroundPressed(Application * app, GuiBackgroundEvent & e); void onGuiEvent(Application * app, GuiEvent & e); - - // Undoable public methods - void selectSurface(Application * app, int i); - void selectNextSurface(Application * app); - void selectPrevSurface(Application * app); - void selectNextVertex(Application * app); - void selectPrevVertex(Application * app); - void moveSelection(Application * app, ofVec2f by); private: ProjectionMappingMode(); diff --git a/src/ofxPiMapper.cpp b/src/ofxPiMapper.cpp index a8803f3..873da5c 100644 --- a/src/ofxPiMapper.cpp +++ b/src/ofxPiMapper.cpp @@ -80,7 +80,7 @@ void ofxPiMapper::eraseActivePreset(){ } void ofxPiMapper::selectSurface(int i){ - _application.getState()->selectSurface(&_application, i); + _application.selectSurface(i); } void ofxPiMapper::togglePerspective(){ @@ -88,11 +88,11 @@ void ofxPiMapper::togglePerspective(){ } void ofxPiMapper::selectNextSurface(){ - _application.getState()->selectNextSurface(&_application); + _application.selectNextSurface(); } void ofxPiMapper::selectPrevSurface(){ - _application.getState()->selectPrevSurface(&_application); + _application.selectPrevSurface(); } void ofxPiMapper::duplicateSurface(){ @@ -100,11 +100,11 @@ void ofxPiMapper::duplicateSurface(){ } void ofxPiMapper::selectNextVertex(){ - _application.getState()->selectNextVertex(&_application); + _application.selectNextVertex(); } void ofxPiMapper::selectPrevVertex(){ - _application.getState()->selectPrevVertex(&_application); + _application.selectPrevVertex(); } void ofxPiMapper::moveLayerUp(){ @@ -132,7 +132,7 @@ void ofxPiMapper::togglePauseForSurface(unsigned int i){ } void ofxPiMapper::moveSelection(ofVec2f by){ - _application.getState()->moveSelection(&_application, by); + _application.moveSelection(by); } void ofxPiMapper::createSurface(ofx::piMapper::SurfaceType type){