diff --git a/engine/src/android/com/jme3/app/AndroidHarness.java b/engine/src/android/com/jme3/app/AndroidHarness.java index c4f393c8a..021562375 100644 --- a/engine/src/android/com/jme3/app/AndroidHarness.java +++ b/engine/src/android/com/jme3/app/AndroidHarness.java @@ -8,6 +8,7 @@ import android.content.DialogInterface; import android.content.pm.ActivityInfo; import android.opengl.GLSurfaceView; import android.os.Bundle; +import android.view.Display; import android.view.SurfaceView; import android.view.View; import android.view.Window; @@ -56,7 +57,17 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt */ protected boolean eglConfigVerboseLogging = false; - protected boolean mouseEventsEnabled = true; + /** + * If true MouseEvents are generated from TouchEvents + */ + protected boolean mouseEventsEnabled = true; + /** + * Flip X axis + */ + protected boolean mouseEventsInvertX = true; + /** + * Flip Y axis + */ protected boolean mouseEventsInvertY = true; /** @@ -101,13 +112,16 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt WindowManager.LayoutParams.FLAG_FULLSCREEN); setRequestedOrientation(screenOrientation); - - AppSettings settings = new AppSettings(true); - AndroidInput input = new AndroidInput(this); + // Create Settings + AppSettings settings = new AppSettings(true); + + // Create the input class + AndroidInput input = new AndroidInput(this); + input.setMouseEventsInvertX(mouseEventsInvertX); input.setMouseEventsInvertY(mouseEventsInvertY); input.setMouseEventsEnabled(mouseEventsEnabled); - + // Create application instance try { @@ -122,13 +136,24 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt app.start(); ctx = (OGLESContext) app.getContext(); view = ctx.createView(input, eglConfigType, eglConfigVerboseLogging); - setContentView(view); + setContentView(view); + + // Set the screen reolution + WindowManager wind = this.getWindowManager(); + Display disp = wind.getDefaultDisplay(); + ctx.getSettings().setResolution(disp.getWidth(), disp.getHeight()); + + AppSettings s = ctx.getSettings(); + logger.info("Settings: Width " + s.getWidth() + " Height " + s.getHeight()); + + } catch (Exception ex) { handleError("Class " + appClass + " init failed", ex); setContentView(new TextView(this)); } + } diff --git a/engine/src/android/com/jme3/input/android/AndroidInput.java b/engine/src/android/com/jme3/input/android/AndroidInput.java index a467bd086..790e40339 100644 --- a/engine/src/android/com/jme3/input/android/AndroidInput.java +++ b/engine/src/android/com/jme3/input/android/AndroidInput.java @@ -32,7 +32,8 @@ public class AndroidInput extends GLSurfaceView implements TouchInput, // Custom settings public boolean mouseEventsEnabled = true; - public boolean mouseEventsInvertY = false; + public boolean mouseEventsInvertX = false; + public boolean mouseEventsInvertY = false; public boolean keyboardEventsEnabled = false; @@ -521,7 +522,11 @@ public class AndroidInput extends GLSurfaceView implements TouchInput, if (mouseEventsEnabled) { - newX = this.getWidth() - (int) event.getX(); + if (mouseEventsInvertX) + newX = this.getWidth() - (int) event.getX(); + else + newX = (int) event.getX(); + if (mouseEventsInvertY) newY = this.getHeight() - (int) event.getY(); else @@ -565,7 +570,9 @@ public class AndroidInput extends GLSurfaceView implements TouchInput, lastX = newX; lastY = newY; break; - } + } + + } } @@ -737,5 +744,12 @@ public class AndroidInput extends GLSurfaceView implements TouchInput, this.mouseEventsInvertY = mouseEventsInvertY; } + public boolean isMouseEventsInvertX() { + return mouseEventsInvertX; + } + + public void setMouseEventsInvertX(boolean mouseEventsInvertX) { + this.mouseEventsInvertX = mouseEventsInvertX; + } } diff --git a/engine/src/android/com/jme3/system/android/OGLESContext.java b/engine/src/android/com/jme3/system/android/OGLESContext.java index bedc9e634..aee6b3d37 100644 --- a/engine/src/android/com/jme3/system/android/OGLESContext.java +++ b/engine/src/android/com/jme3/system/android/OGLESContext.java @@ -179,9 +179,33 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer return view; } - + // renderer:initialize + @Override + public void onSurfaceCreated(GL10 gl, EGLConfig cfg) + { + + if (created.get() && renderer != null) + { + renderer.resetGLObjects(); + } + else + { + if (!created.get()) + { + logger.info("GL Surface created"); + initInThread(); + } + else + { + logger.warning("GL Surface already created"); + } + } + } + protected void initInThread() { + created.set(true); + logger.info("OGLESContext create"); logger.info("Running on thread: "+Thread.currentThread().getName()); @@ -230,9 +254,9 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer app.getInputManager().addListener((AndroidHarness)ctx, new String[]{ESCAPE_EVENT}); } } - - created.set(true); + needClose.set(false); + renderable.set(true); } /** @@ -242,7 +266,7 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer { if (renderable.get()) { - renderable.set(false); + created.set(false); if (renderer != null) renderer.cleanup(); @@ -253,9 +277,9 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer timer = null; // do android specific cleaning here - logger.info("Display destroyed."); - - created.set(false); + logger.info("Display destroyed."); + + renderable.set(false); } } @@ -267,10 +291,11 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer renderer.setVerboseLogging(settings.getBoolean("VERBOSE_LOGGING")); } - protected void applySettings(AppSettings setting) + protected void applySettings(AppSettings settings) { + setSettings(settings); if (renderer != null) - applySettingsToRenderer(renderer, settings); + applySettingsToRenderer(renderer, this.settings); } @Override @@ -336,22 +361,7 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer this.autoFlush = enabled; } - // renderer:initialize - @Override - public void onSurfaceCreated(GL10 gl, EGLConfig cfg) - { - - if (created.get() && renderer != null) - { - renderer.resetGLObjects(); - } - else - { - logger.info("GL Surface created"); - initInThread(); - renderable.set(true); - } - } + // SystemListener:reshape @Override @@ -447,7 +457,7 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer protected void waitFor(boolean createdVal) { - while (created.get() != createdVal){ + while (renderable.get() != createdVal){ try { Thread.sleep(10); } catch (InterruptedException ex) {