From 04a345b37729f2412f7f36179eca31e8cf56e16c Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Sat, 10 Oct 2015 15:31:52 +0300 Subject: [PATCH] Create a bridge between the new state system and the old solution --- src/Application/Application.cpp | 16 ++++++++++++---- src/Application/Application.h | 3 +++ src/Commands/SetApplicationStateCmd.cpp | 17 ++++++++++++++++- src/Commands/SetApplicationStateCmd.h | 9 ++++++++- 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/Application/Application.cpp b/src/Application/Application.cpp index 043a271..58d4502 100644 --- a/src/Application/Application.cpp +++ b/src/Application/Application.cpp @@ -26,26 +26,34 @@ namespace ofx { // Here we handle application state changes only void Application::onKeyPressed(ofKeyEventArgs & args) { + + // For now we set the state of the new system and also the old + // before it is completely ported to the state system. + switch (args.key) { case '1': _ofxPiMapper->getCmdManager().exec( new ofx::piMapper::SetApplicationStateCmd( - this, PresentationState::instance())); + this, PresentationState::instance(), + &_ofxPiMapper->getGui(), GuiMode::NONE)); break; case '2': _ofxPiMapper->getCmdManager().exec( new ofx::piMapper::SetApplicationStateCmd( - this, TextureMappingState::instance())); + this, TextureMappingState::instance(), + &_ofxPiMapper->getGui(), GuiMode::TEXTURE_MAPPING)); break; case '3': _ofxPiMapper->getCmdManager().exec( new ofx::piMapper::SetApplicationStateCmd( - this, ProjectionMappingState::instance())); + this, ProjectionMappingState::instance(), + &_ofxPiMapper->getGui(), GuiMode::PROJECTION_MAPPING)); break; case '4': _ofxPiMapper->getCmdManager().exec( new ofx::piMapper::SetApplicationStateCmd( - this, SourceSelectionState::instance())); + this, SourceSelectionState::instance(), + &_ofxPiMapper->getGui(), GuiMode::SOURCE_SELECTION)); break; default: break; diff --git a/src/Application/Application.h b/src/Application/Application.h index 2772fcd..bec8459 100644 --- a/src/Application/Application.h +++ b/src/Application/Application.h @@ -11,6 +11,9 @@ #include "TextureMappingState.h" #include "SourceSelectionState.h" +// TODO: To be removed. +#include "GuiMode.h" + class ofxPiMapper; namespace ofx { diff --git a/src/Commands/SetApplicationStateCmd.cpp b/src/Commands/SetApplicationStateCmd.cpp index 14ef2d6..bb55d0a 100644 --- a/src/Commands/SetApplicationStateCmd.cpp +++ b/src/Commands/SetApplicationStateCmd.cpp @@ -5,21 +5,36 @@ namespace ofx { SetApplicationStateCmd::SetApplicationStateCmd( Application * app, - ApplicationBaseState * st) { + ApplicationBaseState * st, + + SurfaceManagerGui * gui, + int mode) { _application = app; _prevApplicationState = 0; _applicationState = st; + + // TODO: To be removed + _gui = gui; + _prevGuiMode = -1; + _mode = mode; } void SetApplicationStateCmd::exec() { _prevApplicationState = _application->getState(); _application->setState(_applicationState); + + // TODO: To be removed. + _prevGuiMode = _gui->getMode(); + _gui->setMode(_mode); } void SetApplicationStateCmd::undo() { ofLogNotice("SetApplicationStateCmd", "undo"); _application->setState(_prevApplicationState); + + // TODO: To be removed. + _gui->setMode(_prevGuiMode); } } // namespace piMapper diff --git a/src/Commands/SetApplicationStateCmd.h b/src/Commands/SetApplicationStateCmd.h index 57df74a..11ca7bb 100644 --- a/src/Commands/SetApplicationStateCmd.h +++ b/src/Commands/SetApplicationStateCmd.h @@ -14,7 +14,9 @@ namespace ofx { public: SetApplicationStateCmd( Application * app, - ApplicationBaseState * st); + ApplicationBaseState * st, + SurfaceManagerGui * gui, + int mode); void exec(); void undo(); @@ -23,6 +25,11 @@ namespace ofx { Application * _application; ApplicationBaseState * _prevApplicationState; ApplicationBaseState * _applicationState; + + // TODO: Remove these after porting to app state system is done + SurfaceManagerGui * _gui; + int _prevGuiMode; + int _mode; }; } // namespace piMapper