diff --git a/src/Application/Application.cpp b/src/Application/Application.cpp index 5448f03..6c8819c 100644 --- a/src/Application/Application.cpp +++ b/src/Application/Application.cpp @@ -152,15 +152,7 @@ void Application::onBackgroundPressed(GuiBackgroundEvent & e){ } void Application::onGuiEvent(GuiEvent & e){ - if(e.widget == &Gui::instance()->getScaleWidget()){ - if(e.args.type == e.args.Pressed){ - cout << "Scale Pressed" << endl; - }else if(e.args.type == e.args.Released){ - cout << "Scale Released" << endl; - }else if(e.args.type == e.args.Dragged){ - cout << "Scale Dragged" << endl; - } - } + _state->onGuiEvent(this, e); } void Application::addFboSource(FboSource & fboSource){ diff --git a/src/Application/ApplicationBaseState.h b/src/Application/ApplicationBaseState.h index 19ca573..80aa507 100644 --- a/src/Application/ApplicationBaseState.h +++ b/src/Application/ApplicationBaseState.h @@ -23,6 +23,8 @@ class ApplicationBaseState { virtual void onJointPressed(Application * app, GuiJointEvent & e){} virtual void onSurfacePressed(Application * app, GuiSurfaceEvent & e){} virtual void onBackgroundPressed(Application * app, GuiBackgroundEvent & e){} + + virtual void onGuiEvent(Application * app, GuiEvent & e) = 0; }; diff --git a/src/Application/PresentationState.h b/src/Application/PresentationState.h index c30e706..091a136 100644 --- a/src/Application/PresentationState.h +++ b/src/Application/PresentationState.h @@ -17,6 +17,8 @@ class PresentationState : public ApplicationBaseState { static PresentationState * instance(); void draw(Application * app); void onMousePressed(Application * app, ofMouseEventArgs & args); + + void onGuiEvent(Application * app, GuiEvent & e){} private: static PresentationState * _instance; diff --git a/src/Application/ProjectionMappingState.cpp b/src/Application/ProjectionMappingState.cpp index ec0d763..2df897d 100644 --- a/src/Application/ProjectionMappingState.cpp +++ b/src/Application/ProjectionMappingState.cpp @@ -334,5 +334,17 @@ void ProjectionMappingState::onBackgroundPressed(Application * app, GuiBackgroun app->getCmdManager()->exec(new DeselectSurfaceCmd(app->getSurfaceManager())); } +void ProjectionMappingState::onGuiEvent(Application * app, GuiEvent & e){ + if(e.widget == &Gui::instance()->getScaleWidget()){ + if(e.args.type == e.args.Pressed){ + cout << "Scale Pressed" << endl; + }else if(e.args.type == e.args.Released){ + cout << "Scale Released" << endl; + }else if(e.args.type == e.args.Dragged){ + cout << "Scale Dragged" << endl; + } + } +} + } // namespace piMapper } // namespace ofx \ No newline at end of file diff --git a/src/Application/ProjectionMappingState.h b/src/Application/ProjectionMappingState.h index 471ba31..c806f8f 100644 --- a/src/Application/ProjectionMappingState.h +++ b/src/Application/ProjectionMappingState.h @@ -48,6 +48,8 @@ class ProjectionMappingState : public ApplicationBaseState { void onJointPressed(Application * app, GuiJointEvent & e); void onSurfacePressed(Application * app, GuiSurfaceEvent & e); void onBackgroundPressed(Application * app, GuiBackgroundEvent & e); + + void onGuiEvent(Application * app, GuiEvent & e); private: static ProjectionMappingState * _instance; diff --git a/src/Application/ScaleWidget.cpp b/src/Application/ScaleWidget.cpp index 527c2ee..0dd681f 100644 --- a/src/Application/ScaleWidget.cpp +++ b/src/Application/ScaleWidget.cpp @@ -40,19 +40,21 @@ void ScaleWidget::onMousePressed(ofMouseEventArgs & args){ if(_handle.inside(args.x, args.y)){ _dragging = true; _originalLine = _line; + + GuiWidgetEvent e; + e.args = args; + ofNotifyEvent(guiWidgetEvent, e, this); } - - GuiWidgetEvent e; - e.args = args; - ofNotifyEvent(guiWidgetEvent, e, this); } void ScaleWidget::onMouseReleased(ofMouseEventArgs & args){ - _dragging = false; + if(_dragging){ + GuiWidgetEvent e; + e.args = args; + ofNotifyEvent(guiWidgetEvent, e, this); + } - GuiWidgetEvent e; - e.args = args; - ofNotifyEvent(guiWidgetEvent, e, this); + _dragging = false; } void ScaleWidget::onMouseDragged(ofMouseEventArgs & args){ @@ -62,11 +64,11 @@ void ScaleWidget::onMouseDragged(ofMouseEventArgs & args){ _line[1].x = args.x; _line[1].y = args.y; + + GuiWidgetEvent e; + e.args = args; + ofNotifyEvent(guiWidgetEvent, e, this); } - - GuiWidgetEvent e; - e.args = args; - ofNotifyEvent(guiWidgetEvent, e, this); } bool ScaleWidget::inside(float x, float y){ diff --git a/src/Application/SourceSelectionState.h b/src/Application/SourceSelectionState.h index e1bfdba..fb0b1b8 100644 --- a/src/Application/SourceSelectionState.h +++ b/src/Application/SourceSelectionState.h @@ -13,6 +13,8 @@ class SourceSelectionState : public ApplicationBaseState { public: static SourceSelectionState * instance(); void draw(Application * app); + + void onGuiEvent(Application * app, GuiEvent & e){} private: static SourceSelectionState * _instance; diff --git a/src/Application/TextureMappingState.h b/src/Application/TextureMappingState.h index b18610d..f66dd68 100644 --- a/src/Application/TextureMappingState.h +++ b/src/Application/TextureMappingState.h @@ -21,6 +21,8 @@ class TextureMappingState : public ApplicationBaseState { void draw(Application * app); void onKeyPressed(Application * app, ofKeyEventArgs & args); void onBackgroundPressed(Application * app, GuiBackgroundEvent & e); + + void onGuiEvent(Application * app, GuiEvent & e){} private: static TextureMappingState * _instance;