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

4
src/ofxBaseJoint.h

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

16
src/ofxCircleJoint.cpp

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

2
src/ofxSurfaceGui.cpp

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

Loading…
Cancel
Save