-
Notifications
You must be signed in to change notification settings - Fork 1
/
TextObject.java
264 lines (234 loc) · 8.16 KB
/
TextObject.java
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
import processing.core.PApplet;
import processing.core.PGraphics;
import processing.core.PImage;
import processing.core.PFont;
import picking.*;
public class TextObject extends Thing
{
private String textstr;
private boolean setFont;
private boolean hover;
private boolean activeState;
private int fontSize;
private PFont font;
private ColorConfiguration config;
private PImage nodeImage;
private PImage popupNodeImage;
private PImage nodeImageHover;
private PImage nodeImageActive;
TextObject(PApplet context, String txt, String user, long timestamp, int id, int fontSize, PFont font)
{
this.activate();
this.textstr = txt;
this.fontSize = fontSize;
this.font = font;
this.setFont = true;
this.position = new PhysicalParameter(0, 0, 0, 0, 0, 0);
this.resetPhysicsToDefault();
this.setPos = false;
this.setContext(context);
this.setAlpha(255);
this.setTimestamp(timestamp);
this.setMode(IDLE);
this.setId(id);
this.config = ((NetworkOfThoughts)context).config;
this.nodeImage = context.loadImage(config.nodeImage);
this.popupNodeImage = context.loadImage(config.popupNodeImage);
this.nodeImageHover = context.loadImage(config.nodeImageHover);
this.nodeImageActive = context.loadImage(config.nodeImageActive);
this.hover = false;
this.activeState = false;
}
TextObject(PApplet context, String txt, String user, long timestamp, int id)
{
this.activate();
this.textstr = txt;
this.setUser(user);
this.fontSize = 15;
this.setFont = false;
this.position = new PhysicalParameter(0, 0, 0, 0, 0, 0);
this.resetPhysicsToDefault();
this.setPos = false;
this.setContext(context);
this.setAlpha(255);
this.setTimestamp(timestamp);
this.setMode(IDLE);
this.setId(id);
this.config = ((NetworkOfThoughts)context).config;
this.nodeImage = context.loadImage(config.nodeImage);
this.popupNodeImage = context.loadImage(config.popupNodeImage);
this.nodeImageHover = context.loadImage(config.nodeImageHover);
this.nodeImageActive = context.loadImage(config.nodeImageActive);
this.hover = false;
this.activeState = false;
}
public void setHover(boolean value)
{
this.hover = value;
}
public void setActiveState(boolean value)
{
this.activeState = value;
}
public void resetPhysicsToDefault()
{
this.position.setMaxSpeed((float)40);
this.position.setSpring((float)0);
this.position.setDrag((float)1);
}
public String getText()
{
return textstr;
}
//TODO: WROOONG... set position and call render()... Maybe not, its goot to render out of position for interface design reasons
public void render(float x, float y, float z)
{
if(this.active)
{
if(this.setFont)
{
this.context.textFont(font, fontSize);
}
this.context.text(textstr, x, y, z);
}
}
public void render(float x, float y)
{
if(this.active)
{
if(this.setFont)
{
this.context.textFont(font, fontSize);
}
this.context.text(textstr, x, y);
}
}
public void render()
{
if(this.active)
{
int nodeXOffset = 22;
int nodeYOffset = 19;
context.pushMatrix();
context.translate(0,0,this.position.getPosition().z);
if(this.getMode() != TEMPORARY)
{
if(this.activeState)
{
//HERE GOES THE IMAGE RENDERING
context.tint(255, this.getAlpha());
context.image(this.nodeImageActive, this.position.getPosition().x-nodeXOffset, this.position.getPosition().y-nodeYOffset, 23, 23);
context.tint(255);
}else if (!this.hover)
{
//HERE GOES THE IMAGE RENDERING
context.tint(255, this.getAlpha());
context.image(this.nodeImage, this.position.getPosition().x-nodeXOffset, this.position.getPosition().y-nodeYOffset, 23, 23);
context.tint(255);
}
else
{
//HERE GOES THE IMAGE RENDERING
context.tint(255, this.getAlpha());
context.image(this.nodeImageHover, this.position.getPosition().x-nodeXOffset, this.position.getPosition().y-nodeYOffset, 23, 23);
context.tint(255);
}
}else
{
//HERE GOES THE IMAGE RENDERING
context.tint(255, this.getAlpha());
context.image(this.popupNodeImage, this.position.getPosition().x-nodeXOffset, this.position.getPosition().y-nodeYOffset, 23, 23);
context.tint(255);
}
/*int lineHeight = context.round(context.textAscent()+context.textDescent())+5;
int nLines = textstr.split("\n").length;
context.fill(255,255, 255, 50);
context.noStroke();
context.rect(this.position.getPosition().x-3, this.position.getPosition().y-context.textAscent()-5, context.textWidth(this.textstr)+5, lineHeight*nLines+1);*/
context.fill(config.text);
context.popMatrix();
if(this.getMode() == TEMPORARY)
{
context.fill(config.popupText);
}
else
{
context.fill(context.red(config.text),context.green(config.text),context.blue(config.text),this.getAlpha());
//context.fill(0,0,0);
}
if(this.setFont)
{
this.context.textFont(font, fontSize);
}
/*if(this.getMode() == SELECTED)
{
this.context.textSize(fontSize + 5);
}
else
{
this.context.textSize(fontSize); //TODO: DO NOT SET ALLWAYS, ONLY WHEN NECESSARY
}*/
this.context.textSize(fontSize); //TODO: DO NOT SET ALLWAYS, ONLY WHEN NECESSARY
this.context.text(textstr, this.position.getPosition().x, this.position.getPosition().y, this.position.getPosition().z);
}
}
public void render(PGraphics context)
{
context.background(255);
if(this.active)
{
if(this.getMode() != TEMPORARY)
{
context.fill(config.normalNode);
}else
{
context.fill(config.popupNode);
}
//context.ellipse(this.position.getPosition().x-5, this.position.getPosition().y-12, 10, 10);
//HERE GOES THE IMAGE RENDERING
context.tint(255, this.getAlpha());
context.image(this.nodeImage, 0, 0, 20, 20);
context.tint(255);
if(this.getMode() == TEMPORARY)
{
context.fill(config.popupText);
}
else
{
context.fill(context.red(config.text),context.green(config.text),context.blue(config.text),this.getAlpha());
//context.fill(0,0,0);
}
if(this.setFont)
{
context.textFont(font, fontSize);
}
context.textSize(fontSize); //TODO: DO NOT SET ALLWAYS, ONLY WHEN NECESSARY
context.text(textstr, 15, 18, 0);
}
}
public void renderHitArea()
{
this.context.textSize(fontSize); //TODO: DO NOT SET ALLWAYS, ONLY WHEN NECESSARY
context.pushMatrix();
context.translate(0,0,this.position.getPosition().z);
context.fill(100,100,100,50);
context.ellipse(this.position.getPosition().x-10, this.position.getPosition().y-10, 40, 40);
int lineHeight = context.round(context.textAscent()+context.textDescent())+5;
int nLines = textstr.split("\n").length;
context.rect(this.position.getPosition().x, this.position.getPosition().y-context.textAscent(), context.textWidth(this.textstr), lineHeight*nLines+1);
context.fill(0);
context.popMatrix();
}
public void renderHitArea(Buffer buffer)
{
this.context.textSize(fontSize); //TODO: DO NOT SET ALLWAYS, ONLY WHEN NECESSARY
buffer.pushMatrix();
buffer.translate(0,0,this.position.getPosition().z);
buffer.ellipse(this.position.getPosition().x-5, this.position.getPosition().y-5, 40, 40);
int lineHeight = context.round(context.textAscent()+context.textDescent())+5;
int nLines = textstr.split("\n").length;
buffer.rect(this.position.getPosition().x, this.position.getPosition().y-context.textAscent(), context.textWidth(this.textstr), lineHeight*nLines+1);
buffer.fill(0);
buffer.popMatrix();
}
}