diff --git a/src/Application/States/TextureMappingState.cpp b/src/Application/States/TextureMappingState.cpp index 8f17609..0c520ba 100644 --- a/src/Application/States/TextureMappingState.cpp +++ b/src/Application/States/TextureMappingState.cpp @@ -14,6 +14,8 @@ TextureMappingState * TextureMappingState::instance(){ TextureMappingState::TextureMappingState(){ _bTranslateCanvas = false; + _canvasTranslate = ofPoint(0, 0); + _clickCanvasTranslate = ofPoint(0, 0); } void TextureMappingState::draw(Application * app){ @@ -85,24 +87,42 @@ void TextureMappingState::onBackgroundPressed(Application * app, GuiBackgroundEv new DeselectTexCoordCmd(app->getGui()->getTextureEditor())); _bTranslateCanvas = true; - _clickPosition = ofPoint(e.args.x, e.args.y); - _clickCanvasTranslate = _canvasTranslate; + +} + +void TextureMappingState::onMousePressed(Application * app, ofMouseEventArgs & args){ + _clickPosition = ofPoint(args.x, args.y); + + // Alter mouse event args to match canvas translation + args.x -= _canvasTranslate.x; + args.y -= _canvasTranslate.y; + app->getGui()->mousePressed(args); } void TextureMappingState::onMouseReleased(Application * app, ofMouseEventArgs & args){ cout << "TextureMappingState::onMouseReleased()" << endl; _bTranslateCanvas = false; + + _clickCanvasTranslate = _canvasTranslate; + + // Alter mouse event args to match canvas translation + args.x -= _canvasTranslate.x; + args.y -= _canvasTranslate.y; + app->getGui()->mouseReleased(args); } void TextureMappingState::onMouseDragged(Application * app, ofMouseEventArgs & args){ if(!_bTranslateCanvas){ - return; + // Alter mouse event args to match canvas translation + args.x -= _canvasTranslate.x; + args.y -= _canvasTranslate.y; + app->getGui()->mouseDragged(args); + }else{ + ofPoint mousePosition = ofPoint(args.x, args.y); + ofPoint distance = mousePosition - _clickPosition; + _canvasTranslate = _clickCanvasTranslate + distance; } - - 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 18ac531..dee24b3 100644 --- a/src/Application/States/TextureMappingState.h +++ b/src/Application/States/TextureMappingState.h @@ -22,6 +22,7 @@ class TextureMappingState : public ApplicationBaseState { void draw(Application * app); void onKeyPressed(Application * app, ofKeyEventArgs & args); void onBackgroundPressed(Application * app, GuiBackgroundEvent & e); + void onMousePressed(Application * app, ofMouseEventArgs & args); void onMouseReleased(Application * app, ofMouseEventArgs & args); void onMouseDragged(Application * app, ofMouseEventArgs & args); diff --git a/src/Surfaces/SurfaceManagerGui.cpp b/src/Surfaces/SurfaceManagerGui.cpp index 0b3acb8..fd5339a 100644 --- a/src/Surfaces/SurfaceManagerGui.cpp +++ b/src/Surfaces/SurfaceManagerGui.cpp @@ -19,21 +19,21 @@ SurfaceManagerGui::~SurfaceManagerGui(){ } void SurfaceManagerGui::registerMouseEvents(){ - ofAddListener(ofEvents().mousePressed, this, - &SurfaceManagerGui::mousePressed); - ofAddListener(ofEvents().mouseReleased, this, - &SurfaceManagerGui::mouseReleased); - ofAddListener(ofEvents().mouseDragged, this, - &SurfaceManagerGui::mouseDragged); + //ofAddListener(ofEvents().mousePressed, this, + // &SurfaceManagerGui::mousePressed); + //ofAddListener(ofEvents().mouseReleased, this, + // &SurfaceManagerGui::mouseReleased); + //ofAddListener(ofEvents().mouseDragged, this, + // &SurfaceManagerGui::mouseDragged); } void SurfaceManagerGui::unregisterMouseEvents(){ - ofRemoveListener(ofEvents().mousePressed, this, - &SurfaceManagerGui::mousePressed); - ofRemoveListener(ofEvents().mouseReleased, this, - &SurfaceManagerGui::mouseReleased); - ofRemoveListener(ofEvents().mouseDragged, this, - &SurfaceManagerGui::mouseDragged); + //ofRemoveListener(ofEvents().mousePressed, this, + // &SurfaceManagerGui::mousePressed); + //ofRemoveListener(ofEvents().mouseReleased, this, + // &SurfaceManagerGui::mouseReleased); + //ofRemoveListener(ofEvents().mouseDragged, this, + // &SurfaceManagerGui::mouseDragged); } void SurfaceManagerGui::draw(){ @@ -77,6 +77,8 @@ void SurfaceManagerGui::mousePressed(ofMouseEventArgs & args){ CircleJoint * hitJoint = textureEditor.hitTestJoints(ofVec2f(args.x, args.y)); if(hitJoint != 0){ + + hitJoint->mousePressed(args); textureEditor.unselectAllJoints(); hitJoint->select(); @@ -155,13 +157,14 @@ void SurfaceManagerGui::mouseReleased(ofMouseEventArgs & args){ if(!surfaceManager->getSelectedSurface()->getMoved()){ // TODO: emit event through the gui singleton - _cmdManager->undo(); + //_cmdManager->undo(); } } - } void SurfaceManagerGui::mouseDragged(ofMouseEventArgs & args){ + textureEditor.mouseDragged(args); + if(bDrag){ ofVec2f mousePosition = ofVec2f(args.x, args.y); ofVec2f distance = mousePosition - clickPosition; diff --git a/src/UserInterface/BaseJoint.cpp b/src/UserInterface/BaseJoint.cpp index 2788d7a..c5d65cb 100644 --- a/src/UserInterface/BaseJoint.cpp +++ b/src/UserInterface/BaseJoint.cpp @@ -14,16 +14,18 @@ BaseJoint::~BaseJoint(){ } void BaseJoint::registerMouseEvents(){ - ofAddListener(ofEvents().mousePressed, this, &BaseJoint::mousePressed); - ofAddListener(ofEvents().mouseDragged, this, &BaseJoint::mouseDragged); + //ofAddListener(ofEvents().mousePressed, this, &BaseJoint::mousePressed); + //ofAddListener(ofEvents().mouseDragged, this, &BaseJoint::mouseDragged); } void BaseJoint::unregisterMouseEvents(){ - ofRemoveListener(ofEvents().mousePressed, this, &BaseJoint::mousePressed); - ofRemoveListener(ofEvents().mouseDragged, this, &BaseJoint::mouseDragged); + //ofRemoveListener(ofEvents().mousePressed, this, &BaseJoint::mousePressed); + //ofRemoveListener(ofEvents().mouseDragged, this, &BaseJoint::mouseDragged); } void BaseJoint::mousePressed(ofMouseEventArgs & args){ + cout << "BaseJoint::mousePressed()" << endl; + if(hitTest(ofVec2f(args.x, args.y))){ // selected = true; clickDistance = position - ofVec2f(args.x, args.y); @@ -36,6 +38,8 @@ void BaseJoint::mouseReleased(int x, int y, int button){ } void BaseJoint::mouseDragged(ofMouseEventArgs & args){ + cout << "BaseJoint::mouseDragged()" << endl; + if(!bDrag){ return; } diff --git a/src/UserInterface/TextureEditor.cpp b/src/UserInterface/TextureEditor.cpp index 4ba8088..8210272 100644 --- a/src/UserInterface/TextureEditor.cpp +++ b/src/UserInterface/TextureEditor.cpp @@ -152,6 +152,18 @@ void TextureEditor::keyReleased(ofKeyEventArgs & args){ } } +void TextureEditor::mousePressed(ofMouseEventArgs & args){ + for(unsigned int i = 0; i < joints.size(); ++i){ + joints[i]->mousePressed(args); + } +} + +void TextureEditor::mouseDragged(ofMouseEventArgs & args){ + for(unsigned int i = 0; i < joints.size(); ++i){ + joints[i]->mouseDragged(args); + } +} + void TextureEditor::draw(){ if(surface == 0){ return; diff --git a/src/UserInterface/TextureEditor.h b/src/UserInterface/TextureEditor.h index d73a70a..cc1fe09 100644 --- a/src/UserInterface/TextureEditor.h +++ b/src/UserInterface/TextureEditor.h @@ -26,6 +26,8 @@ class TextureEditor { void update(ofEventArgs & args); void keyPressed(ofKeyEventArgs & args); void keyReleased(ofKeyEventArgs & args); + void mousePressed(ofMouseEventArgs & args); + void mouseDragged(ofMouseEventArgs & args); void draw(); void drawJoints(); void setSurface(BaseSurface * newSurface);