Repository navigation
Expand file tree
/
Copy pathsearchBar.pde
More file actions
94 lines (86 loc) · 1.95 KB
/
Copy pathsearchBar.pde
File metadata and controls
94 lines (86 loc) · 1.95 KB
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
// Jake Casserly's code for searchBar 20/03/2024
class searchBar {
float x, y, width, height;
String label;
color widgetColor, labelColor, borderColor;
private boolean active;
private String result;
private boolean blank;
public searchBar(float x, float y, float width, float height, String label, color widgetColor, String result, boolean blank)
{
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.label = label;
this.widgetColor = widgetColor;
labelColor = color(0);
this.result = result;
this.blank = false;
}
void display()
{
strokeWeight(5);
stroke(borderColor);
fill(widgetColor);
rect(x, y, width, height, 15);
fill(labelColor);
textAlign(CENTER, CENTER);
textSize(25);
text(label, x + width / 2, y + height / 2);
}
void adjustText()
{
if (!blank)
{
label = "";
blank = true;
}
if (keyPressed)
{
if (key != ENTER && key != BACKSPACE)
{
label += key;
}
else if (key == BACKSPACE && label.length() > 0)
{
label = label.substring(0, label.length() - 1);
}
keyPressed = false;
}
}
boolean checkSearchBar(float mx, float my)
{
if (mx > x && mx < x + width && my > y && my < y + height)
{
return true;
}
return false;
}
boolean checkBorder(float mx, float my)
{
if (mx > x && mx < x + width && my > y && my < y + height)
{
borderColor = 255;
return true;
}
if (mx < x || mx > x + width || my < y || my > y + height)
{
borderColor = 0;
return true;
}
return false;
}
void result() {
String test = label;
println("Request");
if (label != "type text here...") {
result = test.toUpperCase();
println("Request fulfilled");
}
else {
label = "";
print("reset");
}
}
}