Browse Source

Optimize `SurfaceManagerGui`

Replace the initiation of `StartDragSurfaceCmd` with an emited event that is being handled elsewhere
master
Krisjanis Rijnieks 9 years ago
parent
commit
7430c64655
  1. 57
      src/Surfaces/SurfaceManagerGui.cpp
  2. 1
      src/Surfaces/SurfaceManagerGui.h

57
src/Surfaces/SurfaceManagerGui.cpp

@ -137,57 +137,38 @@ void SurfaceManagerGui::mousePressed(ofMouseEventArgs & args){
} }
}else if(guiMode == GuiMode::PROJECTION_MAPPING){ }else if(guiMode == GuiMode::PROJECTION_MAPPING){
bool bSurfaceSelected = false; CircleJoint * hitJoint = 0;
int hitJointIndex = -1;
BaseSurface * hitSurface = 0;
CircleJoint * hitJoint = hitJoint = projectionEditor.hitTestJoints(ofVec2f(args.x, args.y));
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++){ if(hitJoint){
for(int i = projectionEditor.getJoints()->size() - 1; i >= 0 ; --i){
if((*projectionEditor.getJoints())[i] == hitJoint){ if((*projectionEditor.getJoints())[i] == hitJoint){
jointVertIndex = i; hitJointIndex = i;
break; break;
} }
} }
}else{
Gui::instance()->notifyJointPressed(args, jointVertIndex); for(int i = surfaceManager->size() - 1; i >= 0; --i){
bSurfaceSelected = true;
}
// attempt to select surface, loop from end to beginning
if(!bSurfaceSelected){
for(int i = surfaceManager->size() - 1; i >= 0; i--){
if(surfaceManager->getSurface(i)->hitTest(ofVec2f(args.x, args.y))){ if(surfaceManager->getSurface(i)->hitTest(ofVec2f(args.x, args.y))){
Gui::instance()->notifySurfacePressed(args, surfaceManager->getSurface(i)); hitSurface = surfaceManager->getSurface(i);
bSurfaceSelected = true;
break; break;
} }
} }
} }
if(bSurfaceSelected && hitJoint == 0){ if(hitJoint){
hitJoint->select();
// if not hitting the joints, start drag only if hitJoint->startDrag();
// we have a selected surface Gui::instance()->notifyJointPressed(args, hitJointIndex);
}else if(hitSurface){
clickPosition = ofVec2f(args.x, args.y); clickPosition = ofVec2f(args.x, args.y);
startDrag(); startDrag(); // TODO: Should be something like `hitSurface->startDrag()`
Gui::instance()->notifySurfacePressed(args, hitSurface);
// TODO: emit event through the gui singleton }else{
_cmdManager->exec( //projectionEditor.clearJoints();
new MvSurfaceCmd(
surfaceManager->getSelectedSurface(),
&projectionEditor));
}
if(!bSurfaceSelected){
// unselect if no surface selected
projectionEditor.clearJoints();
// TODO: emit event though the gui singleton
_cmdManager->exec(new DeselectSurfaceCmd(surfaceManager)); _cmdManager->exec(new DeselectSurfaceCmd(surfaceManager));
} }
}else if(guiMode == GuiMode::SOURCE_SELECTION){} }else if(guiMode == GuiMode::SOURCE_SELECTION){}

1
src/Surfaces/SurfaceManagerGui.h

@ -11,7 +11,6 @@
#include "SourcesEditor.h" #include "SourcesEditor.h"
#include "GuiMode.h" #include "GuiMode.h"
#include "CmdManager.h" #include "CmdManager.h"
#include "MvSurfaceCmd.h"
#include "SelSurfaceCmd.h" #include "SelSurfaceCmd.h"
#include "MvSurfaceVertCmd.h" #include "MvSurfaceVertCmd.h"
#include "MvAllTexCoordsCmd.h" #include "MvAllTexCoordsCmd.h"

Loading…
Cancel
Save