-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathText.pde
More file actions
73 lines (65 loc) · 1.42 KB
/
Text.pde
File metadata and controls
73 lines (65 loc) · 1.42 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
class Text {
String contentType;
PVector pos;
int fontSize;
String content;
int xAlign, yAlign;
int w;
int h;
color c;
boolean boundSet, contentSet, alignSet, fontSet;
boolean underline;
int lineWidth, lineHeight;
PFont font;
Text (String type, int _fontSize) {
contentType = type;
fontSize = _fontSize;
}
void setBound(int x, int y, int _w, int _h) {
pos = new PVector(x, y);
w = _w;
h = _h;
boundSet = true;
}
void setAlign(int xAlignment, int yAlignment) {
xAlign = xAlignment;
yAlign = yAlignment;
alignSet = true;
}
void setContent(String _content) {
content = _content;
contentSet = true;
}
void setColor(color _c) {
c = _c;
}
void setFont(PFont f) {
font = f;
fontSet = true;
}
void addLine( int lineW, int lineH ) {
lineWidth = lineW;
lineHeight = lineH;
underline = true;
}
void drawOn(PGraphics pg) {
if (boundSet && contentSet && alignSet && fontSet ) {
pg.beginDraw();
pg.pushMatrix();
pg.translate(pos.x, pos.y);
pg.textFont(font);
pg.textAlign(xAlign, yAlign);
pg.textSize(fontSize);
if (contentType == "headline") {
pg.strokeCap(SQUARE);
pg.textLeading(fontSize*0.9);
}
pg.fill(c);
pg.text(content, 0, 0, w, h);
pg.popMatrix();
pg.endDraw();
} else {
System.err.println("Text hasn't been set fully");
}
}
}