Browse Source

Rename application states to modes

master
Krisjanis Rijnieks 9 years ago
parent
commit
a722ef1b2f
  1. 24
      src/Application/Application.cpp
  2. 20
      src/Application/Application.h
  3. 12
      src/Application/Modes/ApplicationBaseMode.cpp
  4. 6
      src/Application/Modes/ApplicationBaseMode.h
  5. 29
      src/Application/Modes/PresentationMode.cpp
  6. 8
      src/Application/Modes/PresentationMode.h
  7. 32
      src/Application/Modes/ProjectionMappingMode.cpp
  8. 8
      src/Application/Modes/ProjectionMappingMode.h
  9. 12
      src/Application/Modes/SourceSelectionMode.cpp
  10. 6
      src/Application/Modes/SourceSelectionMode.h
  11. 38
      src/Application/Modes/TextureMappingMode.cpp
  12. 8
      src/Application/Modes/TextureMappingMode.h
  13. 12
      src/Application/States/ApplicationBaseState.cpp
  14. 29
      src/Application/States/PresentationState.cpp
  15. 10
      src/Commands/SetApplicationStateCmd.cpp
  16. 8
      src/Commands/SetApplicationStateCmd.h
  17. 2
      src/Commands/SetTexMapDrawModeCmd.cpp
  18. 8
      src/Commands/SetTexMapDrawModeCmd.h

24
src/Application/Application.cpp

@ -1,5 +1,5 @@
#include "Application.h" #include "Application.h"
#include "PresentationState.h" #include "PresentationMode.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
@ -9,7 +9,7 @@ Application::Application(){
_surfaceManager.setMediaServer(&_mediaServer); _surfaceManager.setMediaServer(&_mediaServer);
setState(PresentationState::instance()); setState(PresentationMode::instance());
ofAddListener(ofEvents().keyPressed, this, &Application::onKeyPressed); ofAddListener(ofEvents().keyPressed, this, &Application::onKeyPressed);
ofAddListener(ofEvents().keyReleased, this, &Application::onKeyReleased); ofAddListener(ofEvents().keyReleased, this, &Application::onKeyReleased);
ofAddListener(ofEvents().mousePressed, this, &Application::onMousePressed); ofAddListener(ofEvents().mousePressed, this, &Application::onMousePressed);
@ -43,10 +43,10 @@ void Application::setup(){
} }
// Setup all states. // Setup all states.
PresentationState::instance()->setup(this); PresentationMode::instance()->setup(this);
TextureMappingState::instance()->setup(this); TextureMappingMode::instance()->setup(this);
ProjectionMappingState::instance()->setup(this); ProjectionMappingMode::instance()->setup(this);
SourceSelectionState::instance()->setup(this); SourceSelectionMode::instance()->setup(this);
// TODO: Consider whether this is the right place for it // TODO: Consider whether this is the right place for it
Gui::instance()->getScaleWidget().setSurfaceManager(&_surfaceManager); Gui::instance()->getScaleWidget().setSurfaceManager(&_surfaceManager);
@ -56,7 +56,7 @@ void Application::update(){
_state->update(this); _state->update(this);
} }
ApplicationBaseState * Application::getState(){ ApplicationBaseMode * Application::getState(){
return _state; return _state;
} }
@ -95,25 +95,25 @@ void Application::onKeyPressed(ofKeyEventArgs & args){
case '1': case '1':
_cmdManager.exec( _cmdManager.exec(
new ofx::piMapper::SetApplicationStateCmd( new ofx::piMapper::SetApplicationStateCmd(
this, PresentationState::instance())); this, PresentationMode::instance()));
break; break;
case '2': case '2':
_cmdManager.exec( _cmdManager.exec(
new ofx::piMapper::SetApplicationStateCmd( new ofx::piMapper::SetApplicationStateCmd(
this, TextureMappingState::instance())); this, TextureMappingMode::instance()));
break; break;
case '3': case '3':
_cmdManager.exec( _cmdManager.exec(
new ofx::piMapper::SetApplicationStateCmd( new ofx::piMapper::SetApplicationStateCmd(
this, ProjectionMappingState::instance())); this, ProjectionMappingMode::instance()));
break; break;
case '4': case '4':
_cmdManager.exec( _cmdManager.exec(
new ofx::piMapper::SetApplicationStateCmd( new ofx::piMapper::SetApplicationStateCmd(
this, SourceSelectionState::instance())); this, SourceSelectionMode::instance()));
break; break;
case 'f': case 'f':
@ -183,7 +183,7 @@ void Application::addFboSource(FboSource * fboSource){
_mediaServer.addFboSource(fboSource); _mediaServer.addFboSource(fboSource);
} }
void Application::setState(ApplicationBaseState * st){ void Application::setState(ApplicationBaseMode * st){
_state = st; _state = st;
} }

20
src/Application/Application.h

@ -6,11 +6,11 @@
#include "SetApplicationStateCmd.h" #include "SetApplicationStateCmd.h"
#include "ClearSurfacesCmd.h" #include "ClearSurfacesCmd.h"
#include "ApplicationBaseState.h" #include "ApplicationBaseMode.h"
#include "PresentationState.h" #include "PresentationMode.h"
#include "ProjectionMappingState.h" #include "ProjectionMappingMode.h"
#include "TextureMappingState.h" #include "TextureMappingMode.h"
#include "SourceSelectionState.h" #include "SourceSelectionMode.h"
#include "FboSource.h" #include "FboSource.h"
#include "Info.h" #include "Info.h"
@ -28,14 +28,14 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class ApplicationBaseState; class ApplicationBaseMode;
class Application : public KeyListener { class Application : public KeyListener {
public: public:
Application(); Application();
ApplicationBaseState * getState(); ApplicationBaseMode * getState();
void setup(); void setup();
void update(); void update();
@ -70,13 +70,13 @@ class Application : public KeyListener {
TerminalListener consoleListener; TerminalListener consoleListener;
protected: protected:
void setState(ApplicationBaseState * st); void setState(ApplicationBaseMode * st);
private: private:
friend class ApplicationBaseState; friend class ApplicationBaseMode;
friend class SetApplicationStateCmd; friend class SetApplicationStateCmd;
ApplicationBaseState * _state; ApplicationBaseMode * _state;
CmdManager _cmdManager; CmdManager _cmdManager;
MediaServer _mediaServer; MediaServer _mediaServer;

12
src/Application/Modes/ApplicationBaseMode.cpp

@ -0,0 +1,12 @@
#include "ApplicationBaseMode.h"
#include "PresentationMode.h"
namespace ofx {
namespace piMapper {
void ApplicationBaseMode::setState(Application * app, ApplicationBaseMode * st){
app->setState(st);
}
} // namespace piMapper
} // namespace ofx

6
src/Application/States/ApplicationBaseState.h → src/Application/Modes/ApplicationBaseMode.h

@ -9,13 +9,13 @@ namespace piMapper {
class Application; class Application;
class ApplicationBaseState { class ApplicationBaseMode {
public: public:
virtual void setup(Application * app){} virtual void setup(Application * app){}
virtual void update(Application * app){} virtual void update(Application * app){}
virtual void draw(Application * app){} virtual void draw(Application * app){}
virtual void setState(Application * app, ApplicationBaseState * st); virtual void setState(Application * app, ApplicationBaseMode * st);
// Event handler virtual methods // Event handler virtual methods
virtual void onKeyPressed(Application * app, ofKeyEventArgs & args){} virtual void onKeyPressed(Application * app, ofKeyEventArgs & args){}
@ -28,7 +28,7 @@ class ApplicationBaseState {
virtual void onGuiEvent(Application * app, GuiEvent & e) = 0; virtual void onGuiEvent(Application * app, GuiEvent & e) = 0;
// These are only used by TextureMappingState for now. // These are only used by TextureMappingMode for now.
virtual ofPoint getTranslation(){ return ofPoint(0, 0); } virtual ofPoint getTranslation(){ return ofPoint(0, 0); }
virtual void setTranslation(ofPoint p){} virtual void setTranslation(ofPoint p){}

29
src/Application/Modes/PresentationMode.cpp

@ -0,0 +1,29 @@
#include "PresentationMode.h"
namespace ofx {
namespace piMapper {
PresentationMode * PresentationMode::_instance = 0;
PresentationMode * PresentationMode::instance(){
if(_instance == 0){
_instance = new ofx::piMapper::PresentationMode();
}
return _instance;
}
void PresentationMode::draw(Application * app){
ofPushStyle();
ofSetColor(255, 255, 255, 255);
app->getSurfaceManager()->draw();
ofPopStyle();
}
void PresentationMode::onMousePressed(Application * app, ofMouseEventArgs & args){
app->getCmdManager()->exec(
new ofx::piMapper::SetApplicationStateCmd(
app, ProjectionMappingMode::instance()));
}
} // namespace piMapper
} // namespace ofx

8
src/Application/States/PresentationState.h → src/Application/Modes/PresentationMode.h

@ -5,23 +5,23 @@
#include "ofLog.h" #include "ofLog.h"
#include "ofGraphics.h" #include "ofGraphics.h"
#include "SetApplicationStateCmd.h" #include "SetApplicationStateCmd.h"
#include "ProjectionMappingState.h" #include "ProjectionMappingMode.h"
#include "GuiMode.h" #include "GuiMode.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class PresentationState : public ApplicationBaseState { class PresentationMode : public ApplicationBaseMode {
public: public:
static PresentationState * instance(); static PresentationMode * instance();
void draw(Application * app); void draw(Application * app);
void onMousePressed(Application * app, ofMouseEventArgs & args); void onMousePressed(Application * app, ofMouseEventArgs & args);
void onGuiEvent(Application * app, GuiEvent & e){} void onGuiEvent(Application * app, GuiEvent & e){}
private: private:
static PresentationState * _instance; static PresentationMode * _instance;
}; };

32
src/Application/States/ProjectionMappingState.cpp → src/Application/Modes/ProjectionMappingMode.cpp

@ -1,33 +1,33 @@
#include "ProjectionMappingState.h" #include "ProjectionMappingMode.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
ProjectionMappingState::ProjectionMappingState(){ ProjectionMappingMode::ProjectionMappingMode(){
_surfaceScaleBeforeTransform = 1.0f; _surfaceScaleBeforeTransform = 1.0f;
} }
ProjectionMappingState * ProjectionMappingState::_instance = 0; ProjectionMappingMode * ProjectionMappingMode::_instance = 0;
ProjectionMappingState * ProjectionMappingState::instance(){ ProjectionMappingMode * ProjectionMappingMode::instance(){
if(_instance == 0){ if(_instance == 0){
_instance = new ofx::piMapper::ProjectionMappingState(); _instance = new ofx::piMapper::ProjectionMappingMode();
} }
return _instance; return _instance;
} }
void ProjectionMappingState::setup(Application *app){ void ProjectionMappingMode::setup(Application *app){
Gui::instance()->getSurfaceHighlightWidget().setSurfaceManager(app->getSurfaceManager()); Gui::instance()->getSurfaceHighlightWidget().setSurfaceManager(app->getSurfaceManager());
Gui::instance()->getLayerPanelWidget().setSurfaceManager(app->getSurfaceManager()); Gui::instance()->getLayerPanelWidget().setSurfaceManager(app->getSurfaceManager());
Gui::instance()->getProjectionEditorWidget().setSurfaceManager(app->getSurfaceManager()); Gui::instance()->getProjectionEditorWidget().setSurfaceManager(app->getSurfaceManager());
} }
void ProjectionMappingState::update(Application * app){ void ProjectionMappingMode::update(Application * app){
Gui::instance()->getProjectionEditorWidget().update(); Gui::instance()->getProjectionEditorWidget().update();
Gui::instance()->getScaleWidget().update(); Gui::instance()->getScaleWidget().update();
} }
void ProjectionMappingState::draw(Application * app){ void ProjectionMappingMode::draw(Application * app){
ofPushStyle(); ofPushStyle();
ofSetColor(255, 255, 255, 255); ofSetColor(255, 255, 255, 255);
app->getSurfaceManager()->draw(); app->getSurfaceManager()->draw();
@ -45,7 +45,7 @@ void ProjectionMappingState::draw(Application * app){
Gui::instance()->getSurfaceHighlightWidget().draw(); Gui::instance()->getSurfaceHighlightWidget().draw();
} }
void ProjectionMappingState::onKeyPressed(Application * app, ofKeyEventArgs & args){ void ProjectionMappingMode::onKeyPressed(Application * app, ofKeyEventArgs & args){
switch(args.key){ switch(args.key){
case 't': case 't':
@ -287,7 +287,7 @@ void ProjectionMappingState::onKeyPressed(Application * app, ofKeyEventArgs & ar
} }
} }
void ProjectionMappingState::onMousePressed(Application * app, ofMouseEventArgs & args){ void ProjectionMappingMode::onMousePressed(Application * app, ofMouseEventArgs & args){
Gui::instance()->onMousePressed(args); Gui::instance()->onMousePressed(args);
CircleJoint * hitJoint = 0; CircleJoint * hitJoint = 0;
@ -328,13 +328,13 @@ void ProjectionMappingState::onMousePressed(Application * app, ofMouseEventArgs
} }
} }
void ProjectionMappingState::onMouseReleased(Application * app, ofMouseEventArgs & args){ void ProjectionMappingMode::onMouseReleased(Application * app, ofMouseEventArgs & args){
Gui::instance()->onMouseReleased(args); Gui::instance()->onMouseReleased(args);
_bSurfaceDrag = false; // TODO: handle this locally _bSurfaceDrag = false; // TODO: handle this locally
Gui::instance()->getProjectionEditorWidget().stopDragJoints(); Gui::instance()->getProjectionEditorWidget().stopDragJoints();
} }
void ProjectionMappingState::onMouseDragged(Application * app, ofMouseEventArgs & args){ void ProjectionMappingMode::onMouseDragged(Application * app, ofMouseEventArgs & args){
Gui::instance()->onMouseDragged(args); Gui::instance()->onMouseDragged(args);
Gui::instance()->getProjectionEditorWidget().mouseDragged(args); Gui::instance()->getProjectionEditorWidget().mouseDragged(args);
@ -347,14 +347,14 @@ void ProjectionMappingState::onMouseDragged(Application * app, ofMouseEventArgs
} }
} }
void ProjectionMappingState::onJointPressed(Application * app, GuiJointEvent & e){ void ProjectionMappingMode::onJointPressed(Application * app, GuiJointEvent & e){
app->getCmdManager()->exec(new SelVertexCmd(app->getSurfaceManager(), e.jointIndex)); app->getCmdManager()->exec(new SelVertexCmd(app->getSurfaceManager(), e.jointIndex));
app->getCmdManager()->exec(new MvSurfaceVertCmd( app->getCmdManager()->exec(new MvSurfaceVertCmd(
e.jointIndex, e.jointIndex,
app->getSurfaceManager()->getSelectedSurface())); app->getSurfaceManager()->getSelectedSurface()));
} }
void ProjectionMappingState::onSurfacePressed(Application * app, GuiSurfaceEvent & e){ void ProjectionMappingMode::onSurfacePressed(Application * app, GuiSurfaceEvent & e){
if(app->getSurfaceManager()->getSelectedSurface() != e.surface){ if(app->getSurfaceManager()->getSelectedSurface() != e.surface){
app->getCmdManager()->exec(new SelSurfaceCmd(app->getSurfaceManager(), e.surface )); app->getCmdManager()->exec(new SelSurfaceCmd(app->getSurfaceManager(), e.surface ));
} }
@ -362,13 +362,13 @@ void ProjectionMappingState::onSurfacePressed(Application * app, GuiSurfaceEvent
app->getCmdManager()->exec(new StartDragSurfaceCmd(e.surface)); app->getCmdManager()->exec(new StartDragSurfaceCmd(e.surface));
} }
void ProjectionMappingState::onBackgroundPressed(Application * app, GuiBackgroundEvent & e){ void ProjectionMappingMode::onBackgroundPressed(Application * app, GuiBackgroundEvent & e){
if(app->getSurfaceManager()->getSelectedSurface() != 0){ if(app->getSurfaceManager()->getSelectedSurface() != 0){
app->getCmdManager()->exec(new DeselectSurfaceCmd(app->getSurfaceManager())); app->getCmdManager()->exec(new DeselectSurfaceCmd(app->getSurfaceManager()));
} }
} }
void ProjectionMappingState::onGuiEvent(Application * app, GuiEvent & e){ void ProjectionMappingMode::onGuiEvent(Application * app, GuiEvent & e){
// Scale widget now. More widgets later. // Scale widget now. More widgets later.
if(e.widget == &Gui::instance()->getScaleWidget()){ if(e.widget == &Gui::instance()->getScaleWidget()){

8
src/Application/States/ProjectionMappingState.h → src/Application/Modes/ProjectionMappingMode.h

@ -36,10 +36,10 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class ProjectionMappingState : public ApplicationBaseState { class ProjectionMappingMode : public ApplicationBaseMode {
public: public:
static ProjectionMappingState * instance(); static ProjectionMappingMode * instance();
void setup(Application * app); void setup(Application * app);
void update(Application * app); void update(Application * app);
@ -55,9 +55,9 @@ class ProjectionMappingState : public ApplicationBaseState {
void onGuiEvent(Application * app, GuiEvent & e); void onGuiEvent(Application * app, GuiEvent & e);
private: private:
ProjectionMappingState(); ProjectionMappingMode();
static ProjectionMappingState * _instance; static ProjectionMappingMode * _instance;
float _surfaceScaleBeforeTransform; float _surfaceScaleBeforeTransform;

12
src/Application/States/SourceSelectionState.cpp → src/Application/Modes/SourceSelectionMode.cpp

@ -1,25 +1,25 @@
#include "SourceSelectionState.h" #include "SourceSelectionMode.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
SourceSelectionState * SourceSelectionState::_instance = 0; SourceSelectionMode * SourceSelectionMode::_instance = 0;
SourceSelectionState * SourceSelectionState::instance(){ SourceSelectionMode * SourceSelectionMode::instance(){
if(_instance == 0){ if(_instance == 0){
_instance = new ofx::piMapper::SourceSelectionState(); _instance = new ofx::piMapper::SourceSelectionMode();
} }
return _instance; return _instance;
} }
void SourceSelectionState::setup(Application * app){ void SourceSelectionMode::setup(Application * app){
Gui::instance()->getSourcesEditorWidget().setSurfaceManager(app->getSurfaceManager()); Gui::instance()->getSourcesEditorWidget().setSurfaceManager(app->getSurfaceManager());
Gui::instance()->getSourcesEditorWidget().setMediaServer(app->getMediaServer()); Gui::instance()->getSourcesEditorWidget().setMediaServer(app->getMediaServer());
Gui::instance()->getSourcesEditorWidget().setCmdManager(app->getCmdManager()); Gui::instance()->getSourcesEditorWidget().setCmdManager(app->getCmdManager());
Gui::instance()->getSourcesEditorWidget().setup(); Gui::instance()->getSourcesEditorWidget().setup();
} }
void SourceSelectionState::draw(Application * app){ void SourceSelectionMode::draw(Application * app){
ofPushStyle(); ofPushStyle();
ofSetColor(255, 255, 255, 255); ofSetColor(255, 255, 255, 255);
app->getSurfaceManager()->draw(); app->getSurfaceManager()->draw();

6
src/Application/States/SourceSelectionState.h → src/Application/Modes/SourceSelectionMode.h

@ -9,17 +9,17 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class SourceSelectionState : public ApplicationBaseState { class SourceSelectionMode : public ApplicationBaseMode {
public: public:
static SourceSelectionState * instance(); static SourceSelectionMode * instance();
void setup(Application * app); void setup(Application * app);
void draw(Application * app); void draw(Application * app);
void onGuiEvent(Application * app, GuiEvent & e){} void onGuiEvent(Application * app, GuiEvent & e){}
private: private:
static SourceSelectionState * _instance; static SourceSelectionMode * _instance;
}; };

38
src/Application/States/TextureMappingState.cpp → src/Application/Modes/TextureMappingMode.cpp

@ -1,29 +1,29 @@
#include "TextureMappingState.h" #include "TextureMappingMode.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
TextureMappingState * TextureMappingState::_instance = 0; TextureMappingMode * TextureMappingMode::_instance = 0;
TextureMappingState * TextureMappingState::instance(){ TextureMappingMode * TextureMappingMode::instance(){
if(_instance == 0){ if(_instance == 0){
_instance = new ofx::piMapper::TextureMappingState(); _instance = new ofx::piMapper::TextureMappingMode();
} }
return _instance; return _instance;
} }
TextureMappingState::TextureMappingState(){ TextureMappingMode::TextureMappingMode(){
_bTranslateCanvas = false; _bTranslateCanvas = false;
_canvasTranslate = ofPoint(0, 0); _canvasTranslate = ofPoint(0, 0);
_clickCanvasTranslate = ofPoint(0, 0); _clickCanvasTranslate = ofPoint(0, 0);
_drawMode = 0; _drawMode = 0;
} }
void TextureMappingState::update(Application * app){ void TextureMappingMode::update(Application * app){
Gui::instance()->getTextureEditorWidget().update(); Gui::instance()->getTextureEditorWidget().update();
} }
void TextureMappingState::draw(Application * app){ void TextureMappingMode::draw(Application * app){
ofPushMatrix(); ofPushMatrix();
ofTranslate(_canvasTranslate.x, _canvasTranslate.y); ofTranslate(_canvasTranslate.x, _canvasTranslate.y);
@ -73,7 +73,7 @@ void TextureMappingState::draw(Application * app){
ofPopMatrix(); ofPopMatrix();
} }
void TextureMappingState::onKeyPressed(Application * app, ofKeyEventArgs & args){ void TextureMappingMode::onKeyPressed(Application * app, ofKeyEventArgs & args){
int key = args.key; int key = args.key;
float moveStep; float moveStep;
@ -146,7 +146,7 @@ void TextureMappingState::onKeyPressed(Application * app, ofKeyEventArgs & args)
} }
} }
void TextureMappingState::onBackgroundPressed(Application * app, GuiBackgroundEvent & e){ void TextureMappingMode::onBackgroundPressed(Application * app, GuiBackgroundEvent & e){
// Exec the command only if a joint is selected. // Exec the command only if a joint is selected.
bool selected = false; bool selected = false;
for(unsigned int i = 0; i < Gui::instance()->getTextureEditorWidget().getJoints().size(); ++i){ for(unsigned int i = 0; i < Gui::instance()->getTextureEditorWidget().getJoints().size(); ++i){
@ -164,7 +164,7 @@ void TextureMappingState::onBackgroundPressed(Application * app, GuiBackgroundEv
_bTranslateCanvas = true; _bTranslateCanvas = true;
} }
void TextureMappingState::onMousePressed(Application * app, ofMouseEventArgs & args){ void TextureMappingMode::onMousePressed(Application * app, ofMouseEventArgs & args){
_clickPosition = ofPoint(args.x, args.y); _clickPosition = ofPoint(args.x, args.y);
_prevCanvasTranslate = _canvasTranslate; _prevCanvasTranslate = _canvasTranslate;
@ -213,7 +213,7 @@ void TextureMappingState::onMousePressed(Application * app, ofMouseEventArgs & a
} }
} }
void TextureMappingState::onMouseReleased(Application * app, ofMouseEventArgs & args){ void TextureMappingMode::onMouseReleased(Application * app, ofMouseEventArgs & args){
_bTranslateCanvas = false; _bTranslateCanvas = false;
// If translation has happened, create an undoable command // If translation has happened, create an undoable command
@ -235,7 +235,7 @@ void TextureMappingState::onMouseReleased(Application * app, ofMouseEventArgs &
} }
// TODO: Handle app->getGui()->clickPosition and app->getGui()->bDrag locally. // TODO: Handle app->getGui()->clickPosition and app->getGui()->bDrag locally.
void TextureMappingState::onMouseDragged(Application * app, ofMouseEventArgs & args){ void TextureMappingMode::onMouseDragged(Application * app, ofMouseEventArgs & args){
if(!_bTranslateCanvas){ if(!_bTranslateCanvas){
args.x -= _canvasTranslate.x; args.x -= _canvasTranslate.x;
args.y -= _canvasTranslate.y; args.y -= _canvasTranslate.y;
@ -254,7 +254,7 @@ void TextureMappingState::onMouseDragged(Application * app, ofMouseEventArgs & a
} }
} }
void TextureMappingState::drawTexture(Application * app){ void TextureMappingMode::drawTexture(Application * app){
if(app->getSurfaceManager()->getSelectedSurface() != 0){ if(app->getSurfaceManager()->getSelectedSurface() != 0){
bool normalizedTexCoords = ofGetUsingNormalizedTexCoords(); bool normalizedTexCoords = ofGetUsingNormalizedTexCoords();
ofEnableNormalizedTexCoords(); ofEnableNormalizedTexCoords();
@ -268,24 +268,24 @@ void TextureMappingState::drawTexture(Application * app){
} }
} }
ofPoint TextureMappingState::getTranslation(){ ofPoint TextureMappingMode::getTranslation(){
return _canvasTranslate; return _canvasTranslate;
} }
void TextureMappingState::setTranslation(ofPoint p){ void TextureMappingMode::setTranslation(ofPoint p){
_canvasTranslate = p; _canvasTranslate = p;
_clickCanvasTranslate = p; _clickCanvasTranslate = p;
} }
void TextureMappingState::setDrawMode(int m){ void TextureMappingMode::setDrawMode(int m){
_drawMode = m; _drawMode = m;
} }
int TextureMappingState::getDrawMode(){ int TextureMappingMode::getDrawMode(){
return _drawMode; return _drawMode;
} }
int TextureMappingState::getNextDrawMode(){ int TextureMappingMode::getNextDrawMode(){
int nextDrawMode = _drawMode + 1; int nextDrawMode = _drawMode + 1;
if(nextDrawMode > 2){ if(nextDrawMode > 2){
@ -295,7 +295,7 @@ int TextureMappingState::getNextDrawMode(){
return nextDrawMode; return nextDrawMode;
} }
int TextureMappingState::getPrevDrawMode(){ int TextureMappingMode::getPrevDrawMode(){
int prevDrawMode = _drawMode - 1; int prevDrawMode = _drawMode - 1;
if(prevDrawMode < 0){ if(prevDrawMode < 0){

8
src/Application/States/TextureMappingState.h → src/Application/Modes/TextureMappingMode.h

@ -19,10 +19,10 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class TextureMappingState : public ApplicationBaseState { class TextureMappingMode : public ApplicationBaseMode {
public: public:
static TextureMappingState * instance(); static TextureMappingMode * instance();
void update(Application * app); void update(Application * app);
void draw(Application * app); void draw(Application * app);
@ -44,9 +44,9 @@ class TextureMappingState : public ApplicationBaseState {
int getPrevDrawMode(); int getPrevDrawMode();
private: private:
static TextureMappingState * _instance; static TextureMappingMode * _instance;
TextureMappingState(); TextureMappingMode();
bool _bTranslateCanvas; bool _bTranslateCanvas;
bool _bCropAreaDrag; bool _bCropAreaDrag;

12
src/Application/States/ApplicationBaseState.cpp

@ -1,12 +0,0 @@
#include "ApplicationBaseState.h"
#include "PresentationState.h"
namespace ofx {
namespace piMapper {
void ApplicationBaseState::setState(Application * app, ApplicationBaseState * st){
app->setState(st);
}
} // namespace piMapper
} // namespace ofx

29
src/Application/States/PresentationState.cpp

@ -1,29 +0,0 @@
#include "PresentationState.h"
namespace ofx {
namespace piMapper {
PresentationState * PresentationState::_instance = 0;
PresentationState * PresentationState::instance(){
if(_instance == 0){
_instance = new ofx::piMapper::PresentationState();
}
return _instance;
}
void PresentationState::draw(Application * app){
ofPushStyle();
ofSetColor(255, 255, 255, 255);
app->getSurfaceManager()->draw();
ofPopStyle();
}
void PresentationState::onMousePressed(Application * app, ofMouseEventArgs & args){
app->getCmdManager()->exec(
new ofx::piMapper::SetApplicationStateCmd(
app, ProjectionMappingState::instance()));
}
} // namespace piMapper
} // namespace ofx

10
src/Commands/SetApplicationStateCmd.cpp

@ -4,7 +4,7 @@ namespace ofx {
namespace piMapper { namespace piMapper {
SetApplicationStateCmd::SetApplicationStateCmd(Application * app, SetApplicationStateCmd::SetApplicationStateCmd(Application * app,
ApplicationBaseState * st){ ApplicationBaseMode * st){
_application = app; _application = app;
_prevApplicationState = 0; _prevApplicationState = 0;
@ -20,13 +20,13 @@ void SetApplicationStateCmd::exec(){
Gui::instance()->getTextureEditorWidget().setSurface( Gui::instance()->getTextureEditorWidget().setSurface(
_application->getSurfaceManager()->getSelectedSurface()); _application->getSurfaceManager()->getSelectedSurface());
if(_applicationState != PresentationState::instance()){ if(_applicationState != PresentationMode::instance()){
ofShowCursor(); ofShowCursor();
}else{ }else{
ofHideCursor(); ofHideCursor();
} }
if(_applicationState == SourceSelectionState::instance()){ if(_applicationState == SourceSelectionMode::instance()){
Gui::instance()->getSourcesEditorWidget().enable(); Gui::instance()->getSourcesEditorWidget().enable();
}else{ }else{
Gui::instance()->getSourcesEditorWidget().disable(); Gui::instance()->getSourcesEditorWidget().disable();
@ -41,13 +41,13 @@ void SetApplicationStateCmd::undo(){
Gui::instance()->getTextureEditorWidget().setSurface( Gui::instance()->getTextureEditorWidget().setSurface(
_application->getSurfaceManager()->getSelectedSurface()); _application->getSurfaceManager()->getSelectedSurface());
if(_prevApplicationState != PresentationState::instance()){ if(_prevApplicationState != PresentationMode::instance()){
ofShowCursor(); ofShowCursor();
}else{ }else{
ofHideCursor(); ofHideCursor();
} }
if(_prevApplicationState == SourceSelectionState::instance()){ if(_prevApplicationState == SourceSelectionMode::instance()){
Gui::instance()->getSourcesEditorWidget().enable(); Gui::instance()->getSourcesEditorWidget().enable();
}else{ }else{
Gui::instance()->getSourcesEditorWidget().disable(); Gui::instance()->getSourcesEditorWidget().disable();

8
src/Commands/SetApplicationStateCmd.h

@ -7,21 +7,21 @@ namespace ofx {
namespace piMapper { namespace piMapper {
class Application; class Application;
class ApplicationBaseState; class ApplicationBaseMode;
class SetApplicationStateCmd : public BaseUndoCmd { class SetApplicationStateCmd : public BaseUndoCmd {
public: public:
SetApplicationStateCmd(Application * app, SetApplicationStateCmd(Application * app,
ApplicationBaseState * st); ApplicationBaseMode * st);
void exec(); void exec();
void undo(); void undo();
private: private:
Application * _application; Application * _application;
ApplicationBaseState * _prevApplicationState; ApplicationBaseMode * _prevApplicationState;
ApplicationBaseState * _applicationState; ApplicationBaseMode * _applicationState;
ofPoint _translation; ofPoint _translation;

2
src/Commands/SetTexMapDrawModeCmd.cpp

@ -3,7 +3,7 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
SetTexMapDrawModeCmd::SetTexMapDrawModeCmd(TextureMappingState * s, int m){ SetTexMapDrawModeCmd::SetTexMapDrawModeCmd(TextureMappingMode * s, int m){
_state = s; _state = s;
_newMode = m; _newMode = m;
} }

8
src/Commands/SetTexMapDrawModeCmd.h

@ -5,22 +5,22 @@
#pragma once #pragma once
#include "BaseCmd.h" #include "BaseCmd.h"
#include "TextureMappingState.h" #include "TextureMappingMode.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class TextureMappingState; class TextureMappingMode;
class SetTexMapDrawModeCmd : public BaseUndoCmd { class SetTexMapDrawModeCmd : public BaseUndoCmd {
public: public:
SetTexMapDrawModeCmd(TextureMappingState * s, int m); SetTexMapDrawModeCmd(TextureMappingMode * s, int m);
void exec(); void exec();
void undo(); void undo();
private: private:
TextureMappingState * _state; TextureMappingMode * _state;
int _oldMode; int _oldMode;
int _newMode; int _newMode;

Loading…
Cancel
Save