Java Code Examples for com.watabou.noosa.Game#dispHeight()

The following examples show how to use com.watabou.noosa.Game#dispHeight() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InputHandler.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public synchronized boolean touchDown(int screenX, int screenY, int pointer, int button) {
	screenX /= (Game.dispWidth / (float)Game.width);
	screenY /= (Game.dispHeight / (float)Game.height);
	PointerEvent.addPointerEvent(new PointerEvent(screenX, screenY, pointer, true));
	return true;
}
 
Example 2
Source File: InputHandler.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public synchronized boolean touchUp(int screenX, int screenY, int pointer, int button) {
	screenX /= (Game.dispWidth / (float)Game.width);
	screenY /= (Game.dispHeight / (float)Game.height);
	PointerEvent.addPointerEvent(new PointerEvent(screenX, screenY, pointer, false));
	return true;
}
 
Example 3
Source File: InputHandler.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public synchronized boolean touchDragged(int screenX, int screenY, int pointer) {
	screenX /= (Game.dispWidth / (float)Game.width);
	screenY /= (Game.dispHeight / (float)Game.height);
	PointerEvent.addPointerEvent(new PointerEvent(screenX, screenY, pointer, true));
	return true;
}
 
Example 4
Source File: InputHandler.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean mouseMoved(int screenX, int screenY) {
	screenX /= (Game.dispWidth / (float)Game.width);
	screenY /= (Game.dispHeight / (float)Game.height);
	pointerHoverPos.x = screenX;
	pointerHoverPos.y = screenY;
	return true;
}
 
Example 5
Source File: AndroidPlatformSupport.java    From shattered-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
public void updateDisplaySize(){
	if (SPDSettings.landscape() != null) {
		AndroidGame.instance.setRequestedOrientation( SPDSettings.landscape() ?
				ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE :
				ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT );
	}
	
	if (AndroidGame.view.getMeasuredWidth() == 0 || AndroidGame.view.getMeasuredHeight() == 0)
		return;
	
	Game.dispWidth = AndroidGame.view.getMeasuredWidth();
	Game.dispHeight = AndroidGame.view.getMeasuredHeight();

	boolean fullscreen = Build.VERSION.SDK_INT < Build.VERSION_CODES.N
			|| !AndroidGame.instance.isInMultiWindowMode();

	if (fullscreen && SPDSettings.landscape() != null
			&& (Game.dispWidth >= Game.dispHeight) != SPDSettings.landscape()){
		int tmp = Game.dispWidth;
		Game.dispWidth = Game.dispHeight;
		Game.dispHeight = tmp;
	}
	
	float dispRatio = Game.dispWidth / (float)Game.dispHeight;
	
	float renderWidth = dispRatio > 1 ? PixelScene.MIN_WIDTH_L : PixelScene.MIN_WIDTH_P;
	float renderHeight = dispRatio > 1 ? PixelScene.MIN_HEIGHT_L : PixelScene.MIN_HEIGHT_P;
	
	//force power saver in this case as all devices must run at at least 2x scale.
	if (Game.dispWidth < renderWidth*2 || Game.dispHeight < renderHeight*2)
		SPDSettings.put( SPDSettings.KEY_POWER_SAVER, true );
	
	if (SPDSettings.powerSaver() && fullscreen){
		
		int maxZoom = (int)Math.min(Game.dispWidth/renderWidth, Game.dispHeight/renderHeight);
		
		renderWidth *= Math.max( 2, Math.round(1f + maxZoom*0.4f));
		renderHeight *= Math.max( 2, Math.round(1f + maxZoom*0.4f));
		
		if (dispRatio > renderWidth / renderHeight){
			renderWidth = renderHeight * dispRatio;
		} else {
			renderHeight = renderWidth / dispRatio;
		}
		
		final int finalW = Math.round(renderWidth);
		final int finalH = Math.round(renderHeight);
		if (finalW != Game.width || finalH != Game.height){
			
			AndroidGame.instance.runOnUiThread(new Runnable() {
				@Override
				public void run() {
					AndroidGame.view.getHolder().setFixedSize(finalW, finalH);
				}
			});
			
		}
	} else {
		AndroidGame.instance.runOnUiThread(new Runnable() {
			@Override
			public void run() {
				AndroidGame.view.getHolder().setSizeFromLayout();
			}
		});
	}
}