rt300@0
|
1 //
|
rt300@0
|
2 // buttron.cpp
|
rt300@0
|
3 // emptyExample
|
rt300@0
|
4 //
|
rt300@0
|
5 // Created by Robert Tubb on 30/04/2013.
|
rt300@0
|
6 //
|
rt300@0
|
7 //
|
rt300@0
|
8
|
rt300@0
|
9 #include "buttron.h"
|
rt300@0
|
10
|
rt300@0
|
11 //------------------------------------------------------------------
|
rt300@0
|
12
|
rt300@0
|
13 Buttron::Buttron(){
|
rt300@0
|
14 //
|
rt300@0
|
15 //cout << " buttron default constructur\n";
|
rt300@0
|
16 }
|
rt300@0
|
17 //------------------------------------------------------------------
|
rt300@0
|
18 Buttron::Buttron(
|
rt300@38
|
19 float ax,
|
rt300@38
|
20 float ay,
|
rt300@38
|
21 float awidth,
|
rt300@38
|
22 float aheight,
|
rt300@38
|
23 float athickness,
|
rt300@38
|
24 float aradius,
|
rt300@38
|
25 ofColor aforegroundHi,
|
rt300@38
|
26 ofColor abackgroundHi,
|
rt300@38
|
27 ofColor aforegroundLo,
|
rt300@38
|
28 ofColor abackgroundLo) :
|
rt300@38
|
29 UIElement(ax,ay,awidth,aheight,abackgroundLo),
|
rt300@38
|
30 thickness(athickness),
|
rt300@38
|
31 radius(aradius),
|
rt300@38
|
32 foregroundHi(aforegroundHi),
|
rt300@38
|
33 backgroundHi(abackgroundHi),
|
rt300@38
|
34 foregroundLo(aforegroundLo),
|
rt300@38
|
35 backgroundLo(abackgroundLo) {
|
rt300@0
|
36 //cout << "phew, buttron big constructur\n";
|
rt300@38
|
37 behaviourMode = MOMENTARY;
|
rt300@0
|
38 on = false;
|
rt300@0
|
39 }
|
rt300@0
|
40 //------------------------------------------------------------------
|
rt300@0
|
41 Buttron::Buttron(float ax,
|
rt300@0
|
42 float ay,
|
rt300@0
|
43 const UIProps& props):
|
rt300@38
|
44 UIElement(ax,ay,props.buttonWidth,props.buttonHeight, props)
|
rt300@0
|
45
|
rt300@0
|
46 {
|
rt300@38
|
47
|
rt300@0
|
48 thickness = props.borderThickness;
|
rt300@0
|
49 radius = props.cornerRadius;
|
rt300@0
|
50 foregroundHi = props.buttonHi;
|
rt300@38
|
51 backgroundHi = props.backgroundHi;
|
rt300@0
|
52 foregroundLo = props.buttonLo;
|
rt300@0
|
53 backgroundLo = props.generalBackground;
|
rt300@38
|
54 behaviourMode = MOMENTARY;
|
rt300@0
|
55 on = false;
|
rt300@44
|
56 bgImage = NULL;
|
rt300@0
|
57 }
|
rt300@0
|
58 //------------------------------------------------------------------
|
rt300@0
|
59 Buttron::Buttron(float ax,
|
rt300@38
|
60 float ay,
|
rt300@38
|
61 float awidth,
|
rt300@38
|
62 float aheight,
|
rt300@38
|
63 const UIProps& props):
|
rt300@38
|
64 UIElement(ax,ay,awidth,aheight, props)
|
rt300@0
|
65
|
rt300@0
|
66 {
|
rt300@0
|
67 //cout << "slider (meh) recommended constructor\n";
|
rt300@0
|
68
|
rt300@0
|
69 thickness = props.borderThickness;
|
rt300@0
|
70 radius = props.cornerRadius;
|
rt300@0
|
71 foregroundHi = props.buttonHi;
|
rt300@38
|
72 backgroundHi = props.backgroundHi;
|
rt300@0
|
73 foregroundLo = props.buttonLo;
|
rt300@0
|
74 backgroundLo = props.generalBackground;
|
rt300@0
|
75 fgInactive = props.inactiveGreyedOut;
|
rt300@0
|
76
|
rt300@0
|
77 on = false;
|
rt300@38
|
78 behaviourMode = MOMENTARY;
|
rt300@0
|
79 }
|
rt300@0
|
80 //------------------------------------------------------------------
|
rt300@0
|
81 void Buttron::draw(){
|
rt300@0
|
82 if(hidden) return;
|
rt300@26
|
83
|
rt300@26
|
84 ofDisableDepthTest();
|
rt300@0
|
85 //cout << "drawing button" << endl;
|
rt300@0
|
86 ofFill();
|
rt300@0
|
87 UIElement::draw(); // should do background
|
rt300@44
|
88 //drawBackground();
|
rt300@0
|
89 drawOutline();
|
rt300@0
|
90 drawTextLabel();
|
rt300@26
|
91
|
rt300@26
|
92 ofEnableDepthTest();
|
rt300@0
|
93 }
|
rt300@0
|
94 //------------------------------------------------------------------
|
rt300@0
|
95 void Buttron::drawTextLabel(){
|
rt300@0
|
96 ofColor fg,bg;
|
rt300@0
|
97
|
rt300@0
|
98 if(on){
|
rt300@0
|
99 fg = foregroundHi;
|
rt300@0
|
100 bg = backgroundHi;
|
rt300@0
|
101 }else{
|
rt300@0
|
102 fg = foregroundLo;
|
rt300@0
|
103 bg = backgroundLo;
|
rt300@0
|
104 }
|
rt300@0
|
105 if(inactive){
|
rt300@0
|
106 fg = fgInactive;
|
rt300@0
|
107 }
|
rt300@0
|
108 ofSetColor(fg);
|
rt300@0
|
109 verdana16.drawString(labelName, x + thickness*2, y + 35);
|
rt300@0
|
110
|
rt300@26
|
111
|
rt300@0
|
112 }
|
rt300@0
|
113 //------------------------------------------------------------------
|
rt300@0
|
114 void Buttron::drawOutline(){
|
rt300@0
|
115
|
rt300@0
|
116 // draw bars
|
rt300@0
|
117 ofColor fg,bg;
|
rt300@0
|
118
|
rt300@0
|
119 if(on){
|
rt300@0
|
120 fg = foregroundHi;
|
rt300@0
|
121 bg = backgroundHi;
|
rt300@0
|
122 }else{
|
rt300@0
|
123 fg = foregroundLo;
|
rt300@0
|
124 bg = backgroundLo;
|
rt300@0
|
125 }
|
rt300@22
|
126 if(inactive){
|
rt300@22
|
127 ofSetColor(fgInactive);
|
rt300@22
|
128 }
|
rt300@0
|
129 ofSetColor(fg);
|
rt300@0
|
130
|
rt300@0
|
131 float cornerSize = thickness + radius;
|
rt300@0
|
132 // left
|
rt300@0
|
133 ofRect(x, y+cornerSize, thickness, height - 2*(cornerSize));
|
rt300@0
|
134 //right
|
rt300@0
|
135 ofRect(x + width - thickness, y+cornerSize, thickness, height - 2*(cornerSize));
|
rt300@0
|
136 // top
|
rt300@0
|
137 ofRect(x+cornerSize, y, width-2*(cornerSize), thickness);
|
rt300@0
|
138 // bottom
|
rt300@0
|
139 ofRect(x+cornerSize, y+height-thickness, width-2*(cornerSize), thickness);
|
rt300@0
|
140
|
rt300@0
|
141 // draw corner foreground circles
|
rt300@0
|
142
|
rt300@0
|
143 //tl
|
rt300@0
|
144 ofCircle(x+cornerSize, y+cornerSize, cornerSize);
|
rt300@38
|
145
|
rt300@0
|
146
|
rt300@0
|
147 //tr
|
rt300@38
|
148
|
rt300@0
|
149 ofCircle(x+width-cornerSize, y+cornerSize, cornerSize);
|
rt300@38
|
150
|
rt300@0
|
151 //bl
|
rt300@38
|
152
|
rt300@0
|
153 ofCircle(x+cornerSize, y+height-cornerSize, cornerSize);
|
rt300@38
|
154
|
rt300@0
|
155 //br
|
rt300@38
|
156
|
rt300@0
|
157 ofCircle(x+width-cornerSize, y+height-cornerSize, cornerSize);
|
rt300@38
|
158
|
rt300@0
|
159 // draw corner inner bg circles
|
rt300@0
|
160 ofSetColor(bg);
|
rt300@0
|
161 ofCircle(x+cornerSize, y+cornerSize, radius);
|
rt300@38
|
162
|
rt300@0
|
163 ofCircle(x+width-cornerSize, y+cornerSize, radius);
|
rt300@38
|
164
|
rt300@0
|
165 ofCircle(x+cornerSize, y+height-cornerSize, radius);
|
rt300@38
|
166
|
rt300@0
|
167 ofCircle(x+width-cornerSize, y+height-cornerSize, radius);
|
rt300@0
|
168
|
rt300@0
|
169 // fill in background
|
rt300@44
|
170
|
rt300@0
|
171 ofRect(x+cornerSize,y+thickness,width-2*cornerSize,height-2*thickness);
|
rt300@0
|
172 ofRect(x+thickness, y+cornerSize, radius, height-2*cornerSize);
|
rt300@0
|
173 ofRect(x+width-cornerSize, y+cornerSize, radius, height-2*cornerSize);
|
rt300@26
|
174
|
rt300@26
|
175
|
rt300@0
|
176 }
|
rt300@0
|
177 //------------------------------------------------------------------------------
|
rt300@0
|
178 bool Buttron::handleMyTouch(int tx, int ty, touchType ttype, int touchID){
|
rt300@0
|
179
|
rt300@0
|
180 //cout << "buttron handling touch\n";
|
rt300@38
|
181 if(behaviourMode == MOMENTARY){
|
rt300@38
|
182 if(ttype == TOUCH_DOWN){
|
rt300@38
|
183 on = true;
|
rt300@38
|
184 if(callback) callback(myParamID,1);
|
rt300@38
|
185
|
rt300@38
|
186 }else if(ttype == TOUCH_MOVED){
|
rt300@38
|
187
|
rt300@38
|
188 }else if(ttype == TOUCH_UP){
|
rt300@38
|
189 on = false;
|
rt300@38
|
190 }
|
rt300@0
|
191 }
|
rt300@38
|
192 if(behaviourMode == TOGGLE)
|
rt300@38
|
193 if(ttype == TOUCH_DOWN){
|
rt300@38
|
194 on = !on;
|
rt300@38
|
195 if(callback) callback(myParamID,1);
|
rt300@38
|
196 }
|
rt300@0
|
197 return true; // necessary?
|
rt300@0
|
198
|
rt300@0
|
199 }
|
rt300@0
|
200
|
rt300@0
|
201 //------------------------------------------------------------------------------
|