diff --git a/src/Application/Application.cpp b/src/Application/Application.cpp index 456647f..043a271 100644 --- a/src/Application/Application.cpp +++ b/src/Application/Application.cpp @@ -16,6 +16,10 @@ namespace ofx { ofRemoveListener(ofEvents().keyPressed, this, &Application::onKeyPressed); } + ApplicationBaseState * Application::getState() { + return _state; + } + void Application::draw(){ _state->draw(this); } @@ -24,36 +28,24 @@ namespace ofx { void Application::onKeyPressed(ofKeyEventArgs & args) { switch (args.key) { case '1': - ofLogNotice("Application::onKeyPressed()") << "Switching to Presentation State"; - if (_ofxPiMapper->getGui().getMode() != ofx::piMapper::GuiMode::NONE) { - _ofxPiMapper->getCmdManager().exec( - new ofx::piMapper::SetGuiModeCmd(&_ofxPiMapper->getGui(), - ofx::piMapper::GuiMode::NONE)); - } + _ofxPiMapper->getCmdManager().exec( + new ofx::piMapper::SetApplicationStateCmd( + this, PresentationState::instance())); break; case '2': - ofLogNotice("Application::onKeyPressed()") << "Switching to Projection Mapping State"; - if (_ofxPiMapper->getGui().getMode() != ofx::piMapper::GuiMode::PROJECTION_MAPPING) { - _ofxPiMapper->getCmdManager().exec( - new ofx::piMapper::SetGuiModeCmd(&_ofxPiMapper->getGui(), - ofx::piMapper::GuiMode::PROJECTION_MAPPING)); - } + _ofxPiMapper->getCmdManager().exec( + new ofx::piMapper::SetApplicationStateCmd( + this, TextureMappingState::instance())); break; case '3': - ofLogNotice("Application::onKeyPressed()") << "Switching to Source Selection State"; - if (_ofxPiMapper->getGui().getMode() != ofx::piMapper::GuiMode::SOURCE_SELECTION) { - _ofxPiMapper->getCmdManager().exec( - new ofx::piMapper::SetGuiModeCmd(&_ofxPiMapper->getGui(), - ofx::piMapper::GuiMode::SOURCE_SELECTION)); - } + _ofxPiMapper->getCmdManager().exec( + new ofx::piMapper::SetApplicationStateCmd( + this, ProjectionMappingState::instance())); break; case '4': - ofLogNotice("Application::onKeyPressed()") << "Switching to Texture Mapping State"; - if (_ofxPiMapper->getGui().getMode() != ofx::piMapper::GuiMode::TEXTURE_MAPPING) { - _ofxPiMapper->getCmdManager().exec( - new ofx::piMapper::SetGuiModeCmd(&_ofxPiMapper->getGui(), - ofx::piMapper::GuiMode::TEXTURE_MAPPING)); - } + _ofxPiMapper->getCmdManager().exec( + new ofx::piMapper::SetApplicationStateCmd( + this, SourceSelectionState::instance())); break; default: break; diff --git a/src/Application/Application.h b/src/Application/Application.h index 916b3a1..2772fcd 100644 --- a/src/Application/Application.h +++ b/src/Application/Application.h @@ -2,8 +2,14 @@ #include "ofEvents.h" #include "ofLog.h" -#include "ApplicationBaseState.h" + #include "ofxPiMapper.h" +#include "SetApplicationStateCmd.h" +#include "ApplicationBaseState.h" +#include "PresentationState.h" +#include "ProjectionMappingState.h" +#include "TextureMappingState.h" +#include "SourceSelectionState.h" class ofxPiMapper; @@ -17,6 +23,8 @@ namespace ofx { Application(ofxPiMapper * opm); ~Application(); + ApplicationBaseState * getState(); + void draw(); void onKeyPressed(ofKeyEventArgs & args); @@ -25,6 +33,8 @@ namespace ofx { private: friend class ApplicationBaseState; + friend class SetApplicationStateCmd; + ApplicationBaseState * _state; ofxPiMapper * _ofxPiMapper; }; diff --git a/src/Commands/SetApplicationStateCmd.cpp b/src/Commands/SetApplicationStateCmd.cpp new file mode 100644 index 0000000..14ef2d6 --- /dev/null +++ b/src/Commands/SetApplicationStateCmd.cpp @@ -0,0 +1,27 @@ +#include "SetApplicationStateCmd.h" + +namespace ofx { + namespace piMapper { + + SetApplicationStateCmd::SetApplicationStateCmd( + Application * app, + ApplicationBaseState * st) { + + _application = app; + _prevApplicationState = 0; + _applicationState = st; + } + + void SetApplicationStateCmd::exec() { + _prevApplicationState = _application->getState(); + _application->setState(_applicationState); + } + + void SetApplicationStateCmd::undo() { + ofLogNotice("SetApplicationStateCmd", "undo"); + _application->setState(_prevApplicationState); + } + + } // namespace piMapper +} // namespace ofx + diff --git a/src/Commands/SetApplicationStateCmd.h b/src/Commands/SetApplicationStateCmd.h new file mode 100644 index 0000000..57df74a --- /dev/null +++ b/src/Commands/SetApplicationStateCmd.h @@ -0,0 +1,30 @@ +#pragma once + +#include "BaseCmd.h" +#include "Application.h" + +namespace ofx { + namespace piMapper { + + class Application; + class ApplicationBaseState; + + class SetApplicationStateCmd : public BaseUndoCmd { + + public: + SetApplicationStateCmd( + Application * app, + ApplicationBaseState * st); + + void exec(); + void undo(); + + private: + Application * _application; + ApplicationBaseState * _prevApplicationState; + ApplicationBaseState * _applicationState; + }; + + } // namespace piMapper +} // namespace ofx + diff --git a/src/Commands/SetGuiModeCmd.cpp b/src/Commands/SetGuiModeCmd.cpp deleted file mode 100644 index 20a27b3..0000000 --- a/src/Commands/SetGuiModeCmd.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#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 deleted file mode 100644 index f397a13..0000000 --- a/src/Commands/SetGuiModeCmd.h +++ /dev/null @@ -1,28 +0,0 @@ -// 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/ofxPiMapper.h b/src/ofxPiMapper.h index 4179cf8..38ae474 100644 --- a/src/ofxPiMapper.h +++ b/src/ofxPiMapper.h @@ -10,7 +10,6 @@ #include "BaseCmd.h" #include "CmdManager.h" #include "RmSurfaceCmd.h" -#include "SetGuiModeCmd.h" // Main view with state design pattern #include "Application.h" // Main application entry point @@ -20,7 +19,7 @@ namespace ofx { namespace piMapper { - class Keyboard; + class Application; } }