annotate UI code/ButtronXY.mm @ 52:89944ab3e129 tip

fix oF linker errors ios8
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Tue, 03 Feb 2015 13:18:23 +0000
parents a223551fdc1f
children
rev   line source
rt300@0 1 //
rt300@0 2 // ButtronXY.cpp
rt300@0 3 // tweakathlon
rt300@0 4 //
rt300@0 5 // Created by Robert Tubb on 25/06/2013.
rt300@0 6 //
rt300@0 7 //
rt300@0 8
rt300@0 9 #include "ButtronXY.h"
rt300@0 10
rt300@0 11 ButtronXY::ButtronXY(float ax,
rt300@0 12 float ay,
rt300@0 13 float awidth, // width same as height
rt300@0 14 float athickness,
rt300@0 15 float aradius,
rt300@0 16 ofColor aforegroundHi,
rt300@0 17 ofColor abackgroundHi,
rt300@0 18 ofColor aforegroundLo,
rt300@0 19 ofColor abackgroundLo) :
rt300@0 20 Buttron(ax,ay,awidth,awidth,athickness,aradius,aforegroundHi,abackgroundHi,aforegroundLo,abackgroundLo)
rt300@0 21
rt300@0 22 {
rt300@0 23
rt300@0 24 cout << "ButtronXY constructor\n";
rt300@0 25 init();
rt300@0 26 }
rt300@0 27
rt300@0 28 ButtronXY::ButtronXY(float ax,
rt300@0 29 float ay,
rt300@0 30 const UIProps& props) :
rt300@0 31 Buttron(ax,ay,props.XYsize ,props.XYsize,props)
rt300@0 32 {
rt300@0 33 cout << "ButtronXY constructor\n";
rt300@0 34 init();
rt300@0 35 };
rt300@0 36 void ButtronXY::init(){
rt300@0 37 xvalue = 0.6;
rt300@0 38 yvalue = 0.7;
rt300@0 39 minVal = 0.;
rt300@0 40 maxVal = 127.;
rt300@0 41 myType = XYPAD;
rt300@0 42 labelNamex = "xxx";
rt300@0 43 labelNamey = "yyy";
rt300@0 44 }
rt300@0 45 //---------------------------------------------------------------------
rt300@0 46 void ButtronXY::drawIndicator(){
rt300@0 47 if(hintShowing) drawHintIndicator();
rt300@0 48
rt300@0 49 if(on){
rt300@0 50 ofSetColor(foregroundHi);
rt300@0 51 }else{
rt300@0 52 ofSetColor(foregroundLo);
rt300@0 53
rt300@0 54 }
rt300@0 55 if(inactive){
rt300@0 56 ofSetColor(fgInactive);
rt300@0 57 }
rt300@0 58
rt300@0 59 // circle and cross hairs
rt300@0 60 ofFill();
rt300@0 61
rt300@0 62 double left = x + thickness + radius;
rt300@0 63 double top = y + radius + thickness;
rt300@0 64 double activeWidth = width - 2*(radius + thickness);
rt300@0 65 double cx = left + xvalue*activeWidth;
rt300@0 66 double cy = top + (1-yvalue)*activeWidth;
rt300@0 67
rt300@0 68 ofLine(cx,y,cx,y+height);
rt300@0 69 ofLine(x, cy, x+ width, cy);
rt300@0 70
rt300@0 71
rt300@0 72 ofEllipse(cx,cy , 2*radius,2*radius);
rt300@0 73
rt300@0 74
rt300@0 75 }
rt300@0 76 //---------------------------------------------------------------------
rt300@0 77 void ButtronXY::drawHintIndicator(){
rt300@0 78 double left = x + thickness + radius;
rt300@0 79 double top = y + radius + thickness;
rt300@0 80 double activeWidth = width - 2*(radius + thickness);
rt300@0 81
rt300@0 82 // loc = y + hthick + (1 - hintValue)*(height-3*hthick);
rt300@0 83 ofSetColor(255,255,255);
rt300@0 84 float hthick = 1;
rt300@0 85 double locx = left + hintValuex*activeWidth;
rt300@0 86 double locy = top + (1 - hintValuey)*activeWidth;
rt300@0 87 ofEllipse(locx,locy, hthick,hthick);
rt300@0 88
rt300@0 89 // draw target dart board thingy
rt300@0 90 ofNoFill();
rt300@0 91 ofSetLineWidth(2);
rt300@0 92 // yellow red blue
rt300@0 93 ofSetColor(255,255,0,166);
rt300@0 94
rt300@0 95 float rband = activeWidth*TARGET_SCORE_CC_BAND*sqrt(2.0)/127.;
rt300@0 96 ofCircle(locx, locy, rband);
rt300@0 97 ofSetColor(255,0,0,166);
rt300@0 98 ofCircle(locx, locy, rband*2);
rt300@0 99 ofSetColor(45,45,255,166);
rt300@0 100 ofCircle(locx, locy, rband*3);
rt300@0 101 ofSetColor(0,255,0,166);
rt300@0 102 ofCircle(locx, locy, rband*4); // within 20 cc vals?
rt300@0 103 ofFill();
rt300@0 104
rt300@0 105 }
rt300@0 106 //---------------------------------------------------------------------
rt300@0 107
rt300@0 108
rt300@0 109 bool ButtronXY::handleMyTouch(int tx, int ty, touchType ttype, int touchID){
rt300@0 110
rt300@0 111 double lx = tx - x - thickness - radius;
rt300@0 112 double ly = ty - y - thickness - radius;
rt300@0 113
rt300@0 114 double propx,propy;
rt300@0 115 propx = lx/(width - 2 * (thickness + radius));
rt300@0 116 propy = 1 - ly/(height - 2 * (thickness + radius));
rt300@0 117 if(propx > 1.) propx = 1.;
rt300@0 118 if(propx < 0.) propx = 0.;
rt300@0 119 if(propy > 1.) propy = 1.;
rt300@0 120 if(propy < 0.) propy = 0.;
rt300@0 121 //cout << "propx: " << propx << endl;
rt300@0 122 setValue(propx,propy);
rt300@0 123
rt300@0 124 int scaleValx = int((maxVal - minVal)*propx + minVal);
rt300@0 125 int scaleValy = int((maxVal - minVal)*propy + minVal);
rt300@0 126
rt300@0 127 if(callback) callback(myParamIDX,scaleValx);
rt300@0 128 if(callback) callback(myParamIDY,scaleValy);
rt300@0 129 return true;
rt300@0 130 }
rt300@0 131
rt300@0 132 //---------------------------------------------------------------------