[fixed] Group.toChildCoordinates() had a sever bug in one of the branches. Thanks Jason!
[added] PixelsPerInch test.
\r
package com.badlogic.gdx.backends.android;\r
\r
+import java.io.InputStream;\r
+\r
+import javax.microedition.khronos.egl.EGL10;\r
+import javax.microedition.khronos.egl.EGLConfig;\r
+import javax.microedition.khronos.egl.EGLContext;\r
+import javax.microedition.khronos.egl.EGLDisplay;\r
+\r
import android.app.Activity;\r
import android.graphics.Bitmap;\r
import android.graphics.BitmapFactory;\r
import android.opengl.GLSurfaceView.Renderer;\r
+import android.util.DisplayMetrics;\r
import android.view.Display;\r
import android.view.View;\r
+\r
import com.badlogic.gdx.Gdx;\r
import com.badlogic.gdx.Graphics;\r
import com.badlogic.gdx.backends.android.surfaceview.GLSurfaceView20;\r
import com.badlogic.gdx.backends.android.surfaceview.GLSurfaceViewCupcake;\r
import com.badlogic.gdx.files.FileHandle;\r
-import com.badlogic.gdx.graphics.*;\r
+import com.badlogic.gdx.graphics.GL10;\r
+import com.badlogic.gdx.graphics.GL11;\r
+import com.badlogic.gdx.graphics.GL20;\r
+import com.badlogic.gdx.graphics.GLCommon;\r
+import com.badlogic.gdx.graphics.Mesh;\r
+import com.badlogic.gdx.graphics.Pixmap;\r
import com.badlogic.gdx.graphics.Pixmap.Format;\r
+import com.badlogic.gdx.graphics.Texture;\r
import com.badlogic.gdx.graphics.Texture.TextureFilter;\r
import com.badlogic.gdx.graphics.Texture.TextureWrap;\r
+import com.badlogic.gdx.graphics.TextureData;\r
import com.badlogic.gdx.graphics.glutils.FrameBuffer;\r
import com.badlogic.gdx.graphics.glutils.ShaderProgram;\r
import com.badlogic.gdx.math.WindowedMean;\r
import com.badlogic.gdx.utils.GdxRuntimeException;\r
\r
-import javax.microedition.khronos.egl.EGL10;\r
-import javax.microedition.khronos.egl.EGLConfig;\r
-import javax.microedition.khronos.egl.EGLContext;\r
-import javax.microedition.khronos.egl.EGLDisplay;\r
-import java.io.InputStream;\r
-\r
/**\r
* An implementation of {@link Graphics} for Android.\r
* \r
boolean running = false;\r
boolean pause = false;\r
boolean resume = false;\r
- boolean destroy = false; \r
+ boolean destroy = false;\r
+ \r
+ private float ppiX = 0;\r
+ private float ppiY = 0;\r
+ private float ppcX = 0;\r
+ private float ppcY = 0;\r
\r
public AndroidGraphics (AndroidApplication activity, boolean useGL2IfAvailable) {\r
view = createGLSurfaceView(activity, useGL2IfAvailable);\r
- this.app = activity;\r
+ this.app = activity; \r
}\r
\r
private View createGLSurfaceView (Activity activity, boolean useGL2) {\r
\r
}\r
\r
+ private void updatePpi() {\r
+ DisplayMetrics metrics = new DisplayMetrics();\r
+ app.getWindowManager().getDefaultDisplay().getMetrics(metrics);\r
+ \r
+ ppiX = metrics.xdpi;\r
+ ppiY = metrics.ydpi;\r
+ ppcX = metrics.xdpi / 2.54f;\r
+ ppcY = metrics.ydpi / 2.54f;\r
+ }\r
+ \r
private boolean checkGL20 () {\r
EGL10 egl = (EGL10)EGLContext.getEGL();\r
EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);\r
@Override public void onSurfaceChanged (javax.microedition.khronos.opengles.GL10 gl, int width, int height) {\r
this.width = width;\r
this.height = height; \r
- app.listener.resize(width, height);\r
+ updatePpi();\r
+ app.listener.resize(width, height); \r
}\r
\r
@Override public void onSurfaceCreated (javax.microedition.khronos.opengles.GL10 gl, EGLConfig config) {\r
setupGL(gl);\r
-\r
+ \r
+ updatePpi();\r
+ \r
Mesh.invalidateAllMeshes();\r
AndroidTexture.invalidateAllTextures();\r
ShaderProgram.invalidateAllShaderPrograms();\r
@Override public GLCommon getGLCommon () {\r
return gl;\r
}\r
+\r
+ @Override\r
+ public float getPpiX() {\r
+ return ppiX;\r
+ }\r
+\r
+ @Override\r
+ public float getPpiY() {\r
+ return ppiY;\r
+ }\r
+\r
+ @Override\r
+ public float getPpcX() {\r
+ return ppcX;\r
+ }\r
+\r
+ @Override\r
+ public float getPpcY() {\r
+ return ppcY;\r
+ }\r
}\r
package com.badlogic.gdx.backends.jogl;\r
\r
-import java.nio.ByteBuffer;\r
+import java.awt.Toolkit;\r
\r
import javax.media.opengl.GLAutoDrawable;\r
import javax.media.opengl.GLEventListener;\r
import com.badlogic.gdx.ApplicationListener;\r
import com.badlogic.gdx.Gdx;\r
import com.badlogic.gdx.Graphics;\r
-import com.badlogic.gdx.graphics.Pixmap.Format;\r
-import com.badlogic.gdx.graphics.Texture;\r
-import com.badlogic.gdx.graphics.Texture.TextureFilter;\r
-import com.badlogic.gdx.graphics.Texture.TextureWrap;\r
import com.badlogic.gdx.utils.GdxRuntimeException;\r
\r
/**\r
canvas.getContext().makeCurrent();\r
listener.dispose();\r
}\r
+\r
+ @Override\r
+ public float getPpiX() {\r
+ return Toolkit.getDefaultToolkit().getScreenResolution();\r
+ }\r
+\r
+ @Override\r
+ public float getPpiY() {\r
+ return Toolkit.getDefaultToolkit().getScreenResolution();\r
+ }\r
+\r
+ @Override\r
+ public float getPpcX() {\r
+ return (Toolkit.getDefaultToolkit().getScreenResolution() / 2.54f);\r
+ }\r
+\r
+ @Override\r
+ public float getPpcY() {\r
+ return (Toolkit.getDefaultToolkit().getScreenResolution() / 2.54f);\r
+ }\r
}\r
package com.badlogic.gdx.backends.lwjgl;\r
\r
import java.awt.Canvas;\r
+import java.awt.Toolkit;\r
import java.awt.image.BufferedImage;\r
import java.io.InputStream;\r
import java.nio.ByteBuffer;\r
Gdx.gl11 = gl11;\r
Gdx.gl20 = gl20;\r
}\r
+\r
+ @Override\r
+ public float getPpiX() {\r
+ return Toolkit.getDefaultToolkit().getScreenResolution();\r
+ }\r
+\r
+ @Override\r
+ public float getPpiY() {\r
+ return Toolkit.getDefaultToolkit().getScreenResolution();\r
+ }\r
+\r
+ @Override\r
+ public float getPpcX() {\r
+ return (Toolkit.getDefaultToolkit().getScreenResolution() / 2.54f);\r
+ }\r
+\r
+ @Override\r
+ public float getPpcY() {\r
+ return (Toolkit.getDefaultToolkit().getScreenResolution() / 2.54f);\r
+ }\r
}\r
* @return the {@link GraphicsType} of this Graphics instance\r
*/\r
public GraphicsType getType ();\r
+ \r
+ /**\r
+ * @return the pixels per inch on the x-axis\r
+ */\r
+ public float getPpiX();\r
+ \r
+ /**\r
+ * @return the pixels per inch on the y-axis\r
+ */\r
+ public float getPpiY();\r
+ \r
+ /**\r
+ * @return the pixels per centimeter on the x-axis\r
+ */\r
+ public float getPpcX();\r
+ \r
+ /** \r
+ * @return the pixels per centimeter on the y-axis.\r
+ */\r
+ public float getPpcY();\r
}\r
out.y = (y - child.y) / child.scaleY;\r
} else {\r
out.x = x / child.scaleX - (child.x - child.originX);\r
- out.x = x / child.scaleX - (child.x - child.originX);\r
+ out.y = x / child.scaleY - (child.y - child.originY);\r
}\r
}\r
} else {\r
--- /dev/null
+package com.badlogic.gdx.tests;\r
+\r
+import com.badlogic.gdx.Gdx;\r
+import com.badlogic.gdx.Files.FileType;\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.graphics.SpriteBatch;\r
+import com.badlogic.gdx.graphics.Texture;\r
+import com.badlogic.gdx.graphics.Texture.TextureFilter;\r
+import com.badlogic.gdx.graphics.Texture.TextureWrap;\r
+import com.badlogic.gdx.tests.utils.GdxTest;\r
+\r
+public class PixelsPerInchTest extends GdxTest {\r
+\r
+ BitmapFont font;\r
+ SpriteBatch batch;\r
+ Texture texture;\r
+ \r
+ @Override\r
+ public void create() {\r
+ font = new BitmapFont();\r
+ batch = new SpriteBatch();\r
+ texture = Gdx.graphics.newTexture(Gdx.files.getFileHandle("data/ui.png", FileType.Internal), \r
+ TextureFilter.Linear, TextureFilter.Linear, \r
+ TextureWrap.ClampToEdge, TextureWrap.ClampToEdge);\r
+ }\r
+ \r
+ public void render() {\r
+ Gdx.gl10.glClear(GL10.GL_COLOR_BUFFER_BIT);\r
+ \r
+ batch.begin();\r
+ float width = (int)(Gdx.graphics.getPpcX() * 2);\r
+ float height = (int)(Gdx.graphics.getPpcY() * 1);\r
+ batch.draw(texture, 10, 100, width, height, 0, 0, 64, 32, Color.WHITE, false, false );\r
+ font.draw(batch, "button is 2x1 cm (" + width + "x" + height + "px), ppi: (" + Gdx.graphics.getPpiX() + "," + Gdx.graphics.getPpiY() +"), ppc: (" + Gdx.graphics.getPpcX() + "," + Gdx.graphics.getPpcY()+ ")", 10, 50, Color.WHITE);\r
+ batch.end();\r
+ }\r
+ \r
+ @Override\r
+ public boolean needsGL20() {\r
+ return false;\r
+ }\r
+\r
+}\r
import com.badlogic.gdx.tests.MultitouchTest;\r
import com.badlogic.gdx.tests.ObjTest;\r
import com.badlogic.gdx.tests.ParticleEmitterTest;\r
+import com.badlogic.gdx.tests.PixelsPerInchTest;\r
import com.badlogic.gdx.tests.Pong;\r
import com.badlogic.gdx.tests.SimpleTest;\r
import com.badlogic.gdx.tests.SoundTest;\r
MultitouchTest.class,\r
ObjTest.class,\r
ParticleEmitterTest.class,\r
+ PixelsPerInchTest.class,\r
Pong.class,\r
SimpleTest.class,\r
SoundTest.class,\r