-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathButton.pde
56 lines (46 loc) · 1.38 KB
/
Button.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
public class Button extends UIBox{
Runnable to_run;
String text;
boolean is_pressed;
public Button(Position new_centre, float new_wh, float new_ht, Runnable new_to_run, color new_col) {
super(new Position(new_centre.get_x() - new_wh / 2, new_centre.get_y() - new_ht / 2), new_wh, new_ht, new_col);
to_run = new_to_run;
text = "";
is_pressed = false;
}
public Button(Position new_centre, float new_wh, float new_ht, Runnable new_to_run, color new_col, String new_text) {
this(new_centre, new_wh, new_ht, new_to_run, new_col);
text = new_text;
}
public String get_text() {
return text;
}
public boolean is_pressed() {
return is_pressed;
}
public void set_pressed(boolean new_pressed) {
is_pressed = new_pressed;
}
public void set_to_run(Runnable new_to_run) {
to_run = new_to_run;
}
public void press() {
to_run.run();
}
@Override
public void show() {
if (is_pressed()) {
super.show(color(red(get_color()) / 3f, green(get_color()) / 3f, blue(get_color()) / 3f));
} else {
super.show();
}
float leading_scalar = 5f / 3;
float horizontal_scalar = 2f / 3;
float vertical_scalar = 2f / 3;
new TextBox(this, get_text(), color(255)).show(leading_scalar, horizontal_scalar, vertical_scalar);
}
@Override
public void cleanup() {
cleanup_buttons.add(this);
}
}