annotate UI code/3Dbox.h @ 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 953db6518738
children
rev   line source
rt300@0 1 //
rt300@0 2 // 3Dbox.h
rt300@0 3 // tweakathlon
rt300@0 4 //
rt300@0 5 // Created by Robert Tubb on 13/02/2014.
rt300@0 6 //
rt300@0 7 //
rt300@0 8
rt300@0 9 #ifndef __tweakathlon___Dbox__
rt300@0 10 #define __tweakathlon___Dbox__
rt300@0 11
rt300@0 12 #include <iostream>
rt300@0 13 #include "UIElement.h"
rt300@0 14 #include "ofMain.h"
rt300@0 15
rt300@0 16
rt300@0 17 class Leap3DBox : public UIElement {
rt300@0 18
rt300@0 19 public:
rt300@0 20 Leap3DBox(float ax,
rt300@0 21 float ay,
rt300@0 22 float awidth,
rt300@0 23 float aheight,
rt300@0 24 float azx,
rt300@0 25 float azy,
rt300@0 26 const UIProps& props);
rt300@0 27 void init(const UIProps& props);
rt300@0 28
rt300@26 29 virtual void setValueAndScale(int which, int val){
rt300@0 30 if(which == 0) xVal = (val - minVal)/(maxVal - minVal);
rt300@0 31 if(which == 1) yVal = (val - minVal)/(maxVal - minVal);
rt300@0 32 if(which == 2) zVal = (val - minVal)/(maxVal - minVal);
rt300@0 33 //cout << zVal << endl;
rt300@0 34 }
rt300@0 35
rt300@26 36 virtual void setHintValue(int which, int val){
rt300@0 37 if(which == 0) hintX = (val - minVal)/(maxVal - minVal);
rt300@0 38 if(which == 1) hintY = (val - minVal)/(maxVal - minVal);
rt300@0 39 if(which == 2) hintZ = (val - minVal)/(maxVal - minVal);
rt300@0 40
rt300@0 41 };
rt300@0 42
rt300@26 43 virtual void draw(){
rt300@0 44 if(hidden)return;
rt300@0 45 if(on){
rt300@0 46 ofSetColor(foregroundHi);
rt300@0 47 }else{
rt300@0 48 ofSetColor(foregroundLo);
rt300@0 49
rt300@0 50 }
rt300@0 51 if(inactive){
rt300@0 52 ofSetColor(fgInactive);
rt300@0 53 }
rt300@0 54
rt300@0 55
rt300@0 56 // draw rear face zy+
rt300@0 57 ofLine(zx+x,zy+y,zx+x,zy+y+height); // left
rt300@0 58 ofLine(zx+x,zy+y,zx+x+width,zy+y); // top
rt300@0 59 ofLine(zx+x+width,zy+y,zx+x+width,zy+y+height); //right
rt300@0 60 ofLine(zx+x+width,zy+y+height,zx+x,zy+y+height); // bottom
rt300@0 61
rt300@0 62 // draw indicators
rt300@0 63 drawIndicator();
rt300@0 64
rt300@0 65 ofSetColor(foregroundHi);
rt300@0 66
rt300@0 67 // draw connectors
rt300@0 68 ofLine(x,y,zx+x,zy+y); // top left
rt300@0 69 ofLine(x+width,y,zx+x+width,zy+y); // top right
rt300@0 70 ofLine(x,y+height,zx+x,zy+y+height); // bot left
rt300@0 71 ofLine(x+width,y+height,zx+x+width,zy+y+height); // bot right
rt300@0 72
rt300@0 73
rt300@0 74 // draw front face
rt300@0 75 ofLine(x,y,x,y+height); // left
rt300@0 76 ofLine(x,y,x+width,y); // top
rt300@0 77 ofLine(x+width,y,x+width,y+height); //right
rt300@0 78 ofLine(x+width,y+height,x,y+height); // bottom
rt300@0 79
rt300@26 80 //drawLabels();
rt300@0 81
rt300@0 82 };
rt300@0 83
rt300@0 84 void drawLabels(){
rt300@0 85 ofColor fg,bg;
rt300@0 86
rt300@0 87 if(on){
rt300@0 88 fg = foregroundHi;
rt300@0 89 bg = backgroundHi;
rt300@0 90 }else{
rt300@0 91 fg = foregroundLo;
rt300@0 92 bg = backgroundLo;
rt300@0 93 }
rt300@0 94 if(inactive){
rt300@0 95 fg = fgInactive;
rt300@0 96 }
rt300@0 97 ofSetColor(fg);
rt300@0 98 verdana16.drawString(labelNameX + " (L/R)", ofGetWidth()/2 - 120, y + height + 50 );
rt300@0 99 verdana16.drawString(labelNameY + " (Up/Dn)", ofGetWidth()/2 - width + 50, y + height/2 );
rt300@0 100 verdana16.drawString(labelNameZ + " Fwd/Bck)", ofGetWidth()/2 + width - 20, y+height);
rt300@0 101
rt300@0 102 // TODO up down etc
rt300@0 103 };
rt300@0 104 void setLabels(string ax, string ay, string az){
rt300@0 105 labelNameX = ax;
rt300@0 106 labelNameY = ay;
rt300@0 107 labelNameZ = az;
rt300@0 108 }
rt300@0 109
rt300@0 110 bool handleMyTouch(int x, int y, touchType ttype, int touchID){
rt300@0 111 return false;
rt300@0 112 };
rt300@0 113 void showHint(bool show){
rt300@0 114 hintShowing = show;
rt300@0 115 }
rt300@0 116 void setHintColor(ofColor c){
rt300@0 117 hintColor = c;
rt300@0 118 };
rt300@0 119
rt300@0 120 protected:
rt300@26 121 virtual void drawIndicator(){
rt300@0 122 ofSetColor(foregroundHi);
rt300@0 123 float px,py;
rt300@0 124 px = x + xVal*width + zx*zVal;
rt300@0 125 py = y + (1-yVal)*height + zy*zVal;
rt300@0 126
rt300@0 127 // line to left wall (no x)
rt300@0 128 ofLine(px , py , x+zx*zVal, py);
rt300@0 129
rt300@0 130 ofEllipse(px,py,thickness,thickness);
rt300@0 131
rt300@0 132
rt300@0 133 // line to bottom wall (no y)
rt300@0 134 ofLine(px , py , px, y+height+zy*zVal);
rt300@0 135 // line to front wall ( no z)
rt300@0 136 ofLine(px , py , x+ width*xVal, y + height*(1-yVal));
rt300@0 137
rt300@0 138 if(hintShowing) drawHintIndicator();
rt300@0 139 };
rt300@26 140 virtual void drawHintIndicator(){
rt300@0 141 ofSetColor(hintColor);
rt300@0 142 float px,py;
rt300@0 143 px = x + hintX*width + zx*hintZ;
rt300@0 144 py = y + (1-hintY)*height + zy*hintZ;
rt300@0 145
rt300@0 146 // line to left wall (no x)
rt300@0 147 ofLine(px , py , x+zx*hintZ, py);
rt300@0 148
rt300@0 149 ofEllipse(px,py,thickness,thickness);
rt300@0 150
rt300@0 151
rt300@0 152 // line to bottom wall (no y)
rt300@0 153 ofLine(px , py , px, y+height+zy*hintZ);
rt300@0 154 // line to front wall ( no z)
rt300@0 155 ofLine(px , py , x+ width*hintX, y + height*(1-hintY));
rt300@0 156
rt300@0 157 };
rt300@0 158
rt300@0 159
rt300@0 160 float xVal,yVal,zVal;
rt300@26 161
rt300@26 162 ofVec3f posVals;
rt300@0 163 float zx,zy; // how much of z and x shows up in diagonal x and y
rt300@0 164
rt300@0 165
rt300@0 166 float minVal;
rt300@0 167 float maxVal;
rt300@0 168
rt300@0 169
rt300@0 170 float hintX;
rt300@0 171 float hintY;
rt300@0 172 float hintZ;
rt300@0 173 bool hintShowing;
rt300@0 174
rt300@0 175 string labelNameX;
rt300@0 176 string labelNameY;
rt300@0 177 string labelNameZ;
rt300@0 178
rt300@0 179 float thickness; // width of border and indicator
rt300@0 180 ofColor foregroundHi;
rt300@0 181 ofColor backgroundHi;
rt300@0 182 ofColor foregroundLo;
rt300@0 183 ofColor backgroundLo;
rt300@0 184 ofColor fgInactive;
rt300@0 185 ofColor hintColor;
rt300@28 186
rt300@28 187
rt300@0 188 };
rt300@0 189 #endif /* defined(__tweakathlon___Dbox__) */