-
Notifications
You must be signed in to change notification settings - Fork 1
/
Checkbox.pde
175 lines (156 loc) · 3.77 KB
/
Checkbox.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
color checkboxColor = 255;
class Checkbox extends View {
boolean value;
color ckbColor = -1;
PImage icon;
public String title;
color iconColor = -1;
PImage unchecked;
PImage checked;
int sized = 0;
char c = '0';
Checkbox(float x_, float y_, float w_, float h_,String text_, PImage image_, color iconColor_)
{
super(x_, y_, w_, h_);
value = false;
icon = image_;
title = text_;
iconColor = iconColor_;
}
Checkbox(float x_, float y_, float w_, float h_, String text_,color color_)
{
super(x_, y_, w_, h_);
value = false;
ckbColor = color_;
title = text_;
}
Checkbox(float x_, float y_, float w_, float h_, String text_)
{
super(x_, y_, w_, h_);
value = false;
title = text_;
}
Checkbox(float x_, float y_,int w_, int h_,PImage checked, PImage unchecked, String text_,boolean value){
super(x_, y_,w_,h_);
title = text_;
this.value = value;
this.checked = checked;
this.unchecked = unchecked;
}
Checkbox(float x_, float y_, int w_, int h_, String text_, boolean value, char c ){
super(x_, y_,w_,h_);
title = text_;
this.value = value;
this.c = c;
}
void drawContent()
{
// System.out.println(y);
// strokeWeight(1);
if(checked != null && unchecked != null){
//System.out.println("Drawing Checkbox");
// textFont(fbold);
fill(255);
text(title, w+70, 20);
// textFont(f2);
if(value){
//checked.resize(0,sized);
image(checked,0,0,w,h);
}else{
//unchecked.resize(0,sized);
image(unchecked,0,0,w,h);
}
}else{
if(c == '1'){
if(!value){
strokeWeight(2);
stroke(255);
fill(menuColor1);
ellipse(0,2,20,20);
fill(255);
text(title, w+50, 10);
}else{
strokeWeight(1);
stroke(255);
fill(255);
ellipse(0,2,20,20);
text(title, w+50, 10);
}
}
else{
strokeWeight(1);
if (value){
stroke((ckbColor== -1)?checkboxColor:ckbColor);
noFill();
rect(0, 0, w, h);
fill((ckbColor== -1)?checkboxColor:ckbColor);
rect(2, 2, w-4, h-4);
}
else{
stroke((ckbColor== -1)?checkboxColor:ckbColor);
noFill();
rect(0, 0, w, h);
}
fill(textColor2);
// textFont(font,normalFontSize);
textAlign(LEFT,TOP);
if (icon != null){
text(title, w + w + 10, 0);
if (iconColor == -1){
imageMode(CORNERS);
image(icon, w + 5, 0,w+5+w,h);
}
else{
noStroke();
fill(iconColor);
ellipse(w + h/2 + 5, h/2,h,h);
}
}
else{
text(title, w + 5, 0);
}
}
}
}
boolean contentClicked(float lx, float ly)
{
value = !value;
System.out.println("Changing titles");
titleChanged = title;
// println(value);
//System.out.println(title+" "+value);
return true;
}
boolean mouseClicked(float px, float py){
if(c == '0'){
if (!ptInRect(px, py, x, y, w, h)) return false;
float lx = px - x;
float ly = py - y;
// check our subviews first
for (int i = subviews.size()-1; i >= 0; i--) {
// System.out.println(i);
View v = (View)subviews.get(i);
if (v.mouseClicked(lx, ly)) return true;
}
return contentClicked(lx, ly);
}
else{
if (!ptInRect(px, py, x-20, y-20, w+40, h+40)) return false;
float lx = px - x;
float ly = py - y;
// check our subviews first
for (int i = subviews.size()-1; i >= 0; i--) {
// System.out.println(i);
View v = (View)subviews.get(i);
if (v.mouseClicked(lx, ly)) return true;
}
return contentClicked(lx, ly);
}
}
void setValue(Boolean _value){
value = _value;
}
String getTitle(){
return title;
}
}