void ofxUIRangeSlider::update() { if(useReference) { valuelow = ofxUIMap(*valuelowRef, min, max, 0.0, 1.0, true); valuehigh = ofxUIMap(*valuehighRef, min, max, 0.0, 1.0, true); } }
void ofxUIRotarySlider::setMaxAndMin(float _max, float _min) { max = _max; min = _min; value = ofxUIMap(value, 0, 1.0, min, max, true); value = ofxUIMap(value, min, max, 0.0, 1.0, true); updateValueRef(); updateLabel(); }
void ofxUIRangeSlider::setMaxAndMin(float _max, float _min) { max = _max; min = _min; valuelow= ofxUIMap(valuelow, 0, 1.0, min, max, true); valuelow = ofxUIMap(valuelow, min, max, 0.0, 1.0, true); valuehigh = ofxUIMap(valuehigh, 0, 1.0, min, max, true); valuehigh = ofxUIMap(valuehigh, min, max, 0.0, 1.0, true); updateValueRef(); updateLabel(); }
void ofxUISlider_<T>::setMaxAndMin(T _max, T _min, bool bKeepValueTheSame) { max = _max; min = _min; if(!bKeepValueTheSame) { value = ofxUIMap(value, 0, 1.0, min, max, bClampValue); value = ofxUIMap(value, min, max, 0.0, 1.0, bClampValue); updateValueRef(); updateLabel(); } }
void ofxUIValuePlotter::drawFill() { if(draw_fill) { ofNoFill(); if(draw_fill_highlight) { ofxUISetColor(color_fill_highlight); } else { ofxUISetColor(color_fill); } ofPushMatrix(); ofTranslate(rect->getX(), rect->getY()+scale, 0); ofSetLineWidth(2.0); ofBeginShape(); for (unsigned int i = 0; i < bufferSize; i++) { ofVertex(inc*(float)i, ofxUIMap(buffer[i], min, max, scale, -scale, true)); } ofEndShape(); ofSetLineWidth(1); ofPopMatrix(); } }
void ofxUIEnvelopeEditor::moveGrabbedCurve(float x, float y) { if(hitCurveNext != NULL && hitCurve != NULL) { float curveBasePoint = (hitCurve->y + hitCurveNext->y)/2.0f; if(hitCurveNext->y >= hitCurve->y) { hitCurve->z = ofxUIMap(y, curveBasePoint, hitCurveNext->y, 0.0f, 1.0f, true); } else if(hitCurveNext->y < hitCurve->y) { hitCurve->z = ofxUIMap(y, curveBasePoint, hitCurve->y, 0.0f, -1.0f, true); } } }
void ofxUISpectrum::drawFill() { if(draw_fill) { ofxUIFill(); if(draw_fill_highlight) { ofxUISetColor(color_fill_highlight); } else { ofxUISetColor(color_fill); } if(buffer != NULL) { ofPushMatrix(); ofTranslate(rect->getX(), rect->getY()+scale, 0); ofBeginShape(); ofVertex(0, 0); for (int i = 0; i < bufferSize; i++) { ofVertex(inc*(float)i, ofxUIMap(buffer[i], min, max, 0, -scale, true)); } ofVertex((bufferSize-1)*inc, 0); ofEndShape(true); ofPopMatrix(); } } }
void ofxUIRotarySlider::update() { if(useReference) { value = ofxUIMap(*valueRef, min, max, 0.0, 1.0, true); } }
void ofxUISlider::init(string _name, float _min, float _max, float *_value, float w, float h, float x, float y) { rect = new ofxUIRectangle(x,y,w,h); name = string(_name); if(w > h) { kind = OFX_UI_WIDGET_SLIDER_H; } else { kind = OFX_UI_WIDGET_SLIDER_V; } paddedRect = new ofxUIRectangle(-padding, -padding, w+padding*2.0, h+padding); paddedRect->setParent(rect); draw_fill = true; value = *_value; //the widget's value if(useReference) { valueRef = _value; } else { valueRef = new float(); *valueRef = value; } max = _max; min = _min; labelPrecision = 2; if(value > max) { value = max; } if(value < min) { value = min; } value = ofxUIMap(value, min, max, 0.0, 1.0, true); if(kind == OFX_UI_WIDGET_SLIDER_H) { label = new ofxUILabel(0,h+padding,string(name+" LABEL"), string(name + ": " + ofxUIToString(max,labelPrecision)), OFX_UI_FONT_SMALL); } else { label = new ofxUILabel(0,h+padding,string(name+" LABEL"), string(name), OFX_UI_FONT_SMALL); } label->setParent(label); label->setRectParent(rect); label->setEmbedded(true); increment = fabs(max - min) / 100.0; bRoundedToNearestInt = false; bClampValue = true; }
void ofxUISlider_<T>::setValue(T _value) { value = ofxUIMap(_value, min, max, 0.0, 1.0, bClampValue); updateValueRef(); updateLabel(); }
void ofxUISlider_<T>::update() { if(useReference) { value = ofxUIMap(*valueRef, min, max, 0.0, 1.0, bClampValue); updateLabel(); } }
T ofxUISlider_<T>::getScaledValue() { T val = ofxUIMap(value, 0.0, 1.0, min, max, bClampValue); if(!bRoundedToNearestInt && bSticky) { val = ceil(val/stickyValue)*stickyValue; } return val; }
void ofxUISlider_<T>::init(string _name, T _min, T _max, T *_value, float w, float h, float x, float y) { initRect(x,y,w,h); name = string(_name); setOrientation(w, h); setKind(); draw_fill = true; value = *_value; //the widget's value if(useReference) { valueRef = _value; } else { valueRef = new T(); *valueRef = value; } max = _max; min = _min; labelPrecision = 2; if(value > max) { value = max; } if(value < min) { value = min; } value = ofxUIMap(value, min, max, 0.0, 1.0, true); valueString = ofxUIToString(getScaledValue(),labelPrecision); if(orientation == OFX_UI_ORIENTATION_HORIZONTAL) { label = new ofxUILabel(0,h+padding,string(name+" LABEL"), string(name + ": " + ofxUIToString(max,labelPrecision)), OFX_UI_FONT_SMALL); } else { label = new ofxUILabel(0,h+padding,string(name+" LABEL"), string(name), OFX_UI_FONT_SMALL); } addEmbeddedWidget(label); label->setVisible(drawLabel); increment = ABS(max - min) / 100.0; bRoundedToNearestInt = false; bClampValue = true; bSticky = false; stickyValue = MAX(10.0*ceil(increment), 1.0); warp = 1.0; setInternalValueFromValue(); }
void ofxUIRotarySlider::input(float x, float y) { hitPoint = ofxUIVec2f(x,y); ofVec2f mappedHitPoint = hitPoint; mappedHitPoint -= ofVec2f(rect->getX()+center.x, rect->getY()+center.y); ofVec2f cVector = center-homePoint; value = ofxUIMap(cVector.angle(mappedHitPoint), -180, 180, 0, 1.0, true); value = MIN(1.0, MAX(0.0, value)); updateValueRef(); updateLabel(); }
void ofxUINumberDialer::calculatePrecisionZone() { currentPrecisionZone = ceil(ofxUIMap(hitPoint.x,rect->getX(),rect->getX()+rect->getWidth(),-1, displaystring.size()-1, true)); if(currentPrecisionZone == 0) { zoneMultiplier = powf(10.0, numOfPrecisionZones-precision-hasPeriod); } else if(currentPrecisionZone <= numOfPrecisionZones-precision) { zoneMultiplier = powf(10.0, numOfPrecisionZones-precision-hasPeriod-currentPrecisionZone); } else { zoneMultiplier = powf(10.0, numOfPrecisionZones-currentPrecisionZone-precision); } }
void ofxUIRotarySlider::drawArcStrip(float percent) { float theta = ofxUIMap(percent, 0, 1, 0, 360.0, true); ofPushMatrix(); ofTranslate(rect->getX(),rect->getY()); ofBeginShape(); { float x = sin(-ofDegToRad(0)); float y = cos(-ofDegToRad(0)); ofVertex(center.x+outerRadius*x,center.y+outerRadius*y); } for(int i = 0; i <= theta; i+=10) { float x = sin(-ofDegToRad(i)); float y = cos(-ofDegToRad(i)); ofVertex(center.x+outerRadius*x,center.y+outerRadius*y); } { float x = sin(-ofDegToRad(theta)); float y = cos(-ofDegToRad(theta)); ofVertex(center.x+outerRadius*x,center.y+outerRadius*y); ofVertex(center.x+innerRadius*x,center.y+innerRadius*y); } for(int i = theta; i >= 0; i-=10) { float x = sin(-ofDegToRad(i)); float y = cos(-ofDegToRad(i)); ofVertex(center.x+innerRadius*x,center.y+innerRadius*y); } { float x = sin(-ofDegToRad(0)); float y = cos(-ofDegToRad(0)); ofVertex(center.x+innerRadius*x,center.y+innerRadius*y); } ofEndShape(); ofPopMatrix(); }
void ofxUICircleSlider::init(float w, float h, float _min, float _max, float *_value, string _name, int _size) { name = string(_name); kind = OFX_UI_WIDGET_CIRCLESLIDER; paddedRect = new ofxUIRectangle(-padding, -padding, w+padding*2.0, h+padding); paddedRect->setParent(rect); draw_fill = true; draw_outline = true; value = *_value; //the widget's value if(useReference) { valueRef = _value; } else { valueRef = new float(); *valueRef = value; } max = _max; min = _min; labelPrecision = 2; if(value > max) { value = max; } if(value < min) { value = min; } value = ofxUIMap(value, min, max, 0.0, 1.0, true); label = new ofxUILabel(0,w+padding,(name+" LABEL"), name, _size); label->setDrawBack(false); label->setParent(label); label->setRectParent(rect); label->setEmbedded(true); increment = .0005; inputDirection = OFX_UI_DIRECTION_SOUTHNORTH; }
void ofxUIRotarySlider::init(float x, float y, float w, float _min, float _max, float *_value, string _name, int _size) { initRect(x,y,w,w); name = string(_name); kind = OFX_UI_WIDGET_ROTARYSLIDER; draw_fill = true; value = *_value; //the widget's value if(useReference) { valueRef = _value; } else { valueRef = new float(); *valueRef = value; } max = _max; min = _min; if(value > max) { value = max; } if(value < min) { value = min; } outerRadius = rect->getWidth()*.5; innerRadius = rect->getWidth()*.25; value = ofxUIMap(value, min, max, 0.0, 1.0, true); valueString = ofxUIToString(getValue(),2); label = new ofxUILabel(0,w+padding,(name+" LABEL"), (name + ": " + valueString), _size); addEmbeddedWidget(label); increment = fabs(max - min) / 10.0; }
void ofxUIRangeSlider::setValueHigh(float _value) { valuehigh = ofxUIMap(_value, min, max, 0.0, 1.0, true); updateValueRef(); updateLabel(); }
float ofxUIRangeSlider::getScaledValueLow() { return ofxUIMap(valuelow, 0.0, 1.0, min, max, true); }
float ofxUIRangeSlider::getScaledValueHigh() { return ofxUIMap(valuehigh, 0.0, 1.0, min, max, true); }
T ofxUISlider_<T>::getScaledValue() { return ofxUIMap(value, 0.0, 1.0, min, max, bClampValue); }
void ofxUIImageSlider::init(float w, float h, float _min, float _max, float *_value, string _pathURL, string _name) { name = string(_name); if(w > h) { kind = OFX_UI_WIDGET_IMAGESLIDER_H; } else { kind = OFX_UI_WIDGET_IMAGESLIDER_V; } paddedRect = new ofxUIRectangle(-padding, -padding, w+padding*2.0, h+padding); paddedRect->setParent(rect); draw_fill = true; value = *_value; //the widget's value if(useReference) { valueRef = _value; } else { valueRef = new float(); *valueRef = value; } max = _max; min = _min; labelPrecision = 2; if(value > max) { value = max; } if(value < min) { value = min; } value = ofxUIMap(value, min, max, 0.0, 1.0, true); if(kind == OFX_UI_WIDGET_IMAGESLIDER_H) { label = new ofxUILabel(0,h+padding,(name+" LABEL"), (name + ": " + ofxUIToString(max,labelPrecision)), OFX_UI_FONT_SMALL); } else { label = new ofxUILabel(0,h+padding,(name+" LABEL"), name, OFX_UI_FONT_SMALL); } label->setParent(label); label->setRectParent(rect); label->setEmbedded(true); increment = fabs(max - min) / 10.0; string coreURL = _pathURL; string extension = ""; string period ("."); size_t found; found=_pathURL.find(period); if (found!=string::npos) { coreURL = _pathURL.substr(0,found); extension = _pathURL.substr(found); } track = new ofImage(); //back track->loadImage(coreURL+"track"+extension); trackleft = new ofImage(); //back trackleft->loadImage(coreURL+"trackleft"+extension); tlaspect = (float)trackleft->getWidth()/(float)trackleft->getHeight(); trackright = new ofImage(); //back trackright->loadImage(coreURL+"trackright"+extension); traspect = (float)trackright->getWidth()/(float)trackright->getHeight(); progress = new ofImage(); //fill progress->loadImage(coreURL+"progress"+extension); progressright = new ofImage(); //fill progressright->loadImage(coreURL+"progressright"+extension); progressleft = new ofImage(); //fill progressleft->loadImage(coreURL+"progressleft"+extension); handle = new ofImage(); //handle handle->loadImage(coreURL+"handle"+extension); handleDown = new ofImage(); //handleOver State handleDown->loadImage(coreURL+"handledown"+extension); handleHalfWidth = handle->getWidth()*.5; handleHalfHeight = handle->getHeight()*.5; if(kind == OFX_UI_WIDGET_IMAGESLIDER_H) { ratio = rect->getHeight() / (float) track->getHeight(); imageRect = new ofxUIRectangle(handleHalfWidth*ratio,0,rect->getWidth()-handle->getWidth()*ratio, rect->getHeight()); } else { ratio = rect->getWidth() / (float) track->getWidth(); imageRect = new ofxUIRectangle(0,handleHalfHeight*ratio,rect->getWidth(), rect->getHeight()-handle->getHeight()*ratio); } imageRect->setParent(rect); }
void ofxUIRangeSlider::init(string _name, float _min, float _max, float *_valuelow, float *_valuehigh, float w, float h, float x, float y, int _size) { initRect(x,y,w,h); name = string(_name); if(w > h) { kind = OFX_UI_WIDGET_RSLIDER_H; } else { kind = OFX_UI_WIDGET_RSLIDER_V; } draw_fill = true; valuelow = *_valuelow; //the widget's value valuehigh = *_valuehigh; //the widget's value if(useReference) { valuelowRef = _valuelow; valuehighRef = _valuehigh; } else { valuelowRef = new float(); valuehighRef = new float(); *valuelowRef = valuelow; *valuehighRef = valuehigh; } max = _max; min = _min; hitHigh = false; hitLow = false; hitCenter = false; if(valuelow > max) { valuelow = max; } if(valuelow < min) { valuelow = min; } if(valuehigh > max) { valuehigh = max; } if(valuehigh < min) { valuehigh = min; } valuelow = ofxUIMap(valuelow, min, max, 0.0, 1.0, true); valuehigh = ofxUIMap(valuehigh, min, max, 0.0, 1.0, true); labelPrecision = 2; valuelowString = ofxUIToString(getScaledValueLow(),labelPrecision); valuehighString = ofxUIToString(getScaledValueHigh(),labelPrecision); if(kind == OFX_UI_WIDGET_RSLIDER_H) { label = new ofxUILabel(0,h+padding,(name+" LABEL"), (name + ": " + valuelowString + " " + valuehighString), _size); } else { label = new ofxUILabel(0,h+padding,(name+" LABEL"), name, _size); } addEmbeddedWidget(label); increment = fabs(max - min) / 10.0; }
void ofxUIRotarySlider::setValue(float _value) { value = ofxUIMap(_value, min, max, 0.0, 1.0, true); updateValueRef(); updateLabel(); }
float ofxUIRotarySlider::getScaledValue() { return ofxUIMap(value, 0.0, 1.0, min, max, true); }