diff --git a/src/Application/Application.cpp b/src/Application/Application.cpp index ccec62f..7a9ed17 100644 --- a/src/Application/Application.cpp +++ b/src/Application/Application.cpp @@ -8,8 +8,6 @@ Application::Application(){ _keySequence = ""; _surfaceManager.setMediaServer(&_mediaServer); - _gui.setMediaServer(&_mediaServer); - _gui.setCmdManager(&_cmdManager); setState(PresentationState::instance()); ofAddListener(ofEvents().keyPressed, this, &Application::onKeyPressed); diff --git a/src/Application/Application.h b/src/Application/Application.h index b9c13b5..79ec465 100644 --- a/src/Application/Application.h +++ b/src/Application/Application.h @@ -14,7 +14,6 @@ #include "FboSource.h" #include "Info.h" -#include "SurfaceManagerGui.h" #include "SurfaceStack.h" // TODO: To be removed. @@ -63,7 +62,6 @@ class Application : public KeyListener { bool loadXmlSettings(string fileName); bool isShiftKeyDown(); - SurfaceManagerGui * getGui(){ return &_gui; } SurfaceManager * getSurfaceManager(){ return &_surfaceManager; } CmdManager * getCmdManager(){ return &_cmdManager; } MediaServer * getMediaServer(){ return &_mediaServer; } @@ -81,7 +79,6 @@ class Application : public KeyListener { ApplicationBaseState * _state; CmdManager _cmdManager; - SurfaceManagerGui _gui; MediaServer _mediaServer; SurfaceManager _surfaceManager; Info _info; diff --git a/src/Application/States/ProjectionMappingState.cpp b/src/Application/States/ProjectionMappingState.cpp index 425d45f..e048b33 100644 --- a/src/Application/States/ProjectionMappingState.cpp +++ b/src/Application/States/ProjectionMappingState.cpp @@ -319,8 +319,9 @@ void ProjectionMappingState::onMousePressed(Application * app, ofMouseEventArgs hitJoint->startDrag(); Gui::instance()->notifyJointPressed(args, hitJointIndex); }else if(hitSurface){ - app->getGui()->clickPosition = ofVec2f(args.x, args.y); - app->getGui()->startDrag(); // TODO: Should be something like `hitSurface->startDrag()` + _clickPosition = ofVec2f(args.x, args.y); // TODO: redesign this so we can use a kind of + // display stack. + _bSurfaceDrag = true; // TODO: Should be something like `hitSurface->startDrag()` Gui::instance()->notifySurfacePressed(args, hitSurface); }else{ Gui::instance()->notifyBackgroundPressed(args); @@ -329,7 +330,7 @@ void ProjectionMappingState::onMousePressed(Application * app, ofMouseEventArgs void ProjectionMappingState::onMouseReleased(Application * app, ofMouseEventArgs & args){ Gui::instance()->onMouseReleased(args); - app->getGui()->stopDrag(); // TODO: handle this locally + _bSurfaceDrag = false; // TODO: handle this locally Gui::instance()->getProjectionEditorWidget().stopDragJoints(); } @@ -338,11 +339,11 @@ void ProjectionMappingState::onMouseDragged(Application * app, ofMouseEventArgs Gui::instance()->getProjectionEditorWidget().mouseDragged(args); // TODO: Handle app->getGui()->clickPosition and app->getGui()->bDrag locally. - if(app->getGui()->bDrag){ + if(_bSurfaceDrag){ ofVec2f mousePosition = ofVec2f(args.x, args.y); - ofVec2f distance = mousePosition - app->getGui()->clickPosition; + ofVec2f distance = mousePosition - _clickPosition; Gui::instance()->getProjectionEditorWidget().moveSelectedSurface(distance); - app->getGui()->clickPosition = mousePosition; + _clickPosition = mousePosition; } } diff --git a/src/Application/States/ProjectionMappingState.h b/src/Application/States/ProjectionMappingState.h index fbb43fc..c26db7e 100644 --- a/src/Application/States/ProjectionMappingState.h +++ b/src/Application/States/ProjectionMappingState.h @@ -26,6 +26,7 @@ #include "MvLayerUpCmd.h" #include "MvLayerDnCmd.h" #include "ScaleSurfaceFromToCmd.h" +#include "MvSurfaceVertCmd.h" #include "SurfaceType.h" #include "Gui.h" @@ -59,6 +60,10 @@ class ProjectionMappingState : public ApplicationBaseState { static ProjectionMappingState * _instance; float _surfaceScaleBeforeTransform; + + ofVec2f _clickPosition; + + bool _bSurfaceDrag; }; diff --git a/src/Application/States/TextureMappingState.cpp b/src/Application/States/TextureMappingState.cpp index b94868f..36228d2 100644 --- a/src/Application/States/TextureMappingState.cpp +++ b/src/Application/States/TextureMappingState.cpp @@ -176,7 +176,6 @@ void TextureMappingState::onMousePressed(Application * app, ofMouseEventArgs & a return; } - // Old code from SurfaceManagerGui CircleJoint * hitJoint = Gui::instance()->getTextureEditorWidget().hitTestJoints(ofVec2f(args.x, args.y)); @@ -201,8 +200,8 @@ void TextureMappingState::onMousePressed(Application * app, ofMouseEventArgs & a }else if(app->getSurfaceManager()->getSelectedSurface()->getTextureHitArea().inside(args.x, args.y)){ - app->getGui()->clickPosition = ofVec2f(args.x, args.y); - app->getGui()->startDrag(); + _clickPosition = ofPoint(args.x, args.y); + _bCropAreaDrag = true; // TODO: emit event through the gui singleton app->getCmdManager()->exec(new MvAllTexCoordsCmd( @@ -231,7 +230,7 @@ void TextureMappingState::onMouseReleased(Application * app, ofMouseEventArgs & args.x -= _canvasTranslate.x; args.y -= _canvasTranslate.y; - app->getGui()->stopDrag(); + _bCropAreaDrag = false; Gui::instance()->getTextureEditorWidget().stopDragJoints(); } @@ -242,11 +241,11 @@ void TextureMappingState::onMouseDragged(Application * app, ofMouseEventArgs & a args.y -= _canvasTranslate.y; Gui::instance()->getTextureEditorWidget().onMouseDragged(args); - if(app->getGui()->bDrag){ - ofVec2f mousePosition = ofVec2f(args.x, args.y); - ofVec2f distance = mousePosition - app->getGui()->clickPosition; + if(_bCropAreaDrag){ + ofPoint mousePosition = ofPoint(args.x, args.y); + ofPoint distance = mousePosition - _clickPosition; Gui::instance()->getTextureEditorWidget().moveTexCoords(distance); - app->getGui()->clickPosition = mousePosition; + _clickPosition = mousePosition; } }else{ ofPoint mousePosition = ofPoint(args.x, args.y); diff --git a/src/Application/States/TextureMappingState.h b/src/Application/States/TextureMappingState.h index 275226f..b7dacd0 100644 --- a/src/Application/States/TextureMappingState.h +++ b/src/Application/States/TextureMappingState.h @@ -12,6 +12,8 @@ #include "ToggleAnimatedSourceCmd.h" #include "TranslateCanvasCmd.h" #include "SetTexMapDrawModeCmd.h" +#include "MvTexCoordCmd.h" +#include "MvAllTexCoordsCmd.h" #include "Gui.h" namespace ofx { @@ -47,6 +49,7 @@ class TextureMappingState : public ApplicationBaseState { TextureMappingState(); bool _bTranslateCanvas; + bool _bCropAreaDrag; int _drawMode; diff --git a/src/Surfaces/SurfaceManagerGui.cpp b/src/Surfaces/SurfaceManagerGui.cpp deleted file mode 100644 index 74721b1..0000000 --- a/src/Surfaces/SurfaceManagerGui.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "SurfaceManagerGui.h" - -namespace ofx { -namespace piMapper { - -SurfaceManagerGui::SurfaceManagerGui(){ - guiMode = GuiMode::NONE; - bDrag = false; - ofHideCursor(); - _cmdManager = 0; -} - -void SurfaceManagerGui::setMediaServer(MediaServer * newMediaServer){ - mediaServer = newMediaServer; -} - -void SurfaceManagerGui::setCmdManager(CmdManager * cmdManager){ - _cmdManager = cmdManager; -} - -void SurfaceManagerGui::setMode(int newGuiMode){ - if(newGuiMode != GuiMode::NONE && newGuiMode != GuiMode::TEXTURE_MAPPING && - newGuiMode != GuiMode::PROJECTION_MAPPING && - newGuiMode != GuiMode::SOURCE_SELECTION){ - throw runtime_error("Trying to set invalid mode."); - } - - if(newGuiMode == GuiMode::NONE){ - ofHideCursor(); - }else{ - ofShowCursor(); - } - - guiMode = newGuiMode; -} - -int SurfaceManagerGui::getMode(){ - return guiMode; -} - -void SurfaceManagerGui::startDrag(){ - bDrag = true; -} - -void SurfaceManagerGui::stopDrag(){ - bDrag = false; -} - -} // namespace piMapper -} // namespace ofx \ No newline at end of file diff --git a/src/Surfaces/SurfaceManagerGui.h b/src/Surfaces/SurfaceManagerGui.h deleted file mode 100644 index 0fbf5a2..0000000 --- a/src/Surfaces/SurfaceManagerGui.h +++ /dev/null @@ -1,49 +0,0 @@ -// TODO: Move this to the Application State system. - -#pragma once - -#include "ofEvents.h" -#include "ofGraphics.h" - -#include "SurfaceManager.h" -#include "GuiMode.h" -#include "CmdManager.h" -#include "SelSurfaceCmd.h" -#include "MvSurfaceVertCmd.h" -#include "MvAllTexCoordsCmd.h" -#include "MvTexCoordCmd.h" -#include "SelVertexCmd.h" -#include "DeselectSurfaceCmd.h" -#include "Gui.h" - -namespace ofx { -namespace piMapper { - -class SurfaceManagerGui { - - public: - SurfaceManagerGui(); - - void setMediaServer(MediaServer * newMediaServer); - void setCmdManager(CmdManager * cmdManager); - - void setMode(int newGuiMode); - int getMode(); - void startDrag(); - void stopDrag(); - - ofVec2f clickPosition; - bool bDrag; - - private: - SurfaceManager * surfaceManager; - MediaServer * mediaServer; - - int guiMode; - - CmdManager * _cmdManager; - -}; - -} // namespace piMapper -} // namespace ofx \ No newline at end of file diff --git a/src/ofxPiMapper.h b/src/ofxPiMapper.h index 64c3990..5012daf 100644 --- a/src/ofxPiMapper.h +++ b/src/ofxPiMapper.h @@ -2,7 +2,6 @@ #include "ofMain.h" #include "SurfaceManager.h" -#include "SurfaceManagerGui.h" #include "MediaServer.h" #include "FboSource.h" #include "BaseCmd.h"