-
Notifications
You must be signed in to change notification settings - Fork 4
/
Tile.pde
341 lines (304 loc) · 9.49 KB
/
Tile.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
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
/**
* Petter - vector-graphic-based pattern generator.
* http://www.lafkon.net/petter/
* Copyright (C) 2015 LAFKON/Benjamin Stephan
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*/
public interface Tile {
public void draw(PGraphics g);
public void resetTransform();
public Tile getOrigin();
public void setOffsetX(float ox);
public void setOffsetY(float oy);
public void setScaleX(float sx);
public void setScaleY(float sy);
public void setRotation(float ro);
public float getOffsetX();
public float getOffsetY();
public float getScaleX();
public float getScaleY();
public float getRotation();
public float getWidth();
public float getHeight();
public float[] getTransformParams();
public void setTransformParams(float[] params);
public void enableGlobalStyle();
public void disableGlobalStyle();
public void useGlobalStyle(boolean use);
public void toggleUseGlobalStyle();
public boolean getUseGlobalStyle();
public void setExplodable(boolean flag);
public boolean isExplodable();
}
// ---------------------------------------------------------------------------
// TileSVG
// ---------------------------------------------------------------------------
public class TileSVG extends PShapeSVG implements Tile {
float scalex = 1f;
float scaley = 1f;
float offsetx = 0f;
float offsety = 0f;
float rotation = 0f;
boolean useGlobalStyle = true;
boolean explodable = true;
Tile origin = null;
String filepath = null;
public TileSVG(String path) {
super(loadXML(path));
filepath = path;
handleLFKN_VDB();
if(globalStyle) enableGlobalStyle();
}
public void draw(PGraphics g) {
try {
g.pushMatrix();
g.translate(offsetx, offsety);
g.translate(width/2, height/2);
g.scale(scalex, scaley);
g.rotate(rotation);
g.translate(-width/2, -height/2);
g.pushStyle();
setDrawStyle(exportCurrentFrame?pdf:g);
super.draw(g);
g.popStyle();
g.popMatrix();
} catch(Exception e) {
//e.printStackTrace();
}
}
private void setDrawStyle(PGraphics g) {
if(globalStyle && useGlobalStyle) {
if (customStroke) {
g.stroke(strokecolor[0]);
g.strokeWeight(customStrokeWeight); //setAbsoluteStrokeWeight
if(!strokeMode) { //setRelativeStrokeWeight
if(tileEditor == null || !tileEditor.getG().equals(g)) { //dirty! if not tileeditor drawing
//float relsw = ((ease(SCA, abscount, 1.0, relScale, tilecount))*(absScale)*(tilescale)*((Tile)s).getScaleX());
float relsw = totalscale; // take totalscale-calc from petter-main
if (relsw != 0f) { relsw = abs(customStrokeWeight*(1/relsw)); }
g.strokeWeight(relsw);
}
}
} else { g.noStroke(); }
if (customFill) {
g.fill(shapecolor[0]);
} else {
g.noFill();
}
g.strokeJoin(joinmode);
g.strokeCap(capmode);
}
}
public void resetTransform() {
scalex = 1f;
scaley = 1f;
offsetx = 0f;
offsety = 0f;
rotation = 0f;
}
public void enableGlobalStyle() {
if(useGlobalStyle) {
this.disableStyle();
super.disableStyle();
}
}
public void disableGlobalStyle() {
if(useGlobalStyle) {
this.enableStyle();
super.enableStyle();
}
}
public void useGlobalStyle(boolean use) {
this.useGlobalStyle = use;
if(use) {
if(globalStyle) {
this.disableStyle();
super.disableStyle();
}
} else {
if(globalStyle) {
this.enableStyle();
super.enableStyle();
}
}
}
public void toggleUseGlobalStyle() {
useGlobalStyle(!useGlobalStyle);
}
public Tile getOrigin() { return null; }
public void setOffsetX(float ox) { offsetx = ox; }
public void setOffsetY(float oy) { offsety = oy; }
public void setScaleX(float sx) { scalex = sx; }
public void setScaleY(float sy) { scaley = sy; }
public void setRotation(float ro) { rotation = ro; }
public float getOffsetX() { return offsetx; }
public float getOffsetY() { return offsety; }
public float getScaleX() { return scalex; }
public float getScaleY() { return scaley; }
public float getRotation() { return rotation; }
public boolean getUseGlobalStyle() { return useGlobalStyle; }
public void setExplodable(boolean flag) { explodable = flag; }
public boolean isExplodable() { return explodable; }
public float[] getTransformParams() {
float[] params = {offsetx, offsety, scalex, scaley, rotation};
return params;
}
public void setTransformParams(float[] params) {
if(params.length == 5) {
offsetx = params[0];
offsety = params[1];
scalex = params[2];
scaley = params[3];
rotation = params[4];
}
}
private void handleLFKN_VDB() {
if (split(filepath, ".lafkon.net").length > 1) {
filepath = split(filepath, ".pdf")[0] +".svg";
}
try {
int index = this.getChildIndex(this.getChild("disclaimer"));
this.removeChild(index); // remove disclaimer from LFKN-VDB-svgs
}
catch (ArrayIndexOutOfBoundsException e) {}
}
}
// ---------------------------------------------------------------------------
// TileShape
// ---------------------------------------------------------------------------
public class TileShape extends PShape implements Tile {
float scalex = 1f;
float scaley = 1f;
float offsetx = 0f;
float offsety = 0f;
float rotation = 0f;
boolean useGlobalStyle = true;
boolean explodable = true;
Tile origin = null;
public TileShape(PShape s, float w, float h) {
super();
this.addChild(s);
this.width = w;
this.height = h;
if(globalStyle) enableGlobalStyle();
}
public TileShape(PShape s, float w, float h, Tile origin) {
this(s, w, h);
this.origin = origin;
setOffsetX(origin.getOffsetX());
setOffsetY(origin.getOffsetY());
setScaleX(origin.getScaleX());
setScaleY(origin.getScaleY());
setRotation(origin.getRotation());
}
public void draw(PGraphics g) {
try {
g.pushMatrix();
g.translate(offsetx, offsety);
g.translate(width/2, height/2);
g.scale(scalex, scaley);
g.rotate(rotation);
g.translate(-width/2, -height/2);
g.pushStyle();
setDrawStyle(exportCurrentFrame?pdf:g);
super.draw(g);
g.popStyle();
g.popMatrix();
} catch(Exception e) {
//e.printStackTrace();
}
}
private void setDrawStyle(PGraphics g) {
if(globalStyle && useGlobalStyle) {
if (customStroke) {
g.stroke(strokecolor[0]);
g.strokeWeight(customStrokeWeight); //setAbsoluteStrokeWeight
if(!strokeMode) { //setRelativeStrokeWeight
if(tileEditor == null || !tileEditor.getG().equals(g)) { //dirty! if not tileeditor drawing
float relsw = ((ease(SCA, abscount, 1.0, relScale, tilecount))*(absScale)*(tilescale)*((Tile)s).getScaleX());
if (relsw != 0f) { relsw = abs(customStrokeWeight*(1/relsw)); }
g.strokeWeight(relsw);
}
}
} else { g.noStroke(); }
if (customFill) {
g.fill(shapecolor[0]);
} else {
g.noFill();
}
g.strokeJoin(joinmode);
g.strokeCap(capmode);
}
}
public void resetTransform() {
scalex = 1f;
scaley = 1f;
offsetx = 0f;
offsety = 0f;
rotation = 0f;
}
public void enableGlobalStyle() {
if(useGlobalStyle) {
this.disableStyle();
super.disableStyle();
}
}
public void disableGlobalStyle() {
if(useGlobalStyle) {
this.enableStyle();
super.enableStyle();
}
}
public void useGlobalStyle(boolean use) {
this.useGlobalStyle = use;
if(use) {
if(globalStyle) {
this.disableStyle();
super.disableStyle();
}
} else {
if(globalStyle) {
this.enableStyle();
super.enableStyle();
}
}
}
public void toggleUseGlobalStyle() {
useGlobalStyle(!useGlobalStyle);
}
public Tile getOrigin() { return origin; }
public void setOffsetX(float ox) { offsetx = ox; }
public void setOffsetY(float oy) { offsety = oy; }
public void setScaleX(float sx) { scalex = sx; }
public void setScaleY(float sy) { scaley = sy; }
public void setRotation(float ro) { rotation = ro; }
public float getOffsetX() { return offsetx; }
public float getOffsetY() { return offsety; }
public float getScaleX() { return scalex; }
public float getScaleY() { return scaley; }
public float getRotation() { return rotation; }
public boolean getUseGlobalStyle() { return useGlobalStyle; }
public void setExplodable(boolean flag) { explodable = flag; }
public boolean isExplodable() { return explodable; }
public float[] getTransformParams() {
float[] params = {offsetx, offsety, scalex, scaley, rotation};
return params;
}
public void setTransformParams(float[] params) {
if(params.length == 5) {
offsetx = params[0];
offsety = params[1];
scalex = params[2];
scaley = params[3];
rotation = params[4];
}
}
}