comparison UI code/Buttron.mm @ 38:fea11c3d1d94

tweaking endlessly
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Thu, 04 Dec 2014 17:03:01 +0000
parents 8d7ae43b2edd
children d810aa9ca03a
comparison
equal deleted inserted replaced
37:52dbd5b4cfa9 38:fea11c3d1d94
14 // 14 //
15 //cout << " buttron default constructur\n"; 15 //cout << " buttron default constructur\n";
16 } 16 }
17 //------------------------------------------------------------------ 17 //------------------------------------------------------------------
18 Buttron::Buttron( 18 Buttron::Buttron(
19 float ax, 19 float ax,
20 float ay, 20 float ay,
21 float awidth, 21 float awidth,
22 float aheight, 22 float aheight,
23 float athickness, 23 float athickness,
24 float aradius, 24 float aradius,
25 ofColor aforegroundHi, 25 ofColor aforegroundHi,
26 ofColor abackgroundHi, 26 ofColor abackgroundHi,
27 ofColor aforegroundLo, 27 ofColor aforegroundLo,
28 ofColor abackgroundLo) : 28 ofColor abackgroundLo) :
29 UIElement(ax,ay,awidth,aheight,abackgroundLo), 29 UIElement(ax,ay,awidth,aheight,abackgroundLo),
30 thickness(athickness), 30 thickness(athickness),
31 radius(aradius), 31 radius(aradius),
32 foregroundHi(aforegroundHi), 32 foregroundHi(aforegroundHi),
33 backgroundHi(abackgroundHi), 33 backgroundHi(abackgroundHi),
34 foregroundLo(aforegroundLo), 34 foregroundLo(aforegroundLo),
35 backgroundLo(abackgroundLo) { 35 backgroundLo(abackgroundLo) {
36 //cout << "phew, buttron big constructur\n"; 36 //cout << "phew, buttron big constructur\n";
37 behaviourMode = MOMENTARY;
37 on = false; 38 on = false;
38 } 39 }
39 //------------------------------------------------------------------ 40 //------------------------------------------------------------------
40 Buttron::Buttron(float ax, 41 Buttron::Buttron(float ax,
41 float ay, 42 float ay,
42 const UIProps& props): 43 const UIProps& props):
43 UIElement(ax,ay,props.buttonWidth,props.buttonHeight, props) 44 UIElement(ax,ay,props.buttonWidth,props.buttonHeight, props)
44 45
45 { 46 {
46 47
47 thickness = props.borderThickness; 48 thickness = props.borderThickness;
48 radius = props.cornerRadius; 49 radius = props.cornerRadius;
49 foregroundHi = props.buttonHi; 50 foregroundHi = props.buttonHi;
50 backgroundHi = props.generalBackground; 51 backgroundHi = props.backgroundHi;
51 foregroundLo = props.buttonLo; 52 foregroundLo = props.buttonLo;
52 backgroundLo = props.generalBackground; 53 backgroundLo = props.generalBackground;
53 54 behaviourMode = MOMENTARY;
54 on = false; 55 on = false;
55 } 56 }
56 //------------------------------------------------------------------ 57 //------------------------------------------------------------------
57 Buttron::Buttron(float ax, 58 Buttron::Buttron(float ax,
58 float ay, 59 float ay,
59 float awidth, 60 float awidth,
60 float aheight, 61 float aheight,
61 const UIProps& props): 62 const UIProps& props):
62 UIElement(ax,ay,awidth,aheight, props) 63 UIElement(ax,ay,awidth,aheight, props)
63 64
64 { 65 {
65 //cout << "slider (meh) recommended constructor\n"; 66 //cout << "slider (meh) recommended constructor\n";
66 67
67 thickness = props.borderThickness; 68 thickness = props.borderThickness;
68 radius = props.cornerRadius; 69 radius = props.cornerRadius;
69 foregroundHi = props.buttonHi; 70 foregroundHi = props.buttonHi;
70 backgroundHi = props.generalBackground; 71 backgroundHi = props.backgroundHi;
71 foregroundLo = props.buttonLo; 72 foregroundLo = props.buttonLo;
72 backgroundLo = props.generalBackground; 73 backgroundLo = props.generalBackground;
73 fgInactive = props.inactiveGreyedOut; 74 fgInactive = props.inactiveGreyedOut;
74 75
75 on = false; 76 on = false;
77 behaviourMode = MOMENTARY;
76 } 78 }
77 //------------------------------------------------------------------ 79 //------------------------------------------------------------------
78 void Buttron::draw(){ 80 void Buttron::draw(){
79 if(hidden) return; 81 if(hidden) return;
80 82
136 138
137 // draw corner foreground circles 139 // draw corner foreground circles
138 140
139 //tl 141 //tl
140 ofCircle(x+cornerSize, y+cornerSize, cornerSize); 142 ofCircle(x+cornerSize, y+cornerSize, cornerSize);
141 143
142 144
143 //tr 145 //tr
144 146
145 ofCircle(x+width-cornerSize, y+cornerSize, cornerSize); 147 ofCircle(x+width-cornerSize, y+cornerSize, cornerSize);
146 148
147 //bl 149 //bl
148 150
149 ofCircle(x+cornerSize, y+height-cornerSize, cornerSize); 151 ofCircle(x+cornerSize, y+height-cornerSize, cornerSize);
150 152
151 //br 153 //br
152 154
153 ofCircle(x+width-cornerSize, y+height-cornerSize, cornerSize); 155 ofCircle(x+width-cornerSize, y+height-cornerSize, cornerSize);
154 156
155 // draw corner inner bg circles 157 // draw corner inner bg circles
156 ofSetColor(bg); 158 ofSetColor(bg);
157 ofCircle(x+cornerSize, y+cornerSize, radius); 159 ofCircle(x+cornerSize, y+cornerSize, radius);
158 160
159 ofCircle(x+width-cornerSize, y+cornerSize, radius); 161 ofCircle(x+width-cornerSize, y+cornerSize, radius);
160 162
161 ofCircle(x+cornerSize, y+height-cornerSize, radius); 163 ofCircle(x+cornerSize, y+height-cornerSize, radius);
162 164
163 ofCircle(x+width-cornerSize, y+height-cornerSize, radius); 165 ofCircle(x+width-cornerSize, y+height-cornerSize, radius);
164 166
165 // fill in background 167 // fill in background
166 ofRect(x+cornerSize,y+thickness,width-2*cornerSize,height-2*thickness); 168 ofRect(x+cornerSize,y+thickness,width-2*cornerSize,height-2*thickness);
167 ofRect(x+thickness, y+cornerSize, radius, height-2*cornerSize); 169 ofRect(x+thickness, y+cornerSize, radius, height-2*cornerSize);
171 } 173 }
172 //------------------------------------------------------------------------------ 174 //------------------------------------------------------------------------------
173 bool Buttron::handleMyTouch(int tx, int ty, touchType ttype, int touchID){ 175 bool Buttron::handleMyTouch(int tx, int ty, touchType ttype, int touchID){
174 176
175 //cout << "buttron handling touch\n"; 177 //cout << "buttron handling touch\n";
176 if(ttype == TOUCH_DOWN){ 178 if(behaviourMode == MOMENTARY){
177 on = true; 179 if(ttype == TOUCH_DOWN){
178 if(callback) callback(myParamID,1); 180 on = true;
179 181 if(callback) callback(myParamID,1);
180 }else if(ttype == TOUCH_MOVED){ 182
181 183 }else if(ttype == TOUCH_MOVED){
182 }else if(ttype == TOUCH_UP){ 184
183 on = false; 185 }else if(ttype == TOUCH_UP){
186 on = false;
187 }
184 } 188 }
189 if(behaviourMode == TOGGLE)
190 if(ttype == TOUCH_DOWN){
191 on = !on;
192 if(callback) callback(myParamID,1);
193 }
185 return true; // necessary? 194 return true; // necessary?
186 195
187 } 196 }
188 197
189 //------------------------------------------------------------------------------ 198 //------------------------------------------------------------------------------