//-------------------------------------------------------------- void ofxMuiKnob::onPress() { registerMousePosition(mousePosition); float nv = getNormalizedKnobPosition(); if(getBounds().isBounded()) { if(isRangeEnabled() && isShiftPressed()) { if(isCtrlPressed()) { setRightOrLeftRangeLimit(nv); } else { setClosestRangeLimit(nv); } } else if(isRangeEnabled() && isCtrlPressed()) { normCtrlDragStartMin = getNormalizedRangeMin(); normCtrlDragStartMax = getNormalizedRangeMax(); } else { setNormalizedValue(nv); } } else { //setNormalizedValue(nv); ofVec2f v = screenToHitBox(mousePosition); float d = v.distance(getHitBoxCenter()); float ds = ofNormalize(d,0,getHitBoxWidth()*2.0f) * 10.0f; add(ds*dKnobScaler*dKnobAngle); } }
//-------------------------------------------------------------- void ofxMuiKnob::onDrag() { registerMousePosition(mousePosition); float nv = getNormalizedKnobPosition(); cout << "nv=" << nv << endl; if(getBounds().isBounded()) { if(isRangeEnabled() && isShiftPressed()) { if(isCtrlPressed()) { setRightOrLeftRangeLimit(nv); } else { setClosestRangeLimit(nv); } } else if(isRangeEnabled() && isCtrlPressed()) { normCtrlDragStartMin = getNormalizedRangeMin(); normCtrlDragStartMax = getNormalizedRangeMax(); } else { setNormalizedValue(nv); } /* if(isRangeEnabled() && isShiftPressed()) { setClosestRangeLimit(nv); } else if(isRangeEnabled() && isCtrlPressed()) { // TODO -- fix this // TODO -- quick angle change problem float normDx = fabs(smallestAngleDelta(normCtrlDragStartMin, normCtrlDragStartMax) )/ (2 * PI - boundaryWedgeAngle); setNormalizedRangeMin(ofClamp(normCtrlDragStartMin + normDx,0,1)); setNormalizedRangeMax(ofClamp(normCtrlDragStartMax + normDx,0,1)); } else { //setNormalizedValue(nv); ofVec2f v = screenToHitBox(mousePosition); float d = v.distance(getHitBoxCenter()); float ds = ofNormalize(d,0,getHitBoxWidth()*2.0f) * 10.0f; add(ds*dKnobScaler*getBounds().delta()*dKnobAngle); } */ } else { //setNormalizedValue(nv); //ofVec2f v = screenToHitBox(mousePosition); //float d = v.distance(ofVec2f(getHitBoxWidth()*0.5f,getHitBoxHeight()*0.5f)); float ds = 1;//ofNormalize(d,0,getHitBoxWidth()*2.0f) * 10.0f; add(ds*dKnobScaler*dKnobAngle); cout << getValue() << endl; } }
//-------------------------------------------------------------- void ofxMuiNumberData::checkRange(bool& _boundsChanged, bool& _rangeChanged, int index) { if(!isRangeEnabled()) return; float constrainedRangeMin = 0; float constrainedRangeMax = 0; bool rangeMinChanged = false; bool rangeMaxChanged = false; bool boundsMinChanged = false; bool boundsMaxChanged = false; // make sure bounds are set. cannot have a range without bounds if(!bounds[index].isMinSet()) { bounds[index].setMin(ranges[index].getMin()); boundsMinChanged = true; } if(!bounds[index].isMaxSet()) { bounds[index].setMax(ranges[index].getMax()); boundsMaxChanged = true; } // callback _boundsChanged = boundsMinChanged || boundsMaxChanged; // NOW WE KNOW THAT BOUNDS ARE SET FOR SURE constrainedRangeMin = bounds[index].constrain(ranges[index].getMin()); if(constrainedRangeMin != ranges[index].getMin()) { ranges[index].setMin(constrainedRangeMin); rangeMinChanged = true; } constrainedRangeMax = bounds[index].constrain(ranges[index].getMax()); if(constrainedRangeMax != ranges[index].getMax()) { ranges[index].setMax(constrainedRangeMax); rangeMaxChanged = true; } _rangeChanged = rangeMinChanged || rangeMaxChanged; }