v0.3.1d: removed strict pixel align pt.1

there is no need to enforce whole interger positions for UI elements. Especially with the recent font changes this was causing alignment problems on high resolution displays.
Elements with non-whole number sizes and positions should be used sparingly, but there's no reason to strictly align them.
This commit is contained in:
Evan Debenham
2015-09-10 19:29:25 -04:00
parent 515473e409
commit 0ba004b1fa
12 changed files with 24 additions and 38 deletions
@@ -530,8 +530,8 @@ public class GameScene extends PixelScene {
private void showBanner( Banner banner ) {
banner.camera = uiCamera;
banner.x = align( uiCamera, (uiCamera.width - banner.width) / 2 );
banner.y = align( uiCamera, (uiCamera.height - banner.height) / 3 );
banner.x = (uiCamera.width - banner.width) / 2 ;
banner.y = (uiCamera.height - banner.height) / 3 ;
add( banner );
}
@@ -187,20 +187,10 @@ public class PixelScene extends Scene {
return result;
}
public static float align( Camera camera, float pos ) {
return ((int)(pos * camera.zoom)) / camera.zoom;
}
// This one should be used for UI elements
public static float align( float pos ) {
return ((int)(pos * defaultZoom)) / defaultZoom;
}
public static void align( Visual v ) {
Camera c = v.camera();
v.x = align( c, v.x );
v.y = align( c, v.y );
return pos;
}
public static boolean noFade = false;
@@ -219,8 +209,8 @@ public class PixelScene extends Scene {
public static void showBadge( Badges.Badge badge ) {
BadgeBanner banner = BadgeBanner.show( badge.image );
banner.camera = uiCamera;
banner.x = align( banner.camera, (banner.camera.width - banner.width) / 2 );
banner.y = align( banner.camera, (banner.camera.height - banner.height) / 3 );
banner.x = (banner.camera.width - banner.width) / 2 ;
banner.y = (banner.camera.height - banner.height) / 3 ;
Game.scene().add( banner );
}
@@ -280,8 +270,8 @@ public class PixelScene extends Scene {
@Override
protected void updateMatrix() {
float sx = align( this, scroll.x + shakeX );
float sy = align( this, scroll.y + shakeY );
float sx = scroll.x + shakeX;
float sy = scroll.y + shakeY;
matrix[0] = +zoom * invW2;
matrix[5] = -zoom * invH2;
@@ -68,7 +68,6 @@ public class AttackIndicator extends Tag {
if (sprite != null) {
sprite.x = x + (width - sprite.width()) / 2;
sprite.y = y + (height - sprite.height()) / 2;
PixelScene.align( sprite );
}
}
@@ -143,7 +142,6 @@ public class AttackIndicator extends Tag {
sprite.x = x + (width - sprite.width()) / 2 + 1;
sprite.y = y + (height - sprite.height()) / 2;
PixelScene.align( sprite );
} catch (Exception e) {
}
@@ -38,13 +38,13 @@ public class CheckBox extends RedButton {
float margin = (height - text.baseLine()) / 2;
text.x = PixelScene.align( PixelScene.uiCamera, x + margin );
text.y = PixelScene.align( PixelScene.uiCamera, y + margin );
text.x = x + margin;
text.y = y + margin;
margin = (height - icon.height) / 2;
icon.x = PixelScene.align( PixelScene.uiCamera, x + width - margin - icon.width );
icon.y = PixelScene.align( PixelScene.uiCamera, y + margin );
icon.x = x + width - margin - icon.width;
icon.y = y + margin;
}
public boolean checked() {
@@ -62,8 +62,8 @@ public class RedButton extends Button {
bg.y = y;
bg.size( width, height );
text.x = x + (int)(width - text.width()) / 2;
text.y = y + (int)(height - text.baseLine()) / 2;
text.x = x + (width - text.width()) / 2;
text.y = y + (height - text.baseLine()) / 2;
if (icon != null) {
icon.x = x + text.x - icon.width() - 2;
@@ -49,8 +49,8 @@ public class ResumeIndicator extends Tag {
protected void layout() {
super.layout();
icon.x = PixelScene.align( PixelScene.uiCamera, x+1 + (width - icon.width) / 2 );
icon.y = PixelScene.align( PixelScene.uiCamera, y + (height - icon.height) / 2 );
icon.x = x+1 + (width - icon.width) / 2;
icon.y = y + (height - icon.height) / 2;
}
@Override
@@ -132,8 +132,8 @@ public class StatusPane extends Component {
shield.size( width, shield.height );
avatar.x = PixelScene.align( camera(), shield.x + 15 - avatar.width / 2 );
avatar.y = PixelScene.align( camera(), shield.y + 16 - avatar.height / 2 );
avatar.x = shield.x + 15 - avatar.width / 2;
avatar.y = shield.y + 16 - avatar.height / 2;
compass.x = avatar.x + avatar.width / 2 - compass.origin.x;
compass.y = avatar.y + avatar.height / 2 - compass.origin.y;
@@ -75,7 +75,6 @@ public class Toast extends Component {
text.x = close.left() - MARGIN_HOR - text.width();
text.y = y + (height - text.height()) / 2;
PixelScene.align( text );
}
public void text( String txt ) {
@@ -81,13 +81,12 @@ public class IconTitle extends Component {
imIcon.x = x;
imIcon.y = y;
tfLabel.x = PixelScene.align( PixelScene.uiCamera, imIcon.x + imIcon.width() + GAP );
tfLabel.x = imIcon.x + imIcon.width() + GAP;
tfLabel.maxWidth = (int)(width - tfLabel.x);
tfLabel.measure();
tfLabel.y = PixelScene.align( PixelScene.uiCamera,
imIcon.height > tfLabel.height() ?
tfLabel.y = imIcon.height > tfLabel.height() ?
imIcon.y + (imIcon.height() - tfLabel.baseLine()) / 2 :
imIcon.y );
imIcon.y;
if (health.visible) {
health.setRect( tfLabel.x, Math.max( tfLabel.y + tfLabel.height(), imIcon.y + imIcon.height() - health.height() ), tfLabel.maxWidth, 0 );
@@ -117,7 +117,7 @@ public class WndCatalogus extends WndTabbed {
txtTitle.text( Utils.format( TXT_TITLE, showPotions ? TXT_POTIONS : TXT_SCROLLS ) );
txtTitle.measure();
txtTitle.x = PixelScene.align( PixelScene.uiCamera, (width - txtTitle.width()) / 2 );
txtTitle.x = (width - txtTitle.width()) / 2;
items.clear();
@@ -50,8 +50,8 @@ public class WndChallenges extends Window {
BitmapText title = PixelScene.createText( TITLE, 9 );
title.hardlight( TITLE_COLOR );
title.measure();
title.x = PixelScene.align( camera, (WIDTH - title.width()) / 2 );
title.y = PixelScene.align( camera, (TTL_HEIGHT - title.height()) / 2 );
title.x = (WIDTH - title.width()) / 2;
title.y = (TTL_HEIGHT - title.height()) / 2;
add( title );
boxes = new ArrayList<CheckBox>();
@@ -54,7 +54,7 @@ public class WndJournal extends Window {
txtTitle = PixelScene.createText( TXT_TITLE, 9 );
txtTitle.hardlight( Window.TITLE_COLOR );
txtTitle.measure();
txtTitle.x = PixelScene.align( PixelScene.uiCamera, (WIDTH - txtTitle.width()) / 2 );
txtTitle.x = (WIDTH - txtTitle.width()) / 2;
add( txtTitle );
Component content = new Component();