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 ); hardlight( color );
measure(); measure();
this.x = PixelScene.align( x - width() / 2 ); this.x = x - width() / 2;
this.y = y - height(); this.y = y - height();
timeLeft = LIFESPAN; timeLeft = LIFESPAN;

View File

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

View File

@ -91,8 +91,8 @@ public class AmuletScene extends PixelScene {
if (noText) { if (noText) {
height = amulet.height + LARGE_GAP + btnExit.height() + SMALL_GAP + btnStay.height(); height = amulet.height + LARGE_GAP + btnExit.height() + SMALL_GAP + btnStay.height();
amulet.x = align( (Camera.main.width - amulet.width) / 2 ); amulet.x = (Camera.main.width - amulet.width) / 2;
amulet.y = align( (Camera.main.height - height) / 2 ); amulet.y = (Camera.main.height - height) / 2;
btnExit.setPos( (Camera.main.width - btnExit.width()) / 2, amulet.y + amulet.height + LARGE_GAP ); btnExit.setPos( (Camera.main.width - btnExit.width()) / 2, amulet.y + amulet.height + LARGE_GAP );
btnStay.setPos( btnExit.left(), btnExit.bottom() + SMALL_GAP ); btnStay.setPos( btnExit.left(), btnExit.bottom() + SMALL_GAP );
@ -100,10 +100,10 @@ public class AmuletScene extends PixelScene {
} else { } else {
height = amulet.height + LARGE_GAP + text.height() + LARGE_GAP + btnExit.height() + SMALL_GAP + btnStay.height(); 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.x = (Camera.main.width - amulet.width) / 2;
amulet.y = align( (Camera.main.height - height) / 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; text.y = amulet.y + amulet.height + LARGE_GAP;
btnExit.setPos( (Camera.main.width - btnExit.width()) / 2, text.y + text.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 ); BitmapText title = PixelScene.createText( TXT_TITLE, 9 );
title.hardlight( Window.TITLE_COLOR ); title.hardlight( Window.TITLE_COLOR );
title.measure(); title.measure();
title.x = align( (w - title.width()) / 2 ); title.x = (w - title.width()) / 2;
title.y = align( (panel.y - title.baseLine()) / 2 ); title.y = (panel.y - title.baseLine()) / 2;
add( title ); add( title );
Badges.loadGlobal(); Badges.loadGlobal();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -106,10 +106,10 @@ public class BadgesList extends ScrollPane {
@Override @Override
protected void layout() { protected void layout() {
icon.x = x; 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.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 ) { public boolean onClick( float x, float y ) {

View File

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

View File

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

View File

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

View File

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

View File

@ -184,10 +184,10 @@ public class WndCatalogus extends WndTabbed {
@Override @Override
protected void layout() { 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.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 ) { public boolean onClick( float x, float y ) {

View File

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

View File

@ -118,11 +118,11 @@ public class WndJournal extends Window {
icon.x = width - icon.width; icon.x = width - icon.width;
depth.x = icon.x - 1 - depth.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; 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 = PixelScene.createText( value, 7 );
txt.measure(); txt.measure();
txt.x = PixelScene.align( WIDTH * 0.65f ); txt.x = WIDTH * 0.65f;
txt.y = pos; txt.y = pos;
parent.add( txt ); parent.add( txt );

View File

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