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@0
|
80 //cout << "drawing button" << endl;
|
rt300@0
|
81 ofFill();
|
rt300@0
|
82 UIElement::draw(); // should do background
|
rt300@0
|
83 drawOutline();
|
rt300@0
|
84 drawTextLabel();
|
rt300@0
|
85 }
|
rt300@0
|
86 //------------------------------------------------------------------
|
rt300@0
|
87 void Buttron::drawTextLabel(){
|
rt300@0
|
88 ofColor fg,bg;
|
rt300@0
|
89
|
rt300@0
|
90 if(on){
|
rt300@0
|
91 fg = foregroundHi;
|
rt300@0
|
92 bg = backgroundHi;
|
rt300@0
|
93 }else{
|
rt300@0
|
94 fg = foregroundLo;
|
rt300@0
|
95 bg = backgroundLo;
|
rt300@0
|
96 }
|
rt300@0
|
97 if(inactive){
|
rt300@0
|
98 fg = fgInactive;
|
rt300@0
|
99 }
|
rt300@0
|
100 ofSetColor(fg);
|
rt300@0
|
101 verdana16.drawString(labelName, x + thickness*2, y + 35);
|
rt300@0
|
102
|
rt300@0
|
103 }
|
rt300@0
|
104 //------------------------------------------------------------------
|
rt300@0
|
105 void Buttron::drawOutline(){
|
rt300@0
|
106
|
rt300@0
|
107 // draw bars
|
rt300@0
|
108 ofColor fg,bg;
|
rt300@0
|
109
|
rt300@0
|
110 if(on){
|
rt300@0
|
111 fg = foregroundHi;
|
rt300@0
|
112 bg = backgroundHi;
|
rt300@0
|
113 }else{
|
rt300@0
|
114 fg = foregroundLo;
|
rt300@0
|
115 bg = backgroundLo;
|
rt300@0
|
116 }
|
rt300@0
|
117 ofSetColor(fg);
|
rt300@0
|
118
|
rt300@0
|
119 float cornerSize = thickness + radius;
|
rt300@0
|
120 // left
|
rt300@0
|
121 ofRect(x, y+cornerSize, thickness, height - 2*(cornerSize));
|
rt300@0
|
122 //right
|
rt300@0
|
123 ofRect(x + width - thickness, y+cornerSize, thickness, height - 2*(cornerSize));
|
rt300@0
|
124 // top
|
rt300@0
|
125 ofRect(x+cornerSize, y, width-2*(cornerSize), thickness);
|
rt300@0
|
126 // bottom
|
rt300@0
|
127 ofRect(x+cornerSize, y+height-thickness, width-2*(cornerSize), thickness);
|
rt300@0
|
128
|
rt300@0
|
129 // draw corner foreground circles
|
rt300@0
|
130
|
rt300@0
|
131 //tl
|
rt300@0
|
132 ofCircle(x+cornerSize, y+cornerSize, cornerSize);
|
rt300@0
|
133
|
rt300@0
|
134
|
rt300@0
|
135 //tr
|
rt300@0
|
136
|
rt300@0
|
137 ofCircle(x+width-cornerSize, y+cornerSize, cornerSize);
|
rt300@0
|
138
|
rt300@0
|
139 //bl
|
rt300@0
|
140
|
rt300@0
|
141 ofCircle(x+cornerSize, y+height-cornerSize, cornerSize);
|
rt300@0
|
142
|
rt300@0
|
143 //br
|
rt300@0
|
144
|
rt300@0
|
145 ofCircle(x+width-cornerSize, y+height-cornerSize, cornerSize);
|
rt300@0
|
146
|
rt300@0
|
147 // draw corner inner bg circles
|
rt300@0
|
148 ofSetColor(bg);
|
rt300@0
|
149 ofCircle(x+cornerSize, y+cornerSize, radius);
|
rt300@0
|
150
|
rt300@0
|
151 ofCircle(x+width-cornerSize, y+cornerSize, radius);
|
rt300@0
|
152
|
rt300@0
|
153 ofCircle(x+cornerSize, y+height-cornerSize, radius);
|
rt300@0
|
154
|
rt300@0
|
155 ofCircle(x+width-cornerSize, y+height-cornerSize, radius);
|
rt300@0
|
156
|
rt300@0
|
157 // fill in background
|
rt300@0
|
158 ofRect(x+cornerSize,y+thickness,width-2*cornerSize,height-2*thickness);
|
rt300@0
|
159 ofRect(x+thickness, y+cornerSize, radius, height-2*cornerSize);
|
rt300@0
|
160 ofRect(x+width-cornerSize, y+cornerSize, radius, height-2*cornerSize);
|
rt300@0
|
161 }
|
rt300@0
|
162 //------------------------------------------------------------------------------
|
rt300@0
|
163 bool Buttron::handleMyTouch(int tx, int ty, touchType ttype, int touchID){
|
rt300@0
|
164
|
rt300@0
|
165 //cout << "buttron handling touch\n";
|
rt300@0
|
166 if(ttype == TOUCH_DOWN){
|
rt300@0
|
167 on = true;
|
rt300@0
|
168 if(callback) callback(myParamID,1);
|
rt300@0
|
169
|
rt300@0
|
170 }else if(ttype == TOUCH_MOVED){
|
rt300@0
|
171
|
rt300@0
|
172 }else if(ttype == TOUCH_UP){
|
rt300@0
|
173 on = false;
|
rt300@0
|
174 }
|
rt300@0
|
175 return true; // necessary?
|
rt300@0
|
176
|
rt300@0
|
177 }
|
rt300@0
|
178
|
rt300@0
|
179 //------------------------------------------------------------------------------
|