rt300@0: // rt300@0: // ButtronSlider.cpp rt300@0: // emptyExample rt300@0: // rt300@0: // Created by Robert Tubb on 22/05/2013. rt300@0: // rt300@0: // rt300@0: rt300@0: #include "ButtronSlider.h" rt300@0: rt300@0: rt300@0: ButtronSlider::ButtronSlider(float ax, rt300@0: float ay, rt300@0: float awidth, rt300@0: float aheight, rt300@0: float athickness, rt300@0: float aradius, rt300@0: ofColor aforegroundHi, rt300@0: ofColor abackgroundHi, rt300@0: ofColor aforegroundLo, rt300@0: ofColor abackgroundLo, rt300@0: SliderType type) : rt300@0: Buttron(ax,ay,awidth,aheight,athickness,aradius,aforegroundHi,abackgroundHi,aforegroundLo,abackgroundLo), rt300@0: sliderType(type) rt300@0: rt300@0: { rt300@0: rt300@0: init(); rt300@0: } rt300@0: ButtronSlider::ButtronSlider(float ax, rt300@0: float ay, rt300@0: float awidth, rt300@0: float aheight, rt300@0: SliderType type, rt300@0: const UIProps& props) : rt300@0: Buttron(ax,ay,awidth,aheight,props), rt300@0: sliderType(type) rt300@0: rt300@0: { rt300@0: init(); rt300@0: } rt300@0: void ButtronSlider::init(){ rt300@0: myType = SLIDER; rt300@0: minVal = 0.; rt300@0: maxVal = 127.; rt300@0: value = 0.6; rt300@0: hintShowing = false; rt300@0: } rt300@0: // rt300@0: //--------------------------------------------------------------------- rt300@0: void ButtronSlider::drawIndicator(double proportion){ rt300@0: if(on){ rt300@0: ofSetColor(foregroundHi); rt300@0: }else{ rt300@0: ofSetColor(foregroundLo); rt300@0: rt300@0: } rt300@0: if(inactive){ rt300@0: ofSetColor(fgInactive); rt300@0: } rt300@0: if(sliderType == FILL){ rt300@0: rt300@0: double maxH = height - 2 * thickness; // rt300@0: double w = width - 2 * thickness;// rt300@0: double barheight = value*maxH; rt300@0: double top = y + height - thickness - barheight; rt300@0: ofRect(x+thickness, top, w, barheight); rt300@0: rt300@0: }else if(sliderType == LINE){ rt300@0: double loc = y + thickness + (1 -value)*(height-3*thickness); rt300@0: ofRect(x+thickness,loc, width-2*thickness,thickness); rt300@0: } rt300@0: rt300@0: rt300@0: } rt300@0: rt300@0: void ButtronSlider::drawHintIndicator(){ rt300@0: rt300@0: ofSetColor(hintColor); rt300@0: float hthick = 1; rt300@0: double loc = y + hthick + (1 - hintValue)*(height-3*hthick); rt300@0: ofRect(x+thickness,loc, width-2*thickness,hthick); rt300@0: rt300@0: } rt300@0: rt300@0: //--------------------------------------------------------------------- rt300@0: rt300@0: bool ButtronSlider::handleMyTouch(int tx, int ty, touchType ttype, int touchID){ rt300@0: rt300@0: double ly = ty - y - thickness - radius; rt300@0: rt300@0: double prop; rt300@0: rt300@0: prop = 1 - ly/(height - 2 * (thickness + radius)); rt300@0: rt300@0: if(prop > 1.) prop = 1.; rt300@0: if(prop < 0.) prop = 0.; rt300@0: rt300@0: setValue(prop); rt300@0: int scaleVal = int((maxVal - minVal)*prop + minVal); rt300@0: rt300@0: vector pass; rt300@0: if(callback) callback(myParamID,scaleVal); rt300@0: rt300@0: return true; rt300@0: }