Browse Source

Fix unwanted surface deselects while in texture mode

master
Krisjanis Rijnieks 11 years ago
parent
commit
4318b947ea
  1. 46
      src/ofxSurfaceGui.cpp
  2. 3
      src/ofxSurfaceGui.h
  3. 11
      src/ofxSurfaceManager.cpp
  4. 1
      src/ofxSurfaceManager.h

46
src/ofxSurfaceGui.cpp

@ -214,16 +214,51 @@ void ofxSurfaceGui::unselect()
} }
bool ofxSurfaceGui::hitTest(float x, float y) bool ofxSurfaceGui::hitTest(float x, float y)
{
if (mode == PROJECTION_MAPPING){
return hitTestProjectionArea(x, y);
} else if (mode == TEXTURE_MAPPING) {
return hitTestTextureArea(x, y);
}
}
bool ofxSurfaceGui::hitTestTextureArea(float x, float y)
{
if ( textureAreaExists() ) {
if ( textureHitarea.inside(x, y) ) {
return true;
} else {
// are we hitting texture mapping joints?
for ( int i=0; i<textureMappingJoints.size(); i++ ) {
if ( textureMappingJoints[i].hitTest(ofVec2f(x, y)) ) {
return true;
}
}
return false;
}
} else {
return false;
} // textureAreaExists()
}
bool ofxSurfaceGui::hitTestProjectionArea(float x, float y)
{ {
if ( projectionAreaExists() ) { if ( projectionAreaExists() ) {
if ( projectionHitarea.inside(x, y) ) { if ( projectionHitarea.inside(x, y) ) {
return true; return true;
} else { } else {
// hitting one of the projection mappting joints also counts,
// so let's check that
for ( int i=0; i<projectionMappingJoints.size(); i++ ) {
if ( projectionMappingJoints[i].hitTest(ofVec2f(x, y)) ) {
return true;
}
}
return false; return false;
} }
} else { } else {
return false; return false;
} } // projectionAreaExists()
} }
bool ofxSurfaceGui::isSelected() bool ofxSurfaceGui::isSelected()
@ -316,4 +351,13 @@ bool ofxSurfaceGui::projectionAreaExists()
} else { } else {
return false; return false;
} }
}
bool ofxSurfaceGui::textureAreaExists()
{
if ( textureHitarea.size() > 2 ) {
return true;
} else {
return false;
}
} }

3
src/ofxSurfaceGui.h

@ -27,6 +27,8 @@ public:
void select(); void select();
void unselect(); void unselect();
bool hitTest(float x, float y); bool hitTest(float x, float y);
bool hitTestTextureArea(float x, float y);
bool hitTestProjectionArea(float x, float y);
bool isSelected(); bool isSelected();
editMode getMode(); editMode getMode();
@ -50,6 +52,7 @@ private:
bool isProjectionMappingJointSelected(); bool isProjectionMappingJointSelected();
bool isTextureMappingJointSelected(); bool isTextureMappingJointSelected();
bool projectionAreaExists(); bool projectionAreaExists();
bool textureAreaExists();
void addProjectionMappingJoint(); void addProjectionMappingJoint();
void addNumProjectionMappingJoints(int num); void addNumProjectionMappingJoints(int num);

11
src/ofxSurfaceManager.cpp

@ -67,9 +67,14 @@ void ofxSurfaceManager::mousePressed(int x, int y, int button)
{ {
bool bSurfaceSelected = false; bool bSurfaceSelected = false;
for ( int i=0; i<surfaceGuis.size(); i++ ) { for ( int i=0; i<surfaceGuis.size(); i++ ) {
if ( surfaceGuis[i]->hitTest(x, y) ) { // check only if in projection mapping mode
selectSurface(i); if ( surfaceGuis[i]->getMode() == ofxSurfaceGui::PROJECTION_MAPPING ) {
bSurfaceSelected = true; if ( surfaceGuis[i]->hitTest(x, y) ) {
selectSurface(i);
bSurfaceSelected = true;
}
} else {
bSurfaceSelected = true; // Hackish - we will need a lot of refractoring here later
} }
surfaceGuis[i]->mousePressed(x, y, button); surfaceGuis[i]->mousePressed(x, y, button);
} }

1
src/ofxSurfaceManager.h

@ -25,7 +25,6 @@ public:
void selectSurface(int index); void selectSurface(int index);
void unselectAllSurfaces(); void unselectAllSurfaces();
int size(); int size();
// TODO: add simple surface
private: private:
deque<ofxTriangleSurface*> triangleSurfaces; deque<ofxTriangleSurface*> triangleSurfaces;

Loading…
Cancel
Save