+\r
package com.badlogic.gdx.backends.desktop;\r
\r
import java.awt.Canvas;\r
import java.awt.Dimension;\r
-import java.lang.reflect.InvocationTargetException;\r
+import java.awt.EventQueue;\r
+import java.util.Timer;\r
+import java.util.TimerTask;\r
\r
import javax.swing.SwingUtilities;\r
\r
import com.badlogic.gdx.ApplicationListener;\r
import com.badlogic.gdx.Audio;\r
import com.badlogic.gdx.Files;\r
+import com.badlogic.gdx.Gdx;\r
import com.badlogic.gdx.Graphics;\r
import com.badlogic.gdx.Input;\r
import com.badlogic.gdx.utils.GdxRuntimeException;\r
Thread mainLoopThread;\r
boolean running = true;\r
Canvas canvas;\r
- \r
- public LwjglCanvas( ApplicationListener listener, boolean useGL2) {\r
+ Timer timer = new Timer("LwjglCanvas Timer");\r
+ Runnable updateRunnable;\r
+\r
+ public LwjglCanvas (ApplicationListener listener, boolean useGL2) {\r
LwjglNativesLoader.load();\r
- \r
- canvas = new Canvas() { \r
+\r
+ canvas = new Canvas() {\r
private final Dimension minSize = new Dimension();\r
\r
public final void addNotify () {\r
super.addNotify();\r
- try {\r
- graphics.setupDisplay();\r
- start();\r
- } catch (LWJGLException e) {\r
- throw new GdxRuntimeException(e);\r
- } \r
+ EventQueue.invokeLater(new Runnable() {\r
+ public void run () {\r
+ start();\r
+ }\r
+ });\r
}\r
\r
public Dimension getMinimumSize () {\r
return minSize;\r
- } \r
- }; \r
- \r
+ }\r
+ };\r
+\r
canvas.setSize(100, 100);\r
- canvas.setMinimumSize(new Dimension(2,2));\r
- graphics = new LwjglGraphics( canvas, useGL2);\r
+ canvas.setMinimumSize(new Dimension(2, 2));\r
+ graphics = new LwjglGraphics(canvas, useGL2);\r
audio = new LwjglAudio();\r
files = new LwjglFiles();\r
input = new LwjglInput();\r
this.listener = listener;\r
+\r
+ Gdx.app = this;\r
+ Gdx.graphics = graphics;\r
+ Gdx.audio = audio;\r
+ Gdx.files = files;\r
+ Gdx.input = input;\r
}\r
- \r
- public Canvas getCanvas() {\r
+\r
+ public Canvas getCanvas () {\r
return canvas;\r
}\r
\r
- @Override\r
- public Audio getAudio() { \r
+ @Override public Audio getAudio () {\r
return audio;\r
}\r
\r
- @Override\r
- public Files getFiles() {\r
+ @Override public Files getFiles () {\r
return files;\r
}\r
\r
- @Override\r
- public Graphics getGraphics() {\r
+ @Override public Graphics getGraphics () {\r
return graphics;\r
}\r
\r
- @Override\r
- public Input getInput() {\r
+ @Override public Input getInput () {\r
return input;\r
}\r
\r
- @Override\r
- public ApplicationType getType() {\r
+ @Override public ApplicationType getType () {\r
return ApplicationType.Desktop;\r
}\r
\r
- @Override\r
- public int getVersion() {\r
+ @Override public int getVersion () {\r
return 0;\r
}\r
\r
- @Override\r
- public void log(String tag, String message) {\r
- System.out.println( tag + ": " + message );\r
+ @Override public void log (String tag, String message) {\r
+ System.out.println(tag + ": " + message);\r
}\r
- \r
- private void start() {\r
- LwjglNativesLoader.load();\r
- mainLoopThread = new Thread("LWJGL Application") {\r
- @SuppressWarnings("synthetic-access")\r
- public void run () { \r
- LwjglCanvas.this.mainLoop(); \r
- }\r
- };\r
- mainLoopThread.start();\r
- }\r
- \r
- private void mainLoop( ) { \r
- Keyboard.enableRepeatEvents(true);\r
+\r
+ void start () {\r
try {\r
- SwingUtilities.invokeAndWait(new Runnable() {\r
- public void run() {\r
- listener.create();\r
- listener.resize(graphics.getWidth(), graphics.getHeight()); \r
- }\r
- });\r
- } catch (Exception e1) {\r
- throw new GdxRuntimeException(e1);\r
+ graphics.setupDisplay();\r
+ } catch (LWJGLException e) {\r
+ throw new GdxRuntimeException(e);\r
}\r
- \r
- Runnable runnable = new Runnable() {\r
+\r
+ Keyboard.enableRepeatEvents(true);\r
+\r
+ listener.create();\r
+ listener.resize(graphics.getWidth(), graphics.getHeight());\r
+\r
+ updateRunnable = new Runnable() {\r
int lastWidth = graphics.getWidth();\r
int lastHeight = graphics.getHeight();\r
- \r
- @Override\r
- public void run() {\r
+\r
+ public void run () {\r
graphics.updateTime();\r
input.update();\r
- \r
- if( lastWidth != graphics.getWidth() || lastHeight != graphics.getHeight() ) {\r
+\r
+ if (lastWidth != graphics.getWidth() || lastHeight != graphics.getHeight()) {\r
lastWidth = graphics.getWidth();\r
lastHeight = graphics.getHeight();\r
- try {\r
- Display.setDisplayMode(new DisplayMode(lastWidth, lastHeight));\r
- } catch (LWJGLException e) {\r
- throw new GdxRuntimeException(e);\r
- }\r
listener.resize(lastWidth, lastHeight);\r
}\r
- \r
+\r
listener.render();\r
input.processEvents(null);\r
Display.update();\r
- Display.sync(60); \r
+ Display.sync(60);\r
}\r
};\r
- \r
- while(running) {\r
- SwingUtilities.invokeLater(runnable); \r
- try {\r
- Thread.sleep(16);\r
- } catch (InterruptedException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
+\r
+ timer.schedule(new TimerTask() {\r
+ public void run () {\r
+ try {\r
+ EventQueue.invokeAndWait(updateRunnable);\r
+ } catch (Exception ex) {\r
+ throw new GdxRuntimeException(ex);\r
+ }\r
}\r
- }\r
- \r
+ }, 0, 16);\r
+ }\r
+\r
+ public void stop () {\r
+ running = false;\r
+ timer.cancel();\r
SwingUtilities.invokeLater(new Runnable() {\r
- public void run() {\r
+ public void run () {\r
listener.pause();\r
listener.destroy();\r
- Display.destroy(); \r
+ Display.destroy();\r
}\r
- }); \r
- }\r
-\r
- public void stop() {\r
- running = false;\r
- try {\r
- mainLoopThread.join();\r
- }\r
- catch(Exception ex) { \r
- }\r
+ });\r
}\r
}\r
+ "abcdefghijklmnopqrstuvwxyz\n1234567890\n" //\r
+ "\"!`?'.,;:()[]{}<>|/@\\^$-%+=#_&~*\u007F";\r
\r
- LwjglApplication app;\r
- Canvas glCanvas;\r
volatile UnicodeFont newUnicodeFont;\r
UnicodeFont unicodeFont;\r
Color renderingBackgroundColor = Color.BLACK;\r
Splash splash = new Splash(this, "/splash.jpg", 2000);\r
initialize();\r
splash.close();\r
- \r
- LwjglCanvas lwjglCanvas = new LwjglCanvas(new Renderer(), false);\r
- gamePanel.add(lwjglCanvas.getCanvas());\r
+\r
+ gamePanel.add(new LwjglCanvas(new Renderer(), false).getCanvas());\r
\r
prefs = Preferences.userNodeForPackage(Hiero.class);\r
java.awt.Color backgroundColor = EffectUtil.fromString(prefs.get("background", "000000"));\r
class Renderer implements ApplicationListener {\r
private String sampleText;\r
\r
- public void created () {\r
+ @Override public void create () {\r
glEnable(GL_SCISSOR_TEST);\r
\r
glEnable(GL_TEXTURE_2D);\r
glEnable(GL_BLEND);\r
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);\r
}\r
- \r
\r
- @Override\r
- public void resize(int width, int height) { \r
+ @Override public void resize (int width, int height) {\r
glViewport(0, 0, width, height);\r
glScissor(0, 0, width, height);\r
\r
glLoadIdentity();\r
glOrtho(0, width, height, 0, 1, -1);\r
glMatrixMode(GL_MODELVIEW);\r
- glLoadIdentity(); \r
+ glLoadIdentity();\r
}\r
\r
public void render () {\r
- if (glCanvas == null) return;\r
int viewWidth = Gdx.graphics.getWidth();\r
int viewHeight = Gdx.graphics.getHeight();\r
- if (viewWidth != glCanvas.getWidth() || viewHeight != glCanvas.getHeight()) {\r
- viewWidth = Math.max(1, glCanvas.getWidth());\r
- viewHeight = Math.max(1, glCanvas.getHeight()); \r
- }\r
\r
if (newUnicodeFont != null) {\r
if (unicodeFont != null) unicodeFont.destroy();\r
}\r
}\r
\r
- public void dispose () {\r
+ @Override public void pause () {\r
}\r
\r
- @Override\r
- public void create() {\r
- // TODO Auto-generated method stub\r
- \r
+ @Override public void resume () {\r
}\r
-\r
- @Override\r
- public void destroy() {\r
- // TODO Auto-generated method stub\r
- \r
- }\r
-\r
- @Override\r
- public void pause() {\r
- // TODO Auto-generated method stub\r
- \r
- }\r
-\r
- @Override\r
- public void resume() {\r
- // TODO Auto-generated method stub\r
- \r
+ \r
+ @Override public void destroy () {\r
}\r
}\r
\r
public static void main (String[] args) throws Exception {\r
-// LookAndFeelInfo[] lookAndFeels = UIManager.getInstalledLookAndFeels();\r
-// for (int i = 0, n = lookAndFeels.length; i < n; i++) {\r
-// if ("Nimbus".equals(lookAndFeels[i].getName())) {\r
-// try {\r
-// UIManager.setLookAndFeel(lookAndFeels[i].getClassName());\r
-// } catch (Throwable ignored) {\r
-// }\r
-// break;\r
-// }\r
-// }\r
- SwingUtilities.invokeLater( new Runnable() {\r
- \r
- @Override\r
- public void run() {\r
- new Hiero(); \r
+// LookAndFeelInfo[] lookAndFeels = UIManager.getInstalledLookAndFeels();\r
+// for (int i = 0, n = lookAndFeels.length; i < n; i++) {\r
+// if ("Nimbus".equals(lookAndFeels[i].getName())) {\r
+// try {\r
+// UIManager.setLookAndFeel(lookAndFeels[i].getClassName());\r
+// } catch (Throwable ignored) {\r
+// }\r
+// break;\r
+// }\r
+// }\r
+ SwingUtilities.invokeLater(new Runnable() {\r
+\r
+ @Override public void run () {\r
+ new Hiero();\r
}\r
});\r
}\r
import com.badlogic.gdx.InputProcessor;\r
import com.badlogic.gdx.Files.FileType;\r
import com.badlogic.gdx.backends.desktop.LwjglApplication;\r
+import com.badlogic.gdx.backends.desktop.LwjglCanvas;\r
import com.badlogic.gdx.graphics.BitmapFont;\r
import com.badlogic.gdx.graphics.Color;\r
import com.badlogic.gdx.graphics.GL10;\r
import com.badlogic.gdx.utils.GdxRuntimeException;\r
\r
public class ParticleEditor extends JFrame {\r
- LwjglApplication app;\r
- Canvas glCanvas;\r
+ LwjglCanvas lwjglCanvas;\r
JPanel rowsPanel;\r
EffectPanel effectPanel;\r
private JSplitPane splitPane;\r
public ParticleEditor () {\r
super("GDX Particle Editor");\r
\r
- glCanvas = new Canvas() {\r
- private final Dimension minSize = new Dimension();\r
-\r
- public final void addNotify () {\r
- super.addNotify();\r
- app = new LwjglApplication(new Renderer(),"ParticleEditor", 200, 200, false, glCanvas); \r
- addWindowListener(new WindowAdapter() {\r
- public void windowClosed (WindowEvent event) {\r
- app.stop();\r
- }\r
- });\r
+ lwjglCanvas = new LwjglCanvas(new Renderer(), false);\r
+ addWindowListener(new WindowAdapter() {\r
+ public void windowClosed (WindowEvent event) {\r
+ System.exit(0);\r
+ // Gdx.app.quit();\r
}\r
-\r
- public Dimension getMinimumSize () {\r
- return minSize;\r
- }\r
- };\r
+ });\r
\r
initializeComponents();\r
\r
EventQueue.invokeLater(new Runnable() {\r
public void run () {\r
rowsPanel.removeAll();\r
- synchronized (effect) {\r
- ParticleEmitter emitter = getEmitter();\r
- addRow(new ImagePanel(ParticleEditor.this));\r
- addRow(new RangedNumericPanel("Delay", emitter.getDelay()));\r
- addRow(new RangedNumericPanel("Duration", emitter.getDuration()));\r
- addRow(new CountPanel(ParticleEditor.this));\r
- addRow(new ScaledNumericPanel("Emission", "Duration", emitter.getEmission()));\r
- addRow(new ScaledNumericPanel("Life", "Duration", emitter.getLife()));\r
- addRow(new ScaledNumericPanel("Life Offset", "Duration", emitter.getLifeOffset()));\r
- addRow(new RangedNumericPanel("X Offset", emitter.getXOffsetValue()));\r
- addRow(new RangedNumericPanel("Y Offset", emitter.getYOffsetValue()));\r
- addRow(new SpawnPanel(emitter.getSpawnShape(), ParticleEditor.this));\r
- addRow(new ScaledNumericPanel("Spawn Width", "Duration", emitter.getSpawnWidth()));\r
- addRow(new ScaledNumericPanel("Spawn Height", "Duration", emitter.getSpawnHeight()));\r
- addRow(new ScaledNumericPanel("Size", "Life", emitter.getScale()));\r
- addRow(new ScaledNumericPanel("Velocity", "Life", emitter.getVelocity()));\r
- addRow(new ScaledNumericPanel("Angle", "Life", emitter.getAngle()));\r
- addRow(new ScaledNumericPanel("Rotation", "Life", emitter.getRotation()));\r
- addRow(new ScaledNumericPanel("Wind", "Life", emitter.getWind()));\r
- addRow(new ScaledNumericPanel("Gravity", "Life", emitter.getGravity()));\r
- addRow(new GradientPanel("Tint", emitter.getTint()));\r
- addRow(new PercentagePanel("Transparency", "Life", emitter.getTransparency()));\r
- addRow(new OptionsPanel(ParticleEditor.this));\r
- for (Component component : rowsPanel.getComponents())\r
- if (component instanceof EditorPanel) ((EditorPanel)component).update(ParticleEditor.this);\r
- }\r
+ ParticleEmitter emitter = getEmitter();\r
+ addRow(new ImagePanel(ParticleEditor.this));\r
+ addRow(new RangedNumericPanel("Delay", emitter.getDelay()));\r
+ addRow(new RangedNumericPanel("Duration", emitter.getDuration()));\r
+ addRow(new CountPanel(ParticleEditor.this));\r
+ addRow(new ScaledNumericPanel("Emission", "Duration", emitter.getEmission()));\r
+ addRow(new ScaledNumericPanel("Life", "Duration", emitter.getLife()));\r
+ addRow(new ScaledNumericPanel("Life Offset", "Duration", emitter.getLifeOffset()));\r
+ addRow(new RangedNumericPanel("X Offset", emitter.getXOffsetValue()));\r
+ addRow(new RangedNumericPanel("Y Offset", emitter.getYOffsetValue()));\r
+ addRow(new SpawnPanel(emitter.getSpawnShape(), ParticleEditor.this));\r
+ addRow(new ScaledNumericPanel("Spawn Width", "Duration", emitter.getSpawnWidth()));\r
+ addRow(new ScaledNumericPanel("Spawn Height", "Duration", emitter.getSpawnHeight()));\r
+ addRow(new ScaledNumericPanel("Size", "Life", emitter.getScale()));\r
+ addRow(new ScaledNumericPanel("Velocity", "Life", emitter.getVelocity()));\r
+ addRow(new ScaledNumericPanel("Angle", "Life", emitter.getAngle()));\r
+ addRow(new ScaledNumericPanel("Rotation", "Life", emitter.getRotation()));\r
+ addRow(new ScaledNumericPanel("Wind", "Life", emitter.getWind()));\r
+ addRow(new ScaledNumericPanel("Gravity", "Life", emitter.getGravity()));\r
+ addRow(new GradientPanel("Tint", emitter.getTint()));\r
+ addRow(new PercentagePanel("Transparency", "Life", emitter.getTransparency()));\r
+ addRow(new OptionsPanel(ParticleEditor.this));\r
+ for (Component component : rowsPanel.getComponents())\r
+ if (component instanceof EditorPanel) ((EditorPanel)component).update(ParticleEditor.this);\r
rowsPanel.repaint();\r
}\r
});\r
{\r
JPanel spacer = new JPanel(new BorderLayout());\r
leftSplit.add(spacer, JSplitPane.TOP);\r
- spacer.add(glCanvas);\r
+ spacer.add(lwjglCanvas.getCanvas());\r
spacer.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 4));\r
}\r
{\r
effectPanel.newEmitter("Untitled", true);\r
// if (resources.openFile("/editor-bg.png") != null) bgImage = new Image(gl, "/editor-bg.png");\r
}\r
- \r
- @Override\r
- public void resize(int width, int height) {\r
+\r
+ @Override public void resize (int width, int height) {\r
Gdx.gl.glViewport(0, 0, width, height);\r
spriteBatch.getProjectionMatrix().setToOrtho(0, width, height, 0, 0, 1);\r
\r
- synchronized (effect) {\r
- effect.setPosition(width / 2, height / 2);\r
- } \r
+ effect.setPosition(width / 2, height / 2);\r
}\r
\r
public void render () {\r
- synchronized (effect) {\r
- int viewWidth = Gdx.graphics.getWidth();\r
- int viewHeight = Gdx.graphics.getHeight();\r
- if (viewWidth != glCanvas.getWidth() || viewHeight != glCanvas.getHeight()) {\r
- viewWidth = Math.max(1, glCanvas.getWidth());\r
- viewHeight = Math.max(1, glCanvas.getHeight()); \r
- }\r
+ int viewWidth = Gdx.graphics.getWidth();\r
+ int viewHeight = Gdx.graphics.getHeight();\r
\r
- float delta = Gdx.graphics.getDeltaTime();\r
+ float delta = Gdx.graphics.getDeltaTime();\r
\r
- Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);\r
+ Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);\r
\r
- spriteBatch.begin();\r
- spriteBatch.enableBlending();\r
- spriteBatch.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);\r
+ spriteBatch.begin();\r
+ spriteBatch.enableBlending();\r
+ spriteBatch.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);\r
\r
- if (bgImage != null) {\r
- bgImage.setPosition(viewWidth / 2 - bgImage.getWidth() / 2, viewHeight / 2 - bgImage.getHeight() / 2);\r
- bgImage.draw(spriteBatch);\r
- }\r
+ if (bgImage != null) {\r
+ bgImage.setPosition(viewWidth / 2 - bgImage.getWidth() / 2, viewHeight / 2 - bgImage.getHeight() / 2);\r
+ bgImage.draw(spriteBatch);\r
+ }\r
\r
- activeCount = 0;\r
- for (ParticleEmitter emitter : effect.getEmitters()) {\r
- if (emitter.getTexture() == null && emitter.getImagePath() != null) loadImage(emitter);\r
- boolean enabled = isEnabled(emitter);\r
- if (enabled) {\r
- if (emitter.getTexture() != null) emitter.draw(spriteBatch, delta);\r
- activeCount += emitter.getActiveCount();\r
- }\r
- }\r
- if (effect.isComplete()) effect.start();\r
-\r
- maxActive = Math.max(maxActive, activeCount);\r
- maxActiveTimer += delta;\r
- if (maxActiveTimer > 3) {\r
- maxActiveTimer = 0;\r
- lastMaxActive = maxActive;\r
- maxActive = 0;\r
+ activeCount = 0;\r
+ for (ParticleEmitter emitter : effect.getEmitters()) {\r
+ if (emitter.getTexture() == null && emitter.getImagePath() != null) loadImage(emitter);\r
+ boolean enabled = isEnabled(emitter);\r
+ if (enabled) {\r
+ if (emitter.getTexture() != null) emitter.draw(spriteBatch, delta);\r
+ activeCount += emitter.getActiveCount();\r
}\r
+ }\r
+ if (effect.isComplete()) effect.start();\r
+\r
+ maxActive = Math.max(maxActive, activeCount);\r
+ maxActiveTimer += delta;\r
+ if (maxActiveTimer > 3) {\r
+ maxActiveTimer = 0;\r
+ lastMaxActive = maxActive;\r
+ maxActive = 0;\r
+ }\r
\r
- if (mouseDown) {\r
- // gl.drawLine(mouseX - 6, mouseY, mouseX + 5, mouseY);\r
- // gl.drawLine(mouseX, mouseY - 5, mouseX, mouseY + 6);\r
- }\r
+ if (mouseDown) {\r
+ // gl.drawLine(mouseX - 6, mouseY, mouseX + 5, mouseY);\r
+ // gl.drawLine(mouseX, mouseY - 5, mouseX, mouseY + 6);\r
+ }\r
\r
- font.draw(spriteBatch, "FPS: " + Gdx.graphics.getFramesPerSecond(), 10, 10, Color.WHITE);\r
- font.draw(spriteBatch, "Count: " + activeCount, 10, 30, Color.WHITE);\r
- font.draw(spriteBatch, "Max: " + lastMaxActive, 10, 50, Color.WHITE);\r
- font.draw(spriteBatch, (int)(getEmitter().getPercentComplete() * 100) + "%", 10, 70, Color.WHITE);\r
+ font.draw(spriteBatch, "FPS: " + Gdx.graphics.getFramesPerSecond(), 10, 10, Color.WHITE);\r
+ font.draw(spriteBatch, "Count: " + activeCount, 10, 30, Color.WHITE);\r
+ font.draw(spriteBatch, "Max: " + lastMaxActive, 10, 50, Color.WHITE);\r
+ font.draw(spriteBatch, (int)(getEmitter().getPercentComplete() * 100) + "%", 10, 70, Color.WHITE);\r
\r
- spriteBatch.end();\r
+ spriteBatch.end();\r
\r
- // gl.drawLine((int)(viewWidth * getCurrentParticles().getPercentComplete()), viewHeight - 1, viewWidth, viewHeight -\r
+ // gl.drawLine((int)(viewWidth * getCurrentParticles().getPercentComplete()), viewHeight - 1, viewWidth, viewHeight -\r
// 1);\r
- Gdx.input.processEvents(this);\r
- }\r
+ Gdx.input.processEvents(this);\r
}\r
\r
private void loadImage (ParticleEmitter emitter) {\r
}\r
\r
public boolean touchDown (int x, int y, int pointer) {\r
- synchronized (effect) {\r
- effect.setPosition(x, y);\r
- }\r
+ effect.setPosition(x, y);\r
return false;\r
}\r
\r
}\r
\r
public boolean touchDragged (int x, int y, int pointer) {\r
- synchronized (effect) {\r
- effect.setPosition(x, y);\r
- }\r
+ effect.setPosition(x, y);\r
return false;\r
}\r
\r
public void dispose () {\r
}\r
\r
-\r
- @Override\r
- public void destroy() {\r
+ @Override public void destroy () {\r
// TODO Auto-generated method stub\r
- \r
+\r
}\r
\r
- @Override\r
- public void pause() {\r
+ @Override public void pause () {\r
// TODO Auto-generated method stub\r
- \r
+\r
}\r
\r
- @Override\r
- public void resume() {\r
+ @Override public void resume () {\r
// TODO Auto-generated method stub\r
- \r
+\r
}\r
}\r
\r