Browse Source

Create a bridge between the new state system and the old solution

master
Krisjanis Rijnieks 10 years ago
parent
commit
04a345b377
  1. 16
      src/Application/Application.cpp
  2. 3
      src/Application/Application.h
  3. 17
      src/Commands/SetApplicationStateCmd.cpp
  4. 9
      src/Commands/SetApplicationStateCmd.h

16
src/Application/Application.cpp

@ -26,26 +26,34 @@ namespace ofx {
// Here we handle application state changes only // Here we handle application state changes only
void Application::onKeyPressed(ofKeyEventArgs & args) { 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) { switch (args.key) {
case '1': case '1':
_ofxPiMapper->getCmdManager().exec( _ofxPiMapper->getCmdManager().exec(
new ofx::piMapper::SetApplicationStateCmd( new ofx::piMapper::SetApplicationStateCmd(
this, PresentationState::instance())); this, PresentationState::instance(),
&_ofxPiMapper->getGui(), GuiMode::NONE));
break; break;
case '2': case '2':
_ofxPiMapper->getCmdManager().exec( _ofxPiMapper->getCmdManager().exec(
new ofx::piMapper::SetApplicationStateCmd( new ofx::piMapper::SetApplicationStateCmd(
this, TextureMappingState::instance())); this, TextureMappingState::instance(),
&_ofxPiMapper->getGui(), GuiMode::TEXTURE_MAPPING));
break; break;
case '3': case '3':
_ofxPiMapper->getCmdManager().exec( _ofxPiMapper->getCmdManager().exec(
new ofx::piMapper::SetApplicationStateCmd( new ofx::piMapper::SetApplicationStateCmd(
this, ProjectionMappingState::instance())); this, ProjectionMappingState::instance(),
&_ofxPiMapper->getGui(), GuiMode::PROJECTION_MAPPING));
break; break;
case '4': case '4':
_ofxPiMapper->getCmdManager().exec( _ofxPiMapper->getCmdManager().exec(
new ofx::piMapper::SetApplicationStateCmd( new ofx::piMapper::SetApplicationStateCmd(
this, SourceSelectionState::instance())); this, SourceSelectionState::instance(),
&_ofxPiMapper->getGui(), GuiMode::SOURCE_SELECTION));
break; break;
default: default:
break; break;

3
src/Application/Application.h

@ -11,6 +11,9 @@
#include "TextureMappingState.h" #include "TextureMappingState.h"
#include "SourceSelectionState.h" #include "SourceSelectionState.h"
// TODO: To be removed.
#include "GuiMode.h"
class ofxPiMapper; class ofxPiMapper;
namespace ofx { namespace ofx {

17
src/Commands/SetApplicationStateCmd.cpp

@ -5,21 +5,36 @@ namespace ofx {
SetApplicationStateCmd::SetApplicationStateCmd( SetApplicationStateCmd::SetApplicationStateCmd(
Application * app, Application * app,
ApplicationBaseState * st) { ApplicationBaseState * st,
SurfaceManagerGui * gui,
int mode) {
_application = app; _application = app;
_prevApplicationState = 0; _prevApplicationState = 0;
_applicationState = st; _applicationState = st;
// TODO: To be removed
_gui = gui;
_prevGuiMode = -1;
_mode = mode;
} }
void SetApplicationStateCmd::exec() { void SetApplicationStateCmd::exec() {
_prevApplicationState = _application->getState(); _prevApplicationState = _application->getState();
_application->setState(_applicationState); _application->setState(_applicationState);
// TODO: To be removed.
_prevGuiMode = _gui->getMode();
_gui->setMode(_mode);
} }
void SetApplicationStateCmd::undo() { void SetApplicationStateCmd::undo() {
ofLogNotice("SetApplicationStateCmd", "undo"); ofLogNotice("SetApplicationStateCmd", "undo");
_application->setState(_prevApplicationState); _application->setState(_prevApplicationState);
// TODO: To be removed.
_gui->setMode(_prevGuiMode);
} }
} // namespace piMapper } // namespace piMapper

9
src/Commands/SetApplicationStateCmd.h

@ -14,7 +14,9 @@ namespace ofx {
public: public:
SetApplicationStateCmd( SetApplicationStateCmd(
Application * app, Application * app,
ApplicationBaseState * st); ApplicationBaseState * st,
SurfaceManagerGui * gui,
int mode);
void exec(); void exec();
void undo(); void undo();
@ -23,6 +25,11 @@ namespace ofx {
Application * _application; Application * _application;
ApplicationBaseState * _prevApplicationState; ApplicationBaseState * _prevApplicationState;
ApplicationBaseState * _applicationState; ApplicationBaseState * _applicationState;
// TODO: Remove these after porting to app state system is done
SurfaceManagerGui * _gui;
int _prevGuiMode;
int _mode;
}; };
} // namespace piMapper } // namespace piMapper

Loading…
Cancel
Save