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