-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathUtilityMethods.pde
94 lines (85 loc) · 2.66 KB
/
UtilityMethods.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
import com.krab.lazy.*;
LazyGui gui;
void setup() {
size(800, 800, P2D);
gui = new LazyGui(this);
}
void draw() {
background(gui.colorPicker("background", color(36)).hex);
translate(width/2, height/2);
gui.pushFolder("rect");
pushMatrix();
transform();
PVector size = gui.plotXY("size", 300, 100);
style();
rect(0, 0, size.x, size.y);
popMatrix();
gui.popFolder();
gui.pushFolder("text");
pushMatrix();
transform();
font();
text(gui.text("text", "hello"), 0, 0);
popMatrix();
gui.popFolder();
}
// Change position and rotation without creating a new gui folder.
void transform() {
gui.pushFolder("transform");
PVector pos = gui.plotXY("pos");
translate(pos.x, pos.y);
rotate(gui.slider("rotate"));
PVector scale = gui.plotXY("scale", 1.00);
scale(scale.x, scale.y);
gui.popFolder();
}
// Change drawing style
void style() {
gui.pushFolder("style");
strokeWeight(gui.slider("weight", 4));
stroke(gui.colorPicker("stroke", color(0)).hex);
fill(gui.colorPicker("fill", color(200)).hex);
String rectMode = gui.radio("rect mode", new String[]{"center", "corner"});
if ("center".equals(rectMode)) {
rectMode(CENTER);
} else {
rectMode(CORNER);
}
gui.popFolder();
}
// font() related fields
PFont selectedFont;
HashMap<String, Integer> xAligns;
HashMap<String, Integer> yAligns;
void font() {
gui.pushFolder("font");
fill(gui.colorPicker("fill", color(255)).hex);
int size = gui.sliderInt("size", 64, 1, 256);
float leading = gui.slider("leading", 64);
if (xAligns == null || yAligns == null) {
xAligns = new HashMap<String, Integer>();
xAligns.put("left", LEFT);
xAligns.put("center", CENTER);
xAligns.put("right", RIGHT);
yAligns = new HashMap<String, Integer>();
yAligns.put("top", TOP);
yAligns.put("center", CENTER);
yAligns.put("bottom", BOTTOM);
}
String xAlignSelection = gui.radio("align x", xAligns.keySet().toArray(new String[0]), "center");
String yAlignSelection = gui.radio("align y", yAligns.keySet().toArray(new String[0]), "center");
textAlign(xAligns.get(xAlignSelection), yAligns.get(yAlignSelection));
String fontName = gui.text("font name", "Arial").trim();
if (gui.button("list fonts")) {
String[] fonts = PFont.list();
for (String font : fonts) {
println(font + " "); // some spaces to avoid copying newlines from the console
}
}
if (selectedFont == null || gui.hasChanged("font name") || gui.hasChanged("size")) {
selectedFont = createFont(fontName, size);
}
textFont(selectedFont);
textLeading(leading);
gui.popFolder();
}