-
Notifications
You must be signed in to change notification settings - Fork 1
/
DisplayTitle.pde
189 lines (141 loc) · 4.36 KB
/
DisplayTitle.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
class TypedText {
String title = "This is untitled...";
int charIndex = 0;
float charPerSec;
float charDx;
float charFrameCount;
color titleColor = color(0, 190, 0, 200);
float inset = 10, fontHeight = 16;
ARect bound;
PGraphics textG;
TypedText(ARect bound) {
this.bound = bound;
this.setCharPerSec(0.1);
}
void setTitle(String t) {
this.title = t;
this.setCharPerSec(charPerSec);
}
void setCharPerSec(float numCharPerSec) {
charPerSec = numCharPerSec;
charDx = 1.0/(charPerSec * frameRate);
charIndex = 0;
charFrameCount = - (1.0/ (5 * frameRate));
}
void draw(PGraphics g) {
if (charIndex >= title.length() + 1) {
g.image(textG, 0, 0);
return;
}
textG = createGraphics(this.bound);
textG.beginDraw();
textG.push();
textG.textSize(fontHeight);
textG.textFont(FONT_16);
textG.fill(titleColor);
textG.translate(inset, inset + fontHeight);
textG.text(this.title.substring(0, charIndex), 0, 0);
charFrameCount++;
if (charFrameCount >= charDx) {
charFrameCount = 0;
charIndex++;
}
textG.pop();
textG.endDraw();
g.image(textG, 0, 0);
}
}
class Panel {
ARect bound;
TypedText typedText;
PGraphics panel; //<>//
Panel(ARect bound, String text) {
this.bound = bound;
typedText = new TypedText(bound);
this.setText(text, 3.4);
preparePanel();
}
void preparePanel() {
this.panel = createGraphics(bound);
this.panel.beginDraw();
this.panel.strokeWeight(1);
this.panel.stroke(colorFromMap(), 100);
this.panel.fill(C_DEFAULT_FILL, random(80,100));
this.panel.rect(0, 0, (int)bound.width-1, (int)bound.height -1, 4);
this.panel.endDraw();
}
void setText(String text, float charPerSec) {
typedText.title = text;
typedText.setCharPerSec(text.length()/charPerSec);
}
void draw(PGraphics g) {
g.image(this.panel, 0, 0);
typedText.draw(g);
}
}
class DisplayTitle extends AbstractDisplay implements StateActionCallback {
PGraphics localG, panelG;
Panel panel;
ARect panelBound;
StateSequenceController stateC;
State state;
int STATE_WAIT_IN = 0, STATE_IN = 1, STATE_TEXT = 2,
STATE_WAIT = 3, STATE_OUT = 4;
float SEC_TEXT = 4, SEC_IN_OUT = 1;
float dxInOut, alphaPanel;
DisplayTitle(ARect bound, ARect panelBound, String title ) {
super(bound);
this.panelBound = panelBound;
panel = new Panel(this.panelBound, title);
panel.setText(title, SEC_TEXT);
stateC = new StateSequenceController();
stateC.listeners.add(this);
state = new State(this, STATE_WAIT_IN, 1 * frameRate);
stateC.add(state);
stateC.add(new State(this, STATE_IN, SEC_IN_OUT * frameRate));
stateC.add(new State(this, STATE_TEXT, SEC_TEXT * frameRate));
stateC.add(new State(this, STATE_WAIT, 4 * frameRate));
stateC.add(new State(this, STATE_OUT, SEC_IN_OUT * frameRate));
this.dxInOut = 1.0/(SEC_IN_OUT * frameRate);
}
void draw(PGraphics g) {
if (super.hidden) return;
if (this.state.stateId == STATE_WAIT_IN) {
return;
}
panelG = createGraphics(panelBound);
panelG.beginDraw();
panel.draw(panelG);
panelG.endDraw();
localG = createGraphics(bound); // draw translate only
localG.beginDraw();
if (this.state.stateId == STATE_WAIT || this.state.stateId == STATE_TEXT ) {
localG.image(panelG, panelBound.originX, panelBound.originY, panelBound.width, panelBound.height);
} else if (this.state.stateId == STATE_IN || this.state.stateId == STATE_OUT) {
localG.push();
this.alphaPanel = this.alphaPanel + this.state.stateId == STATE_IN? this.dxInOut: -this.dxInOut;
localG.tint(255, cvLinearToExp8( this.alphaPanel ) * 255);
localG.image(panelG, panelBound.originX, panelBound.originY, panelBound.width, panelBound.height);
localG.pop();
}
if (DEBUG) {
localG.stroke(C_PINK, 100);
localG.fill(100, 50);
localG.rect(0, 0, bound.width, bound.height);
}
localG.endDraw();
drawOn(localG, g, bound);
stateC.tick();
}
void callbackWith(StateSequenceController sc, State s, PGraphics g) {
if (s.owner != this) return;
this.state = s;
if (this.state.stateId == STATE_IN) {
this.alphaPanel = 0;
} else if (this.state.stateId == STATE_OUT) {
this.alphaPanel = 1;
}
}
void bang() {
}
}