Browse Source

Set application state instead of changing gui mode (in progress)

master
Krisjanis Rijnieks 10 years ago
parent
commit
175067dc98
  1. 40
      src/Application/Application.cpp
  2. 12
      src/Application/Application.h
  3. 27
      src/Commands/SetApplicationStateCmd.cpp
  4. 30
      src/Commands/SetApplicationStateCmd.h
  5. 24
      src/Commands/SetGuiModeCmd.cpp
  6. 28
      src/Commands/SetGuiModeCmd.h
  7. 3
      src/ofxPiMapper.h

40
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;

12
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;
};

27
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

30
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

24
src/Commands/SetGuiModeCmd.cpp

@ -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

28
src/Commands/SetGuiModeCmd.h

@ -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

3
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;
}
}

Loading…
Cancel
Save