Browse Source

Add select feature to joints

master
Krisjanis Rijnieks 11 years ago
parent
commit
49b2d855e9
  1. 7
      src/ofxBaseJoint.cpp
  2. 4
      src/ofxBaseJoint.h
  3. 16
      src/ofxCircleJoint.cpp
  4. 2
      src/ofxSurfaceGui.cpp

7
src/ofxBaseJoint.cpp

@ -14,6 +14,7 @@ ofxBaseJoint::~ofxBaseJoint()
void ofxBaseJoint::mousePressed(int x, int y, int button)
{
if ( hitTest(ofVec2f(x, y)) ) {
selected = true;
clickDistance = position - ofVec2f(x, y);
startDrag();
}
@ -47,8 +48,10 @@ bool ofxBaseJoint::isDragged()
void ofxBaseJoint::setDefaultColors()
{
fillColor = ofColor(0,255,255);
strokeColor = ofColor(255,255,255);
fillColor = ofColor(0, 255, 255);
strokeColor = ofColor(255, 255, 255);
fillColorSelected = ofColor(255, 255, 0);
strokeColorSelected = ofColor(255, 0, 0);
}
void ofxBaseJoint::setDefaultProperties()

4
src/ofxBaseJoint.h

@ -27,8 +27,10 @@ public:
protected:
ofColor fillColor;
ofColor strokeColor;
ofColor fillColorSelected;
ofColor strokeColorSelected;
float strokeWidth;
ofVec2f clickDistance;
ofVec2f clickDistance; // How far from the center of the joint the user has clicked?
bool dragging;
private:

16
src/ofxCircleJoint.cpp

@ -17,10 +17,22 @@ void ofxCircleJoint::draw()
ofPushStyle();
ofFill();
ofSetColor(fillColor);
if ( selected ) {
ofSetColor(fillColorSelected);
} else {
ofSetColor(fillColor);
}
ofCircle(position.x, position.y, radius);
ofNoFill();
ofSetColor(strokeColor);
if ( selected ) {
ofSetColor(strokeColorSelected);
} else {
ofSetColor(strokeColor);
}
ofSetLineWidth(strokeWidth);
ofCircle(position.x, position.y, radius);
ofPopStyle();

2
src/ofxSurfaceGui.cpp

@ -57,10 +57,12 @@ void ofxSurfaceGui::mousePressed(int x, int y, int button)
if (mode == PROJECTION_MAPPING) {
for ( int i=0; i<projectionMappingJoints.size(); i++ ) {
projectionMappingJoints[i].selected = false;
projectionMappingJoints[i].mousePressed(x, y, button);
}
} else if (mode == TEXTURE_MAPPING) {
for ( int i=0; i<textureMappingJoints.size(); i++ ) {
textureMappingJoints[i].selected = false;
textureMappingJoints[i].mousePressed(x, y, button);
}
}

Loading…
Cancel
Save