-
Notifications
You must be signed in to change notification settings - Fork 0
/
TextBox.pde
72 lines (57 loc) · 2.36 KB
/
TextBox.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
public class TextBox extends Box implements Showable{
String text;
color text_color;
public TextBox(Position new_corner, float new_wh, float new_ht) {
super(new_corner, new_wh, new_ht);
text = "";
text_color = color(0);
}
public TextBox(Position new_corner, float new_wh, float new_ht, String new_text, color new_text_color) {
this(new_corner, new_wh, new_ht);
text = new_text;
text_color = new_text_color;
}
public TextBox(Box box) {
this(box.get_corner(), box.get_width(), box.get_height());
}
public TextBox(Box box, String new_text, color new_text_color) {
this(box.get_corner(), box.get_width(), box.get_height(), new_text, new_text_color);
}
public String get_text() {
return text;
}
public void set_text(String new_text) {
text = new_text;
}
public color get_text_color() {
return text_color;
}
public void show(float font_size, float leading_scalar, float horizontal_scalar, float vertical_scalar) {
PFont font = cp_gothic;
float new_width = get_width() * horizontal_scalar;
float new_height = get_height() * vertical_scalar;
Position new_corner = new Position(get_corner().get_x() + (get_width() - new_width) / 2f, get_corner().get_y() + (get_height() - new_height) / 2f);
Box print_box = new Box(new_corner, new_width, new_height);
textFont(font, font_size);
textLeading(font_size * leading_scalar);
fill(get_text_color());
text(text, print_box.get_corner().get_x() + print_box.get_width() / 2f, print_box.get_corner().get_y() + print_box.get_height() / 2f);
}
public void show(float leading_scalar, float horizontal_scalar, float vertical_scalar) {
float new_width = get_width() * horizontal_scalar;
float new_height = get_height() * vertical_scalar;
Position new_corner = new Position(get_corner().get_x() + (get_width() - new_width) / 2f, get_corner().get_y() + (get_height() - new_height) / 2f);
Box print_box = new Box(new_corner, new_width, new_height);
show(find_font_size(print_box, text, leading_scalar), leading_scalar, horizontal_scalar, vertical_scalar);
}
@Override
public void show() {
float leading_scalar = 5f / 3;
float horizontal_scalar = 1;
float vertical_scalar = 1;
show(leading_scalar, horizontal_scalar, vertical_scalar);
}
@Override
public void cleanup() {
}
}