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

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 20:06:14 -04:00
parent 0ba004b1fa
commit 6313619de7
20 changed files with 80 additions and 85 deletions

View File

@ -92,7 +92,7 @@ public class FloatingText extends BitmapText {
hardlight( color );
measure();
this.x = PixelScene.align( x - width() / 2 );
this.x = x - width() / 2;
this.y = y - height();
timeLeft = LIFESPAN;

View File

@ -65,8 +65,8 @@ public class AboutScene extends PixelScene {
final float wataOffset = ShatteredPixelDungeon.landscape() ? colWidth : 0;
Image shpx = Icons.SHPX.get();
shpx.x = align( (colWidth - shpx.width()) / 2 );
shpx.y = align( colTop );
shpx.x = (colWidth - shpx.width()) / 2;
shpx.y = colTop;
add( shpx );
new Flare( 7, 64 ).color( 0x225511, true ).show( shpx, 0 ).angularSpeed = +20;
@ -77,16 +77,16 @@ public class AboutScene extends PixelScene {
shpxtitle.hardlight( Window.SHPX_COLOR );
add( shpxtitle );
shpxtitle.x = align( (colWidth - shpxtitle.width()) / 2 );
shpxtitle.y = align( shpx.y + shpx.height + 5 );
shpxtitle.x = (colWidth - shpxtitle.width()) / 2;
shpxtitle.y = shpx.y + shpx.height + 5;
BitmapTextMultiline shpxtext = createMultiline( TXT_SHPX, 8 );
shpxtext.maxWidth = shpxtitle.maxWidth;
shpxtext.measure();
add( shpxtext );
shpxtext.x = align( (colWidth - shpxtext.width()) / 2 );
shpxtext.y = align( shpxtitle.y + shpxtitle.height() + 12 );
shpxtext.x = (colWidth - shpxtext.width()) / 2;
shpxtext.y = shpxtitle.y + shpxtitle.height() + 12;
BitmapTextMultiline shpxlink = createMultiline( LNK_SHPX, 8 );
shpxlink.maxWidth = shpxtitle.maxWidth;
@ -107,10 +107,10 @@ public class AboutScene extends PixelScene {
add( shpxhotArea );
Image wata = Icons.WATA.get();
wata.x = align( wataOffset + (colWidth - wata.width()) / 2 );
wata.y = align( ShatteredPixelDungeon.landscape() ?
wata.x = wataOffset + (colWidth - wata.width()) / 2;
wata.y = ShatteredPixelDungeon.landscape() ?
colTop:
shpxlink.y + wata.height + 20);
shpxlink.y + wata.height + 20;
add( wata );
new Flare( 7, 64 ).color( 0x112233, true ).show( wata, 0 ).angularSpeed = +20;
@ -121,16 +121,16 @@ public class AboutScene extends PixelScene {
wataTitle.hardlight(Window.TITLE_COLOR);
add( wataTitle );
wataTitle.x = align( wataOffset + (colWidth - wataTitle.width()) / 2 );
wataTitle.y = align( wata.y + wata.height + 11 );
wataTitle.x = wataOffset + (colWidth - wataTitle.width()) / 2;
wataTitle.y = wata.y + wata.height + 11;
BitmapTextMultiline wataText = createMultiline( TXT_WATA, 8 );
wataText.maxWidth = wataTitle.maxWidth;
wataText.measure();
add( wataText );
wataText.x = align( wataOffset + (colWidth - wataText.width()) / 2 );
wataText.y = align( wataTitle.y + wataTitle.height() + 12 );
wataText.x = wataOffset + (colWidth - wataText.width()) / 2;
wataText.y = wataTitle.y + wataTitle.height() + 12;
BitmapTextMultiline wataLink = createMultiline( LNK_WATA, 8 );
wataLink.maxWidth = wataTitle.maxWidth;

View File

@ -91,8 +91,8 @@ public class AmuletScene extends PixelScene {
if (noText) {
height = amulet.height + LARGE_GAP + btnExit.height() + SMALL_GAP + btnStay.height();
amulet.x = align( (Camera.main.width - amulet.width) / 2 );
amulet.y = align( (Camera.main.height - height) / 2 );
amulet.x = (Camera.main.width - amulet.width) / 2;
amulet.y = (Camera.main.height - height) / 2;
btnExit.setPos( (Camera.main.width - btnExit.width()) / 2, amulet.y + amulet.height + LARGE_GAP );
btnStay.setPos( btnExit.left(), btnExit.bottom() + SMALL_GAP );
@ -100,10 +100,10 @@ public class AmuletScene extends PixelScene {
} else {
height = amulet.height + LARGE_GAP + text.height() + LARGE_GAP + btnExit.height() + SMALL_GAP + btnStay.height();
amulet.x = align( (Camera.main.width - amulet.width) / 2 );
amulet.y = align( (Camera.main.height - height) / 2 );
amulet.x = (Camera.main.width - amulet.width) / 2;
amulet.y = (Camera.main.height - height) / 2;
text.x = align( (Camera.main.width - text.width()) / 2 );
text.x = (Camera.main.width - text.width()) / 2;
text.y = amulet.y + amulet.height + LARGE_GAP;
btnExit.setPos( (Camera.main.width - btnExit.width()) / 2, text.y + text.height() + LARGE_GAP );

View File

@ -71,8 +71,8 @@ public class BadgesScene extends PixelScene {
BitmapText title = PixelScene.createText( TXT_TITLE, 9 );
title.hardlight( Window.TITLE_COLOR );
title.measure();
title.x = align( (w - title.width()) / 2 );
title.y = align( (panel.y - title.baseLine()) / 2 );
title.x = (w - title.width()) / 2;
title.y = (panel.y - title.baseLine()) / 2;
add( title );
Badges.loadGlobal();

View File

@ -188,11 +188,6 @@ public class PixelScene extends Scene {
return result;
}
// This one should be used for UI elements
public static float align( float pos ) {
return pos;
}
public static boolean noFade = false;
protected void fadeIn() {
if (noFade) {

View File

@ -79,8 +79,8 @@ public class RankingsScene extends PixelScene {
BitmapText title = PixelScene.createText(TXT_TITLE, 9);
title.hardlight(Window.SHPX_COLOR);
title.measure();
title.x = align((w - title.width()) / 2);
title.y = align( GAP );
title.x = (w - title.width()) / 2;
title.y = GAP;
add(title);
if (Rankings.INSTANCE.records.size() > 0) {
@ -89,7 +89,7 @@ public class RankingsScene extends PixelScene {
float rowHeight = GameMath.gate(ROW_HEIGHT_MIN, (uiCamera.height - 26)/Rankings.INSTANCE.records.size(), ROW_HEIGHT_MAX);
float left = (w - Math.min( MAX_ROW_WIDTH, w )) / 2 + GAP;
float top = align( (h - rowHeight * Rankings.INSTANCE.records.size()) / 2 );
float top = (h - rowHeight * Rankings.INSTANCE.records.size()) / 2;
int pos = 0;
@ -121,15 +121,15 @@ public class RankingsScene extends PixelScene {
BitmapText total = PixelScene.createText( "/" + Rankings.INSTANCE.totalNumber, 8 );
total.hardlight( 0xCCCCCC );
total.measure();
total.x = align( (w - total.width()) / 2 );
total.y = align( top + pos * rowHeight + GAP );
total.x = (w - total.width()) / 2;
total.y = top + pos * rowHeight + GAP;
add( total );
float tw = label.width() + won.width() + total.width();
label.x = align( (w - tw) / 2 );
label.x = (w - tw) / 2;
won.x = label.x + label.width();
total.x = won.x + won.width();
label.y = won.y = total.y = align( h - label.height() - GAP );
label.y = won.y = total.y = h - label.height() - GAP;
}
@ -138,8 +138,8 @@ public class RankingsScene extends PixelScene {
BitmapText noRec = PixelScene.createText(TXT_NO_GAMES, 8);
noRec.hardlight( 0xCCCCCC );
noRec.measure();
noRec.x = align((w - noRec.width()) / 2);
noRec.y = align((h - noRec.height()) / 2);
noRec.x = (w - noRec.width()) / 2;
noRec.y = (h - noRec.height()) / 2;
add(noRec);
}
@ -267,29 +267,29 @@ public class RankingsScene extends PixelScene {
shield.x = x;
shield.y = y + (height - shield.height) / 2;
position.x = align( shield.x + (shield.width - position.width()) / 2 );
position.y = align( shield.y + (shield.height - position.height()) / 2 + 1 );
position.x = shield.x + (shield.width - position.width()) / 2;
position.y = shield.y + (shield.height - position.height()) / 2 + 1;
if (flare != null) {
flare.point( shield.center() );
}
classIcon.x = align(x + width - classIcon.width);
classIcon.x = x + width - classIcon.width;
classIcon.y = shield.y;
level.x = align( classIcon.x + (classIcon.width - level.width()) / 2 );
level.y = align( classIcon.y + (classIcon.height - level.height()) / 2 + 1 );
level.x = classIcon.x + (classIcon.width - level.width()) / 2;
level.y = classIcon.y + (classIcon.height - level.height()) / 2 + 1;
steps.x = align(x + width - steps.width - classIcon.width);
steps.x = x + width - steps.width - classIcon.width;
steps.y = shield.y;
depth.x = align( steps.x + (steps.width - depth.width()) / 2 );
depth.y = align( steps.y + (steps.height - depth.height()) / 2 + 1 );
depth.x = steps.x + (steps.width - depth.width()) / 2;
depth.y = steps.y + (steps.height - depth.height()) / 2 + 1;
desc.x = shield.x + shield.width + GAP;
desc.maxWidth = (int)(steps.x - desc.x);
desc.measure();
desc.y = align( shield.y + (shield.height - desc.height()) / 2 + 1 );
desc.y = shield.y + (shield.height - desc.height()) / 2 + 1;
}
@Override

View File

@ -121,8 +121,8 @@ public class StartScene extends PixelScene {
add( archs );
Image title = BannerSprites.get( Type.SELECT_YOUR_HERO );
title.x = align( (w - title.width()) / 2 );
title.y = align( top );
title.x = (w - title.width()) / 2;
title.y = top;
add( title );
buttonX = left;
@ -215,8 +215,8 @@ public class StartScene extends PixelScene {
for (BitmapText line : text.new LineSplitter().split()) {
line.measure();
line.hardlight( 0xFFFF00 );
line.x = PixelScene.align( w / 2 - line.width() / 2 );
line.y = PixelScene.align( pos );
line.x = w / 2 - line.width() / 2;
line.y = pos;
unlock.add( line );
pos += line.height();
@ -344,12 +344,12 @@ public class StartScene extends PixelScene {
super.layout();
if (secondary.text().length() > 0) {
text.y = align( y + (height - text.height() - secondary.baseLine()) / 2 );
text.y = y + (height - text.height() - secondary.baseLine()) / 2;
secondary.x = align( x + (width - secondary.width()) / 2 );
secondary.y = align( text.y + text.height() );
secondary.x = x + (width - secondary.width()) / 2;
secondary.y = text.y + text.height();
} else {
text.y = align( y + (height - text.baseLine()) / 2 );
text.y = y + (height - text.baseLine()) / 2;
}
}
@ -430,10 +430,10 @@ public class StartScene extends PixelScene {
super.layout();
avatar.x = align( x + (width - avatar.width()) / 2 );
avatar.y = align( y + (height - avatar.height() - name.height()) / 2 );
avatar.x = x + (width - avatar.width()) / 2;
avatar.y = y + (height - avatar.height() - name.height()) / 2;
name.x = align( x + (width - name.width()) / 2 );
name.x = x + (width - name.width()) / 2;
name.y = avatar.y + avatar.height() + SCALE;
emitter.pos( avatar.x, avatar.y, avatar.width(), avatar.height() );
@ -505,8 +505,8 @@ public class StartScene extends PixelScene {
super.layout();
image.x = align( x );
image.y = align( y );
image.x = x;
image.y = y;
}
@Override

View File

@ -84,8 +84,8 @@ public class SurfaceScene extends PixelScene {
archs.setSize( w, h );
add( archs );
float vx = align( (w - SKY_WIDTH) / 2 );
float vy = align( (h - SKY_HEIGHT - BUTTON_HEIGHT) / 2 );
float vx = (w - SKY_WIDTH) / 2;
float vy = (h - SKY_HEIGHT - BUTTON_HEIGHT) / 2;
Point s = Camera.main.cameraToScreen( vx, vy );
viewport = new Camera( s.x, s.y, SKY_WIDTH, SKY_HEIGHT, defaultZoom );
@ -129,7 +129,7 @@ public class SurfaceScene extends PixelScene {
Avatar a = new Avatar( Dungeon.hero.heroClass );
// Removing semitransparent contour
a.am = 2; a.aa = -1;
a.x = PixelScene.align( (SKY_WIDTH - a.width) / 2 );
a.x = (SKY_WIDTH - a.width);
a.y = SKY_HEIGHT - a.height;
window.add( a );

View File

@ -213,11 +213,11 @@ public class TitleScene extends PixelScene {
protected void layout() {
super.layout();
image.x = align( x + (width - image.width()) / 2 );
image.y = align( y );
image.x = x + (width - image.width()) / 2;
image.y = y;
label.x = align( x + (width - label.width()) / 2 );
label.y = align( image.y + image.height() +2 );
label.x = x + (width - label.width()) / 2;
label.y = image.y + image.height() +2;
}
@Override

View File

@ -138,8 +138,8 @@ public class WelcomeScene extends PixelScene {
title.measure();
title.hardlight(Window.SHPX_COLOR);
title.x = align( (w - title.width()) / 2 );
title.y = align( 8 );
title.x = (w - title.width()) / 2;
title.y = 8;
add( title );
NinePatch panel = Chrome.get(Chrome.Type.WINDOW);

View File

@ -106,10 +106,10 @@ public class BadgesList extends ScrollPane {
@Override
protected void layout() {
icon.x = x;
icon.y = PixelScene.align( y + (height - icon.height) / 2 );
icon.y = y + (height - icon.height) / 2;
label.x = icon.x + icon.width + 2;
label.y = PixelScene.align( y + (height - label.baseLine()) / 2 );
label.y = y + (height - label.baseLine()) / 2;
}
public boolean onClick( float x, float y ) {

View File

@ -69,7 +69,7 @@ public class DangerIndicator extends Tag {
private void placeNumber() {
number.x = right() - 11 - number.width();
number.y = PixelScene.align( y + (height - number.baseLine()) / 2 );
number.y = y + (height - number.baseLine()) / 2;
}
@Override

View File

@ -124,8 +124,8 @@ public class QuickSlotButton extends Button implements WndBag.Listener {
slot.fill( this );
crossB.x = PixelScene.align( x + (width - crossB.width) / 2 );
crossB.y = PixelScene.align( y + (height - crossB.height) / 2 );
crossB.x = x + (width - crossB.width) / 2;
crossB.y = y + (height - crossB.height) / 2;
}
@Override
@ -177,8 +177,8 @@ public class QuickSlotButton extends Button implements WndBag.Listener {
if (Actor.chars().contains( lastTarget )) {
lastTarget.sprite.parent.add( crossM );
crossM.point( DungeonTilemap.tileToWorld( lastTarget.pos ) );
crossB.x = PixelScene.align( x + (width - crossB.width) / 2 );
crossB.y = PixelScene.align( y + (height - crossB.height) / 2 );
crossB.x = x + (width - crossB.width) / 2;
crossB.y = y + (height - crossB.height) / 2;
crossB.visible = true;
} else {
lastTarget = null;

View File

@ -185,8 +185,8 @@ public class StatusPane extends Component {
lastLvl = Dungeon.hero.lvl;
level.text( Integer.toString( lastLvl ) );
level.measure();
level.x = PixelScene.align( 27.0f - level.width() / 2 );
level.y = PixelScene.align( 27.5f - level.baseLine() / 2 );
level.x = 27.0f - level.width() / 2;
level.y = 27.5f - level.baseLine() / 2;
}
int k = IronKey.curDepthQuantity;

View File

@ -53,8 +53,8 @@ public class WndBadge extends Window {
float pos = icon.y + icon.height() + MARGIN;
for (BitmapText line : info.new LineSplitter().split()) {
line.measure();
line.x = PixelScene.align( (w - line.width()) / 2 );
line.y = PixelScene.align( pos );
line.x = (w - line.width()) / 2;
line.y = pos;
add( line );
pos += line.height();

View File

@ -184,10 +184,10 @@ public class WndCatalogus extends WndTabbed {
@Override
protected void layout() {
sprite.y = PixelScene.align( y + (height - sprite.height) / 2 );
sprite.y = y + (height - sprite.height) / 2;
label.x = sprite.x + sprite.width;
label.y = PixelScene.align( y + (height - label.baseLine()) / 2 );
label.y = y + (height - label.baseLine()) / 2;
}
public boolean onClick( float x, float y ) {

View File

@ -160,7 +160,7 @@ public class WndHero extends WndTabbed {
txt = PixelScene.createText( value, 8 );
txt.measure();
txt.x = PixelScene.align( WIDTH * 0.65f );
txt.x = 65;
txt.y = pos;
add( txt );

View File

@ -118,11 +118,11 @@ public class WndJournal extends Window {
icon.x = width - icon.width;
depth.x = icon.x - 1 - depth.width();
depth.y = PixelScene.align( y + (height - depth.height()) / 2 );
depth.y = y + (height - depth.height()) / 2;
icon.y = depth.y - 1;
feature.y = PixelScene.align( depth.y + depth.baseLine() - feature.baseLine() );
feature.y = depth.y + depth.baseLine() - feature.baseLine();
}
}
}

View File

@ -224,7 +224,7 @@ public class WndRanking extends WndTabbed {
txt = PixelScene.createText( value, 7 );
txt.measure();
txt.x = PixelScene.align( WIDTH * 0.65f );
txt.x = WIDTH * 0.65f;
txt.y = pos;
parent.add( txt );

View File

@ -214,8 +214,8 @@ public class WndTabbed extends Window {
protected void layout() {
super.layout();
btLabel.x = PixelScene.align( x + (width - btLabel.width()) / 2 );
btLabel.y = PixelScene.align( y + (height - btLabel.baseLine()) / 2 ) - 1;
btLabel.x = x + (width - btLabel.width()) / 2;
btLabel.y = y + (height - btLabel.baseLine()) / 2 - 1;
if (!selected) {
btLabel.y -= 2;
}