From 7430c64655060491460a2726a21de077f8b28329 Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Mon, 15 Feb 2016 17:07:20 +0100 Subject: [PATCH] Optimize `SurfaceManagerGui` Replace the initiation of `StartDragSurfaceCmd` with an emited event that is being handled elsewhere --- src/Surfaces/SurfaceManagerGui.cpp | 63 +++++++++++------------------- src/Surfaces/SurfaceManagerGui.h | 1 - 2 files changed, 22 insertions(+), 42 deletions(-) diff --git a/src/Surfaces/SurfaceManagerGui.cpp b/src/Surfaces/SurfaceManagerGui.cpp index 2b03672..099322a 100644 --- a/src/Surfaces/SurfaceManagerGui.cpp +++ b/src/Surfaces/SurfaceManagerGui.cpp @@ -137,57 +137,38 @@ void SurfaceManagerGui::mousePressed(ofMouseEventArgs & args){ } }else if(guiMode == GuiMode::PROJECTION_MAPPING){ - bool bSurfaceSelected = false; - - CircleJoint * hitJoint = - projectionEditor.hitTestJoints(ofVec2f(args.x, args.y)); - if(hitJoint != 0){ - projectionEditor.unselectAllJoints(); - hitJoint->select(); - hitJoint->startDrag(); - int jointVertIndex = 0; - - for(int i = 0; i < projectionEditor.getJoints()->size(); i++){ + CircleJoint * hitJoint = 0; + int hitJointIndex = -1; + BaseSurface * hitSurface = 0; + + hitJoint = projectionEditor.hitTestJoints(ofVec2f(args.x, args.y)); + + if(hitJoint){ + for(int i = projectionEditor.getJoints()->size() - 1; i >= 0 ; --i){ if((*projectionEditor.getJoints())[i] == hitJoint){ - jointVertIndex = i; + hitJointIndex = i; break; } } - - Gui::instance()->notifyJointPressed(args, jointVertIndex); - bSurfaceSelected = true; - } - - // attempt to select surface, loop from end to beginning - if(!bSurfaceSelected){ - for(int i = surfaceManager->size() - 1; i >= 0; i--){ + }else{ + for(int i = surfaceManager->size() - 1; i >= 0; --i){ if(surfaceManager->getSurface(i)->hitTest(ofVec2f(args.x, args.y))){ - Gui::instance()->notifySurfacePressed(args, surfaceManager->getSurface(i)); - bSurfaceSelected = true; + hitSurface = surfaceManager->getSurface(i); break; } } } - - if(bSurfaceSelected && hitJoint == 0){ - - // if not hitting the joints, start drag only if - // we have a selected surface + + if(hitJoint){ + hitJoint->select(); + hitJoint->startDrag(); + Gui::instance()->notifyJointPressed(args, hitJointIndex); + }else if(hitSurface){ clickPosition = ofVec2f(args.x, args.y); - startDrag(); - - // TODO: emit event through the gui singleton - _cmdManager->exec( - new MvSurfaceCmd( - surfaceManager->getSelectedSurface(), - &projectionEditor)); - } - - if(!bSurfaceSelected){ - // unselect if no surface selected - projectionEditor.clearJoints(); - - // TODO: emit event though the gui singleton + startDrag(); // TODO: Should be something like `hitSurface->startDrag()` + Gui::instance()->notifySurfacePressed(args, hitSurface); + }else{ + //projectionEditor.clearJoints(); _cmdManager->exec(new DeselectSurfaceCmd(surfaceManager)); } }else if(guiMode == GuiMode::SOURCE_SELECTION){} diff --git a/src/Surfaces/SurfaceManagerGui.h b/src/Surfaces/SurfaceManagerGui.h index 4005a0e..4fb4483 100644 --- a/src/Surfaces/SurfaceManagerGui.h +++ b/src/Surfaces/SurfaceManagerGui.h @@ -11,7 +11,6 @@ #include "SourcesEditor.h" #include "GuiMode.h" #include "CmdManager.h" -#include "MvSurfaceCmd.h" #include "SelSurfaceCmd.h" #include "MvSurfaceVertCmd.h" #include "MvAllTexCoordsCmd.h"