diff --git a/src/Application/States/TextureMappingState.cpp b/src/Application/States/TextureMappingState.cpp index d5c471e..8f17609 100644 --- a/src/Application/States/TextureMappingState.cpp +++ b/src/Application/States/TextureMappingState.cpp @@ -12,19 +12,31 @@ TextureMappingState * TextureMappingState::instance(){ return _instance; } +TextureMappingState::TextureMappingState(){ + _bTranslateCanvas = false; +} + void TextureMappingState::draw(Application * app){ + ofPushMatrix(); + ofTranslate(_canvasTranslate.x, _canvasTranslate.y); app->getGui()->draw(); + ofPopMatrix(); ofPushStyle(); ofSetColor(255, 255, 255, 150); app->getSurfaceManager()->draw(); ofPopStyle(); + ofPushMatrix(); + ofTranslate(_canvasTranslate.x, _canvasTranslate.y); + Gui::instance()->getSurfaceHighlightWidget().setSurfaceManager(app->getSurfaceManager()); Gui::instance()->getSurfaceHighlightWidget().draw(); Gui::instance()->getTextureHighlightWidget().setSurfaceManager(app->getSurfaceManager()); Gui::instance()->getTextureHighlightWidget().draw(); + + ofPopMatrix(); } void TextureMappingState::onKeyPressed(Application * app, ofKeyEventArgs & args){ @@ -67,8 +79,30 @@ void TextureMappingState::onKeyPressed(Application * app, ofKeyEventArgs & args) } void TextureMappingState::onBackgroundPressed(Application * app, GuiBackgroundEvent & e){ - app->getCmdManager()->exec( + cout << "TextureMappingState::onBackgroundPressed()" << endl; + + app->getCmdManager()->exec( new DeselectTexCoordCmd(app->getGui()->getTextureEditor())); + + _bTranslateCanvas = true; + _clickPosition = ofPoint(e.args.x, e.args.y); + _clickCanvasTranslate = _canvasTranslate; +} + +void TextureMappingState::onMouseReleased(Application * app, ofMouseEventArgs & args){ + cout << "TextureMappingState::onMouseReleased()" << endl; + + _bTranslateCanvas = false; +} + +void TextureMappingState::onMouseDragged(Application * app, ofMouseEventArgs & args){ + if(!_bTranslateCanvas){ + return; + } + + ofPoint mousePosition = ofPoint(args.x, args.y); + ofPoint distance = mousePosition - _clickPosition; + _canvasTranslate = _clickCanvasTranslate + distance; } } // namespace piMapper diff --git a/src/Application/States/TextureMappingState.h b/src/Application/States/TextureMappingState.h index c905f26..18ac531 100644 --- a/src/Application/States/TextureMappingState.h +++ b/src/Application/States/TextureMappingState.h @@ -22,11 +22,21 @@ class TextureMappingState : public ApplicationBaseState { void draw(Application * app); void onKeyPressed(Application * app, ofKeyEventArgs & args); void onBackgroundPressed(Application * app, GuiBackgroundEvent & e); + void onMouseReleased(Application * app, ofMouseEventArgs & args); + void onMouseDragged(Application * app, ofMouseEventArgs & args); void onGuiEvent(Application * app, GuiEvent & e){} private: static TextureMappingState * _instance; + + TextureMappingState(); + + bool _bTranslateCanvas; + + ofPoint _clickPosition; + ofPoint _canvasTranslate; + ofPoint _clickCanvasTranslate; };