From fc0055cad7e7ba14b8ae405c11be974b9faf8135 Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Wed, 28 Sep 2016 17:17:58 +0300 Subject: [PATCH] Integrate the SourcesEditorWidget into Application --- src/Application/Application.h | 7 ++++--- src/Application/States/ProjectionMappingState.cpp | 2 +- src/Application/States/SourceSelectionState.cpp | 10 ++++++---- src/Application/States/TextureMappingState.cpp | 2 +- src/Commands/SetApplicationStateCmd.cpp | 12 ++++++++++++ src/Gui/Gui.cpp | 4 ++++ src/Gui/Gui.h | 3 +++ src/Gui/Widgets/SourcesEditorWidget.cpp | 2 ++ src/Surfaces/SurfaceManagerGui.cpp | 9 +++++++-- src/Surfaces/SurfaceManagerGui.h | 4 ++-- 10 files changed, 42 insertions(+), 13 deletions(-) diff --git a/src/Application/Application.h b/src/Application/Application.h index 18d062f..b9c13b5 100644 --- a/src/Application/Application.h +++ b/src/Application/Application.h @@ -63,9 +63,10 @@ class Application : public KeyListener { bool loadXmlSettings(string fileName); bool isShiftKeyDown(); - SurfaceManagerGui * getGui(){ return &_gui; }; - SurfaceManager * getSurfaceManager(){ return &_surfaceManager; }; - CmdManager * getCmdManager(){ return &_cmdManager; }; + SurfaceManagerGui * getGui(){ return &_gui; } + SurfaceManager * getSurfaceManager(){ return &_surfaceManager; } + CmdManager * getCmdManager(){ return &_cmdManager; } + MediaServer * getMediaServer(){ return &_mediaServer; } void onCharacterReceived(KeyListenerEventData & e); TerminalListener consoleListener; diff --git a/src/Application/States/ProjectionMappingState.cpp b/src/Application/States/ProjectionMappingState.cpp index 67f54dd..425d45f 100644 --- a/src/Application/States/ProjectionMappingState.cpp +++ b/src/Application/States/ProjectionMappingState.cpp @@ -216,7 +216,7 @@ void ProjectionMappingState::onKeyPressed(Application * app, ofKeyEventArgs & ar app->getCmdManager()->exec( new SetNextSourceCmd( app->getSurfaceManager()->getSelectedSurface(), - app->getGui()->getSourcesEditorWidget())); + &Gui::instance()->getSourcesEditorWidget())); }else{ app->getCmdManager()->exec(new SelNextSurfaceCmd(app->getSurfaceManager())); } diff --git a/src/Application/States/SourceSelectionState.cpp b/src/Application/States/SourceSelectionState.cpp index cc41415..c39f93c 100644 --- a/src/Application/States/SourceSelectionState.cpp +++ b/src/Application/States/SourceSelectionState.cpp @@ -13,8 +13,10 @@ SourceSelectionState * SourceSelectionState::instance(){ } void SourceSelectionState::setup(Application * app){ - app->getGui()->getSourcesEditorWidget()->setSurfaceManager(app->getSurfaceManager()); - app->getGui()->getSourcesEditorWidget()->setup(); + Gui::instance()->getSourcesEditorWidget().setSurfaceManager(app->getSurfaceManager()); + Gui::instance()->getSourcesEditorWidget().setMediaServer(app->getMediaServer()); + Gui::instance()->getSourcesEditorWidget().setCmdManager(app->getCmdManager()); + Gui::instance()->getSourcesEditorWidget().setup(); } void SourceSelectionState::draw(Application * app){ @@ -23,9 +25,9 @@ void SourceSelectionState::draw(Application * app){ app->getSurfaceManager()->draw(); ofPopStyle(); - // TODO: Separate SourcesEditorWidget from SurfaceManagerGui, make it a widget - app->getGui()->getSourcesEditorWidget()->draw(); + Gui::instance()->getSourcesEditorWidget().draw(); + // TODO: Move the following line to setup() Gui::instance()->getSurfaceHighlightWidget().setSurfaceManager(app->getSurfaceManager()); Gui::instance()->getSurfaceHighlightWidget().draw(); } diff --git a/src/Application/States/TextureMappingState.cpp b/src/Application/States/TextureMappingState.cpp index bcfc78d..b94868f 100644 --- a/src/Application/States/TextureMappingState.cpp +++ b/src/Application/States/TextureMappingState.cpp @@ -129,7 +129,7 @@ void TextureMappingState::onKeyPressed(Application * app, ofKeyEventArgs & args) app->getCmdManager()->exec( new SetNextSourceCmd( app->getSurfaceManager()->getSelectedSurface(), - app->getGui()->getSourcesEditorWidget())); + &Gui::instance()->getSourcesEditorWidget())); }else{ app->getCmdManager()->exec(new SelNextSurfaceCmd(app->getSurfaceManager())); } diff --git a/src/Commands/SetApplicationStateCmd.cpp b/src/Commands/SetApplicationStateCmd.cpp index d355c32..841a610 100644 --- a/src/Commands/SetApplicationStateCmd.cpp +++ b/src/Commands/SetApplicationStateCmd.cpp @@ -25,6 +25,12 @@ void SetApplicationStateCmd::exec(){ }else{ ofHideCursor(); } + + if(_applicationState == SourceSelectionState::instance()){ + Gui::instance()->getSourcesEditorWidget().enable(); + }else{ + Gui::instance()->getSourcesEditorWidget().disable(); + } } void SetApplicationStateCmd::undo(){ @@ -40,6 +46,12 @@ void SetApplicationStateCmd::undo(){ }else{ ofHideCursor(); } + + if(_prevApplicationState == SourceSelectionState::instance()){ + Gui::instance()->getSourcesEditorWidget().enable(); + }else{ + Gui::instance()->getSourcesEditorWidget().disable(); + } } } // namespace piMapper diff --git a/src/Gui/Gui.cpp b/src/Gui/Gui.cpp index 1061df6..da147f1 100644 --- a/src/Gui/Gui.cpp +++ b/src/Gui/Gui.cpp @@ -104,6 +104,10 @@ ProjectionEditorWidget & Gui::getProjectionEditorWidget(){ return _projectionEditorWidget; } +SourcesEditorWidget & Gui::getSourcesEditorWidget(){ + return _sourcesEditorWidget; +} + void Gui::onScaleWidgetEvent(GuiWidgetEvent & event){ GuiEvent e; e.args = event.args; diff --git a/src/Gui/Gui.h b/src/Gui/Gui.h index 2150b5a..2b04367 100644 --- a/src/Gui/Gui.h +++ b/src/Gui/Gui.h @@ -10,6 +10,7 @@ #include "TextureHighlightWidget.h" #include "TextureEditorWidget.h" #include "ProjectionEditorWidget.h" +#include "SourcesEditorWidget.h" namespace ofx { namespace piMapper { @@ -71,6 +72,7 @@ class Gui { TextureHighlightWidget & getTextureHighlightWidget(); TextureEditorWidget & getTextureEditorWidget(); ProjectionEditorWidget & getProjectionEditorWidget(); + SourcesEditorWidget & getSourcesEditorWidget(); // Consider these as a part of the application states/modes. void onMousePressed(ofMouseEventArgs & args); @@ -93,6 +95,7 @@ class Gui { TextureHighlightWidget _textureHighlightWidget; TextureEditorWidget _textureEditorWidget; ProjectionEditorWidget _projectionEditorWidget; + SourcesEditorWidget _sourcesEditorWidget; }; } // piMapper diff --git a/src/Gui/Widgets/SourcesEditorWidget.cpp b/src/Gui/Widgets/SourcesEditorWidget.cpp index 834d1bb..b122e9b 100644 --- a/src/Gui/Widgets/SourcesEditorWidget.cpp +++ b/src/Gui/Widgets/SourcesEditorWidget.cpp @@ -67,6 +67,7 @@ void SourcesEditorWidget::draw(){ } } +// TODO: Redesign the selectors completely so they do not need enable and disable. void SourcesEditorWidget::disable(){ if(imageSelector->size()){ imageSelector->disable(); @@ -315,6 +316,7 @@ void SourcesEditorWidget::clearMediaServer(){ mediaServer = 0; } +// TODO: There is no need for those at the moment. They add too much overhead. void SourcesEditorWidget::handleImageAdded(string & path){} void SourcesEditorWidget::handleImageRemoved(string & path){} void SourcesEditorWidget::handleVideoAdded(string & path){} diff --git a/src/Surfaces/SurfaceManagerGui.cpp b/src/Surfaces/SurfaceManagerGui.cpp index 13093bf..8aeb6aa 100644 --- a/src/Surfaces/SurfaceManagerGui.cpp +++ b/src/Surfaces/SurfaceManagerGui.cpp @@ -12,12 +12,12 @@ SurfaceManagerGui::SurfaceManagerGui(){ void SurfaceManagerGui::setMediaServer(MediaServer * newMediaServer){ mediaServer = newMediaServer; - sourcesEditor.setMediaServer(mediaServer); + //sourcesEditor.setMediaServer(mediaServer); } void SurfaceManagerGui::setCmdManager(CmdManager * cmdManager){ _cmdManager = cmdManager; - sourcesEditor.setCmdManager(_cmdManager); + //sourcesEditor.setCmdManager(_cmdManager); } void SurfaceManagerGui::setMode(int newGuiMode){ @@ -35,11 +35,14 @@ void SurfaceManagerGui::setMode(int newGuiMode){ guiMode = newGuiMode; +/* if(guiMode == GuiMode::SOURCE_SELECTION){ sourcesEditor.enable(); }else{ sourcesEditor.disable(); } +*/ + } int SurfaceManagerGui::getMode(){ @@ -54,9 +57,11 @@ void SurfaceManagerGui::stopDrag(){ bDrag = false; } +/* SourcesEditorWidget * SurfaceManagerGui::getSourcesEditorWidget(){ return &sourcesEditor; } +*/ } // namespace piMapper } // namespace ofx \ No newline at end of file diff --git a/src/Surfaces/SurfaceManagerGui.h b/src/Surfaces/SurfaceManagerGui.h index e7c319f..d1863c9 100644 --- a/src/Surfaces/SurfaceManagerGui.h +++ b/src/Surfaces/SurfaceManagerGui.h @@ -33,7 +33,7 @@ class SurfaceManagerGui { void startDrag(); void stopDrag(); - SourcesEditorWidget * getSourcesEditorWidget(); + //SourcesEditorWidget * getSourcesEditorWidget(); ofVec2f clickPosition; bool bDrag; @@ -41,7 +41,7 @@ class SurfaceManagerGui { private: SurfaceManager * surfaceManager; MediaServer * mediaServer; - SourcesEditorWidget sourcesEditor; + //SourcesEditorWidget sourcesEditor; int guiMode;