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