From 77efc60938c05c67355178b9a6cc9fcdb8229b6c Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Wed, 2 Nov 2016 17:18:02 +0100 Subject: [PATCH] Clean up TextureMappingMode --- src/Application/Modes/TextureMappingMode.cpp | 25 +++++++------------- src/Application/Modes/TextureMappingMode.h | 12 ++++++---- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/Application/Modes/TextureMappingMode.cpp b/src/Application/Modes/TextureMappingMode.cpp index ee9c144..80708d0 100644 --- a/src/Application/Modes/TextureMappingMode.cpp +++ b/src/Application/Modes/TextureMappingMode.cpp @@ -164,6 +164,10 @@ void TextureMappingMode::onBackgroundPressed(Application * app, GuiBackgroundEve } void TextureMappingMode::onMousePressed(Application * app, ofMouseEventArgs & args){ + if(app->getSurfaceManager()->getSelectedSurface() == 0){ + return; + } + _clickPosition = ofPoint(args.x, args.y); _prevCanvasTranslate = _canvasTranslate; @@ -171,19 +175,12 @@ void TextureMappingMode::onMousePressed(Application * app, ofMouseEventArgs & ar args.x -= _canvasTranslate.x; args.y -= _canvasTranslate.y; - if(app->getSurfaceManager()->getSelectedSurface() == 0){ - return; - } - CircleJoint * hitJoint = - Gui::instance()->getTextureEditorWidget().hitTestJoints(ofVec2f(args.x, args.y)); + Gui::instance()->getTextureEditorWidget().hitTestJoints( + ofVec2f(args.x, args.y)); if(hitJoint != 0){ hitJoint->mousePressed(args); - //Gui::instance()->getTextureEditorWidget().unselectAllJoints(); - - //hitJoint->select(); - int selectedTexCoord = -1; for(int i = 0; i < Gui::instance()->getTextureEditorWidget().getJoints().size(); ++i){ if(hitJoint == Gui::instance()->getTextureEditorWidget().getJoints()[i]){ @@ -200,11 +197,9 @@ void TextureMappingMode::onMousePressed(Application * app, ofMouseEventArgs & ar } hitJoint->startDrag(); - // TODO: Make the following better, more direct. - // Move this to mouseReleased part as we nee to save the previous location only - // if the move has happened. - _texCoordOnClick = app->getSurfaceManager()->getSelectedSurface()->getTexCoords()[selectedTexCoord]; - //app->getCmdManager()->exec(new SaveTexCoordPosCmd(selectedTexCoord, tex)); + + _texCoordOnClick = + app->getSurfaceManager()->getSelectedSurface()->getTexCoords()[selectedTexCoord]; }else if(app->getSurfaceManager()->getSelectedSurface()->getTextureHitArea().inside(args.x, args.y)){ _clickPosition = ofPoint(args.x, args.y); @@ -291,8 +286,6 @@ void TextureMappingMode::drawTexture(Application * app){ void TextureMappingMode::moveSelection(Application * app, ofVec2f by){ int selectedTexCoord = Gui::instance()->getTextureEditorWidget().getSelectedTexCoord(); - // TODO: Do the moving only through commands not like now. - if(selectedTexCoord >= 0){ app->getCmdManager()->exec( new MvTexCoordCmd(selectedTexCoord, by)); diff --git a/src/Application/Modes/TextureMappingMode.h b/src/Application/Modes/TextureMappingMode.h index c20b67e..8a537ca 100644 --- a/src/Application/Modes/TextureMappingMode.h +++ b/src/Application/Modes/TextureMappingMode.h @@ -29,20 +29,22 @@ class TextureMappingMode : public ApplicationBaseMode { void setup(Application * app); void update(Application * app); 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); + void onGuiEvent(Application * app, GuiEvent & e){} + void drawTexture(Application * app); void moveSelection(Application * app, ofVec2f by); - void onGuiEvent(Application * app, GuiEvent & e){} - - ofPoint getTranslation(); void setTranslation(ofPoint p); - void setDrawMode(int m); + + ofPoint getTranslation(); + int getDrawMode(); int getNextDrawMode(); int getPrevDrawMode(); @@ -59,7 +61,7 @@ class TextureMappingMode : public ApplicationBaseMode { ofPoint _clickPosition; ofPoint _canvasTranslate; - ofPoint _prevCanvasTranslate; // Canvas translate before TranslateCanvasCmd command exec + ofPoint _prevCanvasTranslate; ofPoint _clickCanvasTranslate; ofVec2f _texCoordOnClick;