rt300@0: // rt300@0: // ButtronXY.cpp rt300@0: // tweakathlon rt300@0: // rt300@0: // Created by Robert Tubb on 25/06/2013. rt300@0: // rt300@0: // rt300@0: rt300@0: #include "ButtronXY.h" rt300@0: rt300@0: ButtronXY::ButtronXY(float ax, rt300@0: float ay, rt300@0: float awidth, // width same as height 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: Buttron(ax,ay,awidth,awidth,athickness,aradius,aforegroundHi,abackgroundHi,aforegroundLo,abackgroundLo) rt300@0: rt300@0: { rt300@0: rt300@0: cout << "ButtronXY constructor\n"; rt300@0: init(); rt300@0: } rt300@0: rt300@0: ButtronXY::ButtronXY(float ax, rt300@0: float ay, rt300@0: const UIProps& props) : rt300@0: Buttron(ax,ay,props.XYsize ,props.XYsize,props) rt300@0: { rt300@0: cout << "ButtronXY constructor\n"; rt300@0: init(); rt300@0: }; rt300@0: void ButtronXY::init(){ rt300@0: xvalue = 0.6; rt300@0: yvalue = 0.7; rt300@0: minVal = 0.; rt300@0: maxVal = 127.; rt300@0: myType = XYPAD; rt300@0: labelNamex = "xxx"; rt300@0: labelNamey = "yyy"; rt300@0: } rt300@0: //--------------------------------------------------------------------- rt300@0: void ButtronXY::drawIndicator(){ rt300@0: if(hintShowing) drawHintIndicator(); rt300@0: 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: rt300@0: // circle and cross hairs rt300@0: ofFill(); rt300@0: rt300@0: double left = x + thickness + radius; rt300@0: double top = y + radius + thickness; rt300@0: double activeWidth = width - 2*(radius + thickness); rt300@0: double cx = left + xvalue*activeWidth; rt300@0: double cy = top + (1-yvalue)*activeWidth; rt300@0: rt300@0: ofLine(cx,y,cx,y+height); rt300@0: ofLine(x, cy, x+ width, cy); rt300@0: rt300@0: rt300@0: ofEllipse(cx,cy , 2*radius,2*radius); rt300@0: rt300@0: rt300@0: } rt300@0: //--------------------------------------------------------------------- rt300@0: void ButtronXY::drawHintIndicator(){ rt300@0: double left = x + thickness + radius; rt300@0: double top = y + radius + thickness; rt300@0: double activeWidth = width - 2*(radius + thickness); rt300@0: rt300@0: // loc = y + hthick + (1 - hintValue)*(height-3*hthick); rt300@0: ofSetColor(255,255,255); rt300@0: float hthick = 1; rt300@0: double locx = left + hintValuex*activeWidth; rt300@0: double locy = top + (1 - hintValuey)*activeWidth; rt300@0: ofEllipse(locx,locy, hthick,hthick); rt300@0: rt300@0: // draw target dart board thingy rt300@0: ofNoFill(); rt300@0: ofSetLineWidth(2); rt300@0: // yellow red blue rt300@0: ofSetColor(255,255,0,166); rt300@0: rt300@0: float rband = activeWidth*TARGET_SCORE_CC_BAND*sqrt(2.0)/127.; rt300@0: ofCircle(locx, locy, rband); rt300@0: ofSetColor(255,0,0,166); rt300@0: ofCircle(locx, locy, rband*2); rt300@0: ofSetColor(45,45,255,166); rt300@0: ofCircle(locx, locy, rband*3); rt300@0: ofSetColor(0,255,0,166); rt300@0: ofCircle(locx, locy, rband*4); // within 20 cc vals? rt300@0: ofFill(); rt300@0: rt300@0: } rt300@0: //--------------------------------------------------------------------- rt300@0: rt300@0: rt300@0: bool ButtronXY::handleMyTouch(int tx, int ty, touchType ttype, int touchID){ rt300@0: rt300@0: double lx = tx - x - thickness - radius; rt300@0: double ly = ty - y - thickness - radius; rt300@0: rt300@0: double propx,propy; rt300@0: propx = lx/(width - 2 * (thickness + radius)); rt300@0: propy = 1 - ly/(height - 2 * (thickness + radius)); rt300@0: if(propx > 1.) propx = 1.; rt300@0: if(propx < 0.) propx = 0.; rt300@0: if(propy > 1.) propy = 1.; rt300@0: if(propy < 0.) propy = 0.; rt300@0: //cout << "propx: " << propx << endl; rt300@0: setValue(propx,propy); rt300@0: rt300@0: int scaleValx = int((maxVal - minVal)*propx + minVal); rt300@0: int scaleValy = int((maxVal - minVal)*propy + minVal); rt300@0: rt300@0: if(callback) callback(myParamIDX,scaleValx); rt300@0: if(callback) callback(myParamIDY,scaleValy); rt300@0: return true; rt300@0: } rt300@0: rt300@0: //---------------------------------------------------------------------