/** Returns the top gutter (black bar) height in screen coordinates. */ public int getTopGutterHeight () { return Gdx.graphics.getHeight() - (screenY + screenHeight); } }
@Override public boolean touchDown (int x, int y, int pointer, int button) { position.x = x; position.y = Gdx.graphics.getHeight() - y; return true; }
/** * Convers an y-coordinate given in backbuffer coordinates to * logical screen coordinates */ public static int toLogicalY(int backBufferY) { return (int)(backBufferY * Gdx.graphics.getHeight() / (float)Gdx.graphics.getBackBufferHeight()); }
/** * Convers an y-coordinate given in backbuffer coordinates to * logical screen coordinates */ public static int toBackBufferY(int logicalY) { return (int)(logicalY * Gdx.graphics.getBackBufferHeight() / (float)Gdx.graphics.getHeight()); } }
/** * Convers an y-coordinate given in backbuffer coordinates to * logical screen coordinates */ public static int toLogicalY(int backBufferY) { return (int)(backBufferY * Gdx.graphics.getHeight() / (float)Gdx.graphics.getBackBufferHeight()); }
/** * Convers an y-coordinate given in backbuffer coordinates to * logical screen coordinates */ public static int toBackBufferY(int logicalY) { return (int)(logicalY * Gdx.graphics.getBackBufferHeight() / (float)Gdx.graphics.getHeight()); } }
/** Function to translate a point given in screen coordinates to world space. It's the same as GLU gluUnProject but does not * rely on OpenGL. The viewport is assumed to span the whole screen and is fetched from {@link Graphics#getWidth()} and * {@link Graphics#getHeight()}. The x- and y-coordinate of vec are assumed to be in screen coordinates (origin is the top left * corner, y pointing down, x pointing to the right) as reported by the touch methods in {@link Input}. A z-coordinate of 0 * will return a point on the near plane, a z-coordinate of 1 will return a point on the far plane. * @param screenCoords the point in screen coordinates * @return the mutated and unprojected screenCoords {@link Vector3} */ public Vector3 unproject (Vector3 screenCoords) { unproject(screenCoords, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); return screenCoords; }
@Override public void resize (int width, int height) { float ratio = ((float)Gdx.graphics.getWidth() / (float)Gdx.graphics.getHeight()); int h = 10; int w = (int)(h * ratio); camera = new OrthographicCamera(w, h); } }
/** Sets this camera to an orthographic projection using a viewport fitting the screen resolution, centered at * (Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/2), with the y-axis pointing up or down. * @param yDown whether y should be pointing down */ public void setToOrtho (boolean yDown) { setToOrtho(yDown, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); }
@Override public boolean zoom (float initialDistance, float distance) { float newZoom = distance - initialDistance; float amount = newZoom - previousZoom; previousZoom = newZoom; float w = Gdx.graphics.getWidth(), h = Gdx.graphics.getHeight(); return controller.pinchZoom(amount / ((w > h) ? h : w)); }
/** Calculates a scissor rectangle using 0,0,Gdx.graphics.getWidth(),Gdx.graphics.getHeight() as the viewport. * @see #calculateScissors(Camera, float, float, float, float, Matrix4, Rectangle, Rectangle) */ public static void calculateScissors (Camera camera, Matrix4 batchTransform, Rectangle area, Rectangle scissor) { calculateScissors(camera, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), batchTransform, area, scissor); }
/** Creates a stage with the specified viewport and batch. This can be used to avoid creating a new batch (which can be * somewhat slow) if multiple stages are used during an application's life time. * @param batch Will not be disposed if {@link #dispose()} is called, handle disposal yourself. */ public Stage (Viewport viewport, Batch batch) { if (viewport == null) throw new IllegalArgumentException("viewport cannot be null."); if (batch == null) throw new IllegalArgumentException("batch cannot be null."); this.viewport = viewport; this.batch = batch; root = new Group(); root.setStage(this); viewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true); }
@Override public boolean touchDragged (int screenX, int screenY, int pointer) { boolean result = super.touchDragged(screenX, screenY, pointer); if (result || this.button < 0) return result; final float deltaX = (screenX - startX) / Gdx.graphics.getWidth(); final float deltaY = (startY - screenY) / Gdx.graphics.getHeight(); startX = screenX; startY = screenY; return process(deltaX, deltaY, button); }
/** Transforms a point to real screen coordinates (as opposed to OpenGL ES window coordinates), where the origin is in the top * left and the the y-axis is pointing downwards. */ public Vector2 toScreenCoordinates (Vector2 worldCoords, Matrix4 transformMatrix) { tmp.set(worldCoords.x, worldCoords.y, 0); tmp.mul(transformMatrix); camera.project(tmp); tmp.y = Gdx.graphics.getHeight() - tmp.y; worldCoords.x = tmp.x; worldCoords.y = tmp.y; return worldCoords; }
/** Transforms a point to real screen coordinates (as opposed to OpenGL ES window coordinates), where the origin is in the top * left and the the y-axis is pointing downwards. */ public Vector2 toScreenCoordinates (Vector2 worldCoords, Matrix4 transformMatrix) { tmp.set(worldCoords.x, worldCoords.y, 0); tmp.mul(transformMatrix); camera.project(tmp); tmp.y = Gdx.graphics.getHeight() - tmp.y; worldCoords.x = tmp.x; worldCoords.y = tmp.y; return worldCoords; }
@Override public void render () { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.begin(); font.draw(batch, message, 20, Gdx.graphics.getHeight() - 20); batch.end(); }
@Override public void render () { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.begin(); font.draw(batch, message, 20, Gdx.graphics.getHeight() - 20); batch.end(); }
public ShapeRenderer (int maxVertices, ShaderProgram defaultShader) { if (defaultShader == null) { renderer = new ImmediateModeRenderer20(maxVertices, false, true, 0); } else { renderer = new ImmediateModeRenderer20(maxVertices, false, true, 0, defaultShader); } projectionMatrix.setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); matrixDirty = true; }
public ShapeRenderer (int maxVertices, ShaderProgram defaultShader) { if (defaultShader == null) { renderer = new ImmediateModeRenderer20(maxVertices, false, true, 0); } else { renderer = new ImmediateModeRenderer20(maxVertices, false, true, 0, defaultShader); } projectionMatrix.setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); matrixDirty = true; }
@Override public void render () { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.begin(); batch.draw(texture, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); batch.end(); Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); int color = pixmap.getPixel(0, pixmap.getHeight() - 1); Gdx.app.log("AlphaTest", Integer.toHexString(color)); pixmap.dispose(); }