-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
/
ParticleEditor.java
644 lines (558 loc) · 23.1 KB
/
ParticleEditor.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
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
/*******************************************************************************
* Copyright 2011 See AUTHORS file.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package com.badlogic.gdx.tools.particleeditor;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.util.HashMap;
import javax.swing.*;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.border.CompoundBorder;
import javax.swing.plaf.basic.BasicSplitPaneUI;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Files.FileType;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.backends.lwjgl.LwjglCanvas;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
import com.badlogic.gdx.graphics.g2d.ParticleEmitter;
import com.badlogic.gdx.graphics.g2d.ParticleEmitter.GradientColorValue;
import com.badlogic.gdx.graphics.g2d.ParticleEmitter.NumericValue;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.GdxRuntimeException;
public class ParticleEditor extends JFrame {
public static final String DEFAULT_PARTICLE = "particle.png";
public static final String DEFAULT_PREMULT_PARTICLE = "pre_particle.png";
public Renderer renderer;
LwjglCanvas lwjglCanvas;
JPanel rowsPanel;
JPanel editRowsPanel;
EffectPanel effectPanel;
PreviewImagePanel previewImagePanel;
private JSplitPane splitPane;
OrthographicCamera worldCamera;
OrthographicCamera textCamera;
NumericValue pixelsPerMeter;
NumericValue zoomLevel;
NumericValue deltaMultiplier;
GradientColorValue backgroundColor;
float pixelsPerMeterPrev;
float zoomLevelPrev;
ParticleEffect effect = new ParticleEffect();
File effectFile;
final HashMap<ParticleEmitter, ParticleData> particleData = new HashMap();
JCheckBox renderGridCheckBox;
public ParticleEditor () {
super("Particle Editor");
renderer = new Renderer();
lwjglCanvas = new LwjglCanvas(renderer);
addWindowListener(new WindowAdapter() {
public void windowClosed (WindowEvent event) {
System.exit(0);
// Gdx.app.quit();
}
});
initializeComponents();
setSize(1000, 950);
setLocationRelativeTo(null);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setVisible(true);
}
void reloadRows () {
EventQueue.invokeLater(new Runnable() {
public void run () {
editRowsPanel.removeAll();
addEditorRow(new NumericPanel(pixelsPerMeter, "Pixels per meter", ""));
addEditorRow(new NumericPanel(zoomLevel, "Zoom level", ""));
addEditorRow(new NumericPanel(deltaMultiplier, "Delta multiplier", ""));
addEditorRow(new GradientPanel(backgroundColor, "Background color", "", true));
previewImagePanel = new PreviewImagePanel(ParticleEditor.this, "Preview Image", "");
addEditorRow(previewImagePanel);
JPanel gridPanel = new JPanel(new GridLayout());
boolean previousSelected = renderGridCheckBox != null && renderGridCheckBox.isSelected();
renderGridCheckBox = new JCheckBox("Render Grid", previousSelected);
gridPanel.add(renderGridCheckBox, new GridBagConstraints());
addEditorRow(gridPanel);
addEditorRow(new CustomShadingPanel(ParticleEditor.this, "Shading", "Custom shader and multi-texture preview."));
rowsPanel.removeAll();
ParticleEmitter emitter = getEmitter();
addRow(new ImagePanel(ParticleEditor.this, "Images", ""));
addRow(new CountPanel(ParticleEditor.this, "Count",
"Min number of particles at all times, max number of particles allowed."));
addRow(new RangedNumericPanel(emitter.getDelay(), "Delay",
"Time from beginning of effect to emission start, in milliseconds."));
addRow(new RangedNumericPanel(emitter.getDuration(), "Duration", "Time particles will be emitted, in milliseconds."));
addRow(new ScaledNumericPanel(emitter.getEmission(), "Duration", "Emission",
"Number of particles emitted per second."));
addRow(new ScaledNumericPanel(emitter.getLife(), "Duration", "Life", "Time particles will live, in milliseconds."));
addRow(new ScaledNumericPanel(emitter.getLifeOffset(), "Duration", "Life Offset",
"Particle starting life consumed, in milliseconds."));
addRow(new RangedNumericPanel(emitter.getXOffsetValue(), "X Offset",
"Amount to offset a particle's starting X location, in world units."));
addRow(new RangedNumericPanel(emitter.getYOffsetValue(), "Y Offset",
"Amount to offset a particle's starting Y location, in world units."));
addRow(new SpawnPanel(ParticleEditor.this, emitter.getSpawnShape(), "Spawn", "Shape used to spawn particles."));
addRow(new ScaledNumericPanel(emitter.getSpawnWidth(), "Duration", "Spawn Width",
"Width of the spawn shape, in world units."));
addRow(new ScaledNumericPanel(emitter.getSpawnHeight(), "Duration", "Spawn Height",
"Height of the spawn shape, in world units."));
addRow(new ScaledNumericPanel(emitter.getXScale(), "Life", "X Size", "Particle x size, in world units. If Y Size is not active, this also controls the y size"));
addRow(new ScaledNumericPanel(emitter.getYScale(), "Life", "Y Size", "Particle y size, in world units."));
addRow(new ScaledNumericPanel(emitter.getVelocity(), "Life", "Velocity", "Particle speed, in world units per second."));
addRow(new ScaledNumericPanel(emitter.getAngle(), "Life", "Angle", "Particle emission angle, in degrees."));
addRow(new ScaledNumericPanel(emitter.getRotation(), "Life", "Rotation", "Particle rotation, in degrees."));
addRow(new ScaledNumericPanel(emitter.getWind(), "Life", "Wind", "Wind strength, in world units per second."));
addRow(new ScaledNumericPanel(emitter.getGravity(), "Life", "Gravity", "Gravity strength, in world units per second."));
addRow(new GradientPanel(emitter.getTint(), "Tint", "", false));
addRow(new PercentagePanel(emitter.getTransparency(), "Life", "Transparency", ""));
addRow(new OptionsPanel(ParticleEditor.this, "Options", ""));
for (Component component : rowsPanel.getComponents())
if (component instanceof EditorPanel) ((EditorPanel)component).update(ParticleEditor.this);
rowsPanel.repaint();
}
});
}
void addEditorRow (JPanel row) {
row.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, java.awt.Color.black));
editRowsPanel.add(row, new GridBagConstraints(0, -1, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(0, 0, 0, 0), 0, 0));
}
void addRow (JPanel row) {
row.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, java.awt.Color.black));
rowsPanel.add(row, new GridBagConstraints(0, -1, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(0, 0, 0, 0), 0, 0));
}
public void setVisible (String name, boolean visible) {
for (Component component : rowsPanel.getComponents())
if (component instanceof EditorPanel && ((EditorPanel)component).getName().equals(name)) component.setVisible(visible);
}
public ParticleEmitter getEmitter () {
return effect.getEmitters().get(effectPanel.editIndex);
}
public void setEnabled (ParticleEmitter emitter, boolean enabled) {
ParticleData data = particleData.get(emitter);
if (data == null) particleData.put(emitter, data = new ParticleData());
data.enabled = enabled;
emitter.reset();
}
public boolean isEnabled (ParticleEmitter emitter) {
ParticleData data = particleData.get(emitter);
if (data == null) return true;
return data.enabled;
}
private void initializeComponents () {
// {
// JMenuBar menuBar = new JMenuBar();
// setJMenuBar(menuBar);
// JPopupMenu.setDefaultLightWeightPopupEnabled(false);
// JMenu fileMenu = new JMenu("File");
// menuBar.add(fileMenu);
// }
splitPane = new JSplitPane();
splitPane.setUI(new BasicSplitPaneUI() {
public void paint (Graphics g, JComponent jc) {
}
});
splitPane.setDividerSize(4);
getContentPane().add(splitPane, BorderLayout.CENTER);
{
JSplitPane rightSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
rightSplit.setUI(new BasicSplitPaneUI() {
public void paint (Graphics g, JComponent jc) {
}
});
rightSplit.setDividerSize(4);
splitPane.add(rightSplit, JSplitPane.RIGHT);
{
JPanel propertiesPanel = new JPanel(new GridBagLayout());
rightSplit.add(propertiesPanel, JSplitPane.TOP);
propertiesPanel.setBorder(new CompoundBorder(BorderFactory.createEmptyBorder(3, 0, 6, 6), BorderFactory
.createTitledBorder("Editor Properties")));
{
JScrollPane scroll = new JScrollPane();
propertiesPanel.add(scroll, new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.NORTH,
GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
scroll.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
{
editRowsPanel = new JPanel(new GridBagLayout());
scroll.setViewportView(editRowsPanel);
scroll.getVerticalScrollBar().setUnitIncrement(70);
}
}
}
{
JPanel propertiesPanel = new JPanel(new GridBagLayout());
rightSplit.add(propertiesPanel, JSplitPane.BOTTOM);
propertiesPanel.setBorder(new CompoundBorder(BorderFactory.createEmptyBorder(3, 0, 6, 6), BorderFactory
.createTitledBorder("Emitter Properties")));
{
JScrollPane scroll = new JScrollPane();
propertiesPanel.add(scroll, new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.NORTH,
GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
scroll.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
{
rowsPanel = new JPanel(new GridBagLayout());
scroll.setViewportView(rowsPanel);
scroll.getVerticalScrollBar().setUnitIncrement(70);
}
}
}
rightSplit.setDividerLocation(200);
}
{
JSplitPane leftSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
leftSplit.setUI(new BasicSplitPaneUI() {
public void paint (Graphics g, JComponent jc) {
}
});
leftSplit.setDividerSize(4);
splitPane.add(leftSplit, JSplitPane.LEFT);
{
JPanel spacer = new JPanel(new BorderLayout());
leftSplit.add(spacer, JSplitPane.BOTTOM);
spacer.add(lwjglCanvas.getCanvas());
spacer.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 4));
}
{
JPanel emittersPanel = new JPanel(new BorderLayout());
leftSplit.add(emittersPanel, JSplitPane.TOP);
emittersPanel.setBorder(new CompoundBorder(BorderFactory.createEmptyBorder(0, 6, 6, 0), BorderFactory
.createTitledBorder("Effect Emitters")));
{
effectPanel = new EffectPanel(this);
emittersPanel.add(effectPanel);
}
}
leftSplit.setDividerLocation(575);
}
splitPane.setDividerLocation(325);
}
class Renderer implements ApplicationListener, InputProcessor {
private float maxActiveTimer;
private int maxActive, lastMaxActive;
private boolean mouseDown;
private int activeCount;
private int mouseX, mouseY;
private BitmapFont font;
private SpriteBatch spriteBatch;
private ShapeRenderer shapeRenderer;
private com.badlogic.gdx.graphics.Color lineColor;
public Sprite bgImage; // BOZO - Add setting background image to UI.
public CustomShading customShading;
public void create () {
if (spriteBatch != null) return;
customShading = new CustomShading();
spriteBatch = new SpriteBatch();
shapeRenderer = new ShapeRenderer();
lineColor = com.badlogic.gdx.graphics.Color.valueOf("636363");
worldCamera = new OrthographicCamera();
textCamera = new OrthographicCamera();
pixelsPerMeter = new NumericValue();
pixelsPerMeter.setValue(1.0f);
pixelsPerMeter.setAlwaysActive(true);
zoomLevel = new NumericValue();
zoomLevel.setValue(1.0f);
zoomLevel.setAlwaysActive(true);
deltaMultiplier = new NumericValue();
deltaMultiplier.setValue(1.0f);
deltaMultiplier.setAlwaysActive(true);
backgroundColor = new GradientColorValue();
backgroundColor.setColors(new float[] {0f, 0f, 0f});
font = new BitmapFont(Gdx.files.getFileHandle("default.fnt", FileType.Internal), Gdx.files.getFileHandle("default.png",
FileType.Internal), true);
effectPanel.newExampleEmitter("Untitled", true);
// if (resources.openFile("/editor-bg.png") != null) bgImage = new Image(gl, "/editor-bg.png");
OrthoCamController orthoCamController = new OrthoCamController (worldCamera);
Gdx.input.setInputProcessor(new InputMultiplexer(orthoCamController, this));
}
private class OrthoCamController extends InputAdapter {
final OrthographicCamera camera;
final Vector3 curr = new Vector3();
final Vector3 last = new Vector3(-1, -1, -1);
final Vector3 delta = new Vector3();
boolean canDrag = false;
public OrthoCamController (OrthographicCamera camera) {
this.camera = camera;
}
@Override
public boolean scrolled (int amount) {
worldCamera.zoom += amount * 0.01f;
worldCamera.zoom = MathUtils.clamp(worldCamera.zoom, 0.01f, 5000);
worldCamera.update();
return super.scrolled(amount);
}
@Override
public boolean touchDown (int screenX, int screenY, int pointer, int button) {
if (button == Input.Buttons.LEFT) {
canDrag = true;
} else {
canDrag = false;
}
return super.touchDown(screenX, screenY, pointer, button);
}
@Override
public boolean touchDragged (int x, int y, int pointer) {
if (!canDrag) return false;
camera.unproject(curr.set(x, y, 0));
if (!(last.x == -1 && last.y == -1 && last.z == -1)) {
camera.unproject(delta.set(last.x, last.y, 0));
delta.sub(curr);
camera.position.add(delta.x, delta.y, 0);
}
last.set(x, y, 0);
camera.update();
return false;
}
@Override
public boolean touchUp (int x, int y, int pointer, int button) {
last.set(-1, -1, -1);
canDrag = false;
return false;
}
}
@Override
public void resize (int width, int height) {
Gdx.gl.glViewport(0, 0, width, height);
if (pixelsPerMeter.getValue() <= 0) {
pixelsPerMeter.setValue(1);
}
worldCamera.setToOrtho(false, width / pixelsPerMeter.getValue(), height / pixelsPerMeter.getValue());
worldCamera.update();
textCamera.setToOrtho(true, width, height);
textCamera.update();
effect.setPosition(worldCamera.viewportWidth / 2, worldCamera.viewportHeight / 2);
}
private void renderGrid (ShapeRenderer shapeRenderer, int minX, int maxX, int minY, int maxY) {
shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
shapeRenderer.setColor(this.lineColor);
for (int i = minX; i <= maxX; i++) {
shapeRenderer.line(i, minY, i, maxY);
}
for (int i = minY; i <= maxY; i++) {
shapeRenderer.line(minX, i, maxX, i);
}
shapeRenderer.end();
}
public void render () {
int viewWidth = Gdx.graphics.getWidth();
int viewHeight = Gdx.graphics.getHeight();
float delta = Math.max(0, Gdx.graphics.getDeltaTime() * deltaMultiplier.getValue());
float[] colors = backgroundColor.getColors();
Gdx.gl.glClearColor(colors[0], colors[1], colors[2], 1.0f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
previewImagePanel.updateSpritePosition();
if ((pixelsPerMeter.getValue() != pixelsPerMeterPrev) || (zoomLevel.getValue() != zoomLevelPrev)) {
if (pixelsPerMeter.getValue() <= 0) {
pixelsPerMeter.setValue(1);
}
worldCamera.setToOrtho(false, viewWidth / pixelsPerMeter.getValue(), viewHeight / pixelsPerMeter.getValue());
worldCamera.zoom = zoomLevel.getValue();
worldCamera.update();
effect.setPosition(worldCamera.viewportWidth / 2, worldCamera.viewportHeight / 2);
zoomLevelPrev = zoomLevel.getValue();
pixelsPerMeterPrev = pixelsPerMeter.getValue();
}
spriteBatch.setProjectionMatrix(worldCamera.combined);
shapeRenderer.setProjectionMatrix(ParticleEditor.this.worldCamera.combined);
if (renderGridCheckBox.isSelected()) {
renderGrid(shapeRenderer, -40, 40, -40, 40);
}
shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
shapeRenderer.line(-1000, 0, 1000, 0, com.badlogic.gdx.graphics.Color.GREEN, com.badlogic.gdx.graphics.Color.GREEN);
shapeRenderer.line(0, -1000, 0, 1000, com.badlogic.gdx.graphics.Color.RED, com.badlogic.gdx.graphics.Color.RED);
shapeRenderer.end();
spriteBatch.begin();
spriteBatch.enableBlending();
spriteBatch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
if (bgImage != null) {
bgImage.draw(spriteBatch);
}
activeCount = 0;
boolean complete = true;
customShading.begin(spriteBatch);
for (ParticleEmitter emitter : effect.getEmitters()) {
if (emitter.getSprites().size == 0 && emitter.getImagePaths().size > 0) loadImages(emitter);
boolean enabled = isEnabled(emitter);
if (enabled) {
if (emitter.getSprites().size > 0) emitter.draw(spriteBatch, delta);
activeCount += emitter.getActiveCount();
if (!emitter.isComplete()) complete = false;
}
}
customShading.end(spriteBatch);
if (complete) effect.start();
maxActive = Math.max(maxActive, activeCount);
maxActiveTimer += delta;
if (maxActiveTimer > 3) {
maxActiveTimer = 0;
lastMaxActive = maxActive;
maxActive = 0;
}
if (mouseDown) {
// gl.drawLine(mouseX - 6, mouseY, mouseX + 5, mouseY);
// gl.drawLine(mouseX, mouseY - 5, mouseX, mouseY + 6);
}
spriteBatch.setProjectionMatrix(textCamera.combined);
font.draw(spriteBatch, "FPS: " + Gdx.graphics.getFramesPerSecond(), 5, 15);
font.draw(spriteBatch, "Count: " + activeCount, 5, 35);
font.draw(spriteBatch, "Max: " + lastMaxActive, 5, 55);
font.draw(spriteBatch, (int)(getEmitter().getPercentComplete() * 100) + "%", 5, 75);
spriteBatch.end();
// gl.drawLine((int)(viewWidth * getCurrentParticles().getPercentComplete()), viewHeight - 1, viewWidth, viewHeight -
// 1);
}
private void loadImages (ParticleEmitter emitter) {
String imagePath = null;
try {
Array<Sprite> sprites = new Array<Sprite>();
Array<String> imagePaths = emitter.getImagePaths();
for (int i = 0; i < imagePaths.size; i++) {
imagePath = imagePaths.get(i);
String imageName = new File(imagePath.replace('\\', '/')).getName();
FileHandle file;
if (imagePath.equals(ParticleEditor.DEFAULT_PARTICLE) || imagePath.equals(ParticleEditor.DEFAULT_PREMULT_PARTICLE)) {
file = Gdx.files.classpath(imagePath);
} else {
if ((imagePath.contains("/") || imagePath.contains("\\")) && !imageName.contains("..")) {
file = Gdx.files.absolute(imagePath);
if (!file.exists()) {
// try to use image in effect directory
file = Gdx.files.absolute(new File(effectFile.getParentFile(), imageName).getAbsolutePath());
}
} else {
file = Gdx.files.absolute(new File(effectFile.getParentFile(), imagePath).getAbsolutePath());
}
}
sprites.add(new Sprite(new Texture(file)));
}
emitter.setSprites(sprites);
} catch (GdxRuntimeException ex) {
ex.printStackTrace();
final String imagePathFinal = imagePath;
EventQueue.invokeLater(new Runnable() {
public void run () {
JOptionPane.showMessageDialog(ParticleEditor.this, "Error loading image:\n" + imagePathFinal);
}
});
emitter.getImagePaths().clear();
}
}
public boolean keyDown (int keycode) {
if (keycode == Input.Keys.SPACE) {
effect.setPosition(previewImagePanel.valueX.getValue() + previewImagePanel.valueWidth.getValue()/2f,
previewImagePanel.valueY.getValue() + previewImagePanel.valueHeight.getValue()/2f);
}
return false;
}
public boolean keyUp (int keycode) {
return false;
}
public boolean keyTyped (char character) {
return false;
}
public boolean touchDown (int x, int y, int pointer, int newParam) {
if (Gdx.input.isButtonPressed(Input.Buttons.RIGHT)) {
Vector3 touchPoint = new Vector3(x, y, 0);
worldCamera.unproject(touchPoint);
effect.setPosition(touchPoint.x, touchPoint.y);
}
return false;
}
public boolean touchUp (int x, int y, int pointer, int button) {
ParticleEditor.this.dispatchEvent(new WindowEvent(ParticleEditor.this, WindowEvent.WINDOW_LOST_FOCUS));
ParticleEditor.this.dispatchEvent(new WindowEvent(ParticleEditor.this, WindowEvent.WINDOW_GAINED_FOCUS));
ParticleEditor.this.requestFocusInWindow();
return false;
}
public boolean touchDragged (int x, int y, int pointer) {
if (Gdx.input.isButtonPressed(Input.Buttons.RIGHT)) {
Vector3 touchPoint = new Vector3(x, y, 0);
worldCamera.unproject(touchPoint);
effect.setPosition(touchPoint.x, touchPoint.y);
}
return false;
}
@Override
public void dispose () {
}
@Override
public void pause () {
}
@Override
public void resume () {
}
@Override
public boolean mouseMoved (int x, int y) {
return false;
}
@Override
public boolean scrolled (float amountX, float amountY) {
return false;
}
public void setImageBackground (File file) {
if (bgImage != null) {
bgImage.getTexture().dispose();
bgImage = null;
}
if (file != null) {
bgImage = new Sprite(new Texture(Gdx.files.absolute(file.getAbsolutePath())));
}
}
public void updateImageBackgroundPosSize (float x, float y, float width, float height) {
if (bgImage != null) {
bgImage.setPosition(x, y);
bgImage.setSize(width, height);
}
}
}
static class ParticleData {
public boolean enabled = true;
}
public static void main (String[] args) {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
try {
UIManager.setLookAndFeel(info.getClassName());
} catch (Throwable ignored) {
}
break;
}
}
EventQueue.invokeLater(new Runnable() {
public void run () {
new ParticleEditor();
}
});
}
}