Java Code Examples for com.watabou.noosa.BitmapText#measure()
The following examples show how to use
com.watabou.noosa.BitmapText#measure() .
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: WndBag.java From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 | 6 votes |
protected void placeTitle( Bag bag, int width ){ RenderedTextBlock txtTitle = PixelScene.renderTextBlock( title != null ? Messages.titleCase(title) : Messages.titleCase( bag.name() ), 9 ); txtTitle.hardlight( TITLE_COLOR ); txtTitle.setPos( 1, (TITLE_HEIGHT - txtTitle.height()) / 2f - 1 ); PixelScene.align(txtTitle); add( txtTitle ); ItemSprite gold = new ItemSprite(ItemSpriteSheet.GOLD, null); gold.x = width - gold.width() - 1; gold.y = (TITLE_HEIGHT - gold.height())/2f - 1; PixelScene.align(gold); add(gold); BitmapText amt = new BitmapText( Integer.toString(Dungeon.gold), PixelScene.pixelFont ); amt.hardlight(TITLE_COLOR); amt.measure(); amt.x = width - gold.width() - amt.width() - 2; amt.y = (TITLE_HEIGHT - amt.baseLine())/2f - 1; PixelScene.align(amt); add(amt); }
Example 2
Source File: WndClass.java From YetAnotherPixelDungeon with GNU General Public License v3.0 | 5 votes |
public DetailsTab() { super(); float dotWidth = 0; String[] items = cl.details(); float pos = MARGIN; for (int i=0; i < items.length; i++) { if (i > 0) { pos += GAP; } BitmapText dot = PixelScene.createText( DOT, 6 ); dot.x = MARGIN; dot.y = pos; if (dotWidth == 0) { dot.measure(); dotWidth = dot.width(); } add( dot ); BitmapTextMultiline item = PixelScene.createMultiline( items[i], 6 ); item.x = dot.x + dotWidth; item.y = pos; item.maxWidth = (int)(WIDTH - MARGIN * 2 - dotWidth); item.measure(); add( item ); pos += item.height(); float w = item.width(); if (w > width) { width = w; } } width += MARGIN + dotWidth; height = pos + MARGIN; }
Example 3
Source File: WndBag.java From shattered-pixel-dungeon with GNU General Public License v3.0 | 5 votes |
protected void placeTitle( Bag bag, int width ){ ItemSprite gold = new ItemSprite(ItemSpriteSheet.GOLD, null); gold.x = width - gold.width() - 1; gold.y = (TITLE_HEIGHT - gold.height())/2f - 1; PixelScene.align(gold); add(gold); BitmapText amt = new BitmapText( Integer.toString(Dungeon.gold), PixelScene.pixelFont ); amt.hardlight(TITLE_COLOR); amt.measure(); amt.x = width - gold.width() - amt.width() - 2; amt.y = (TITLE_HEIGHT - amt.baseLine())/2f - 1; PixelScene.align(amt); add(amt); RenderedTextBlock txtTitle = PixelScene.renderTextBlock( title != null ? Messages.titleCase(title) : Messages.titleCase( bag.name() ), 8 ); txtTitle.hardlight( TITLE_COLOR ); txtTitle.maxWidth( (int)amt.x - 2 ); txtTitle.setPos( 1, (TITLE_HEIGHT - txtTitle.height()) / 2f - 1 ); PixelScene.align(txtTitle); add( txtTitle ); }
Example 4
Source File: WndClass.java From pixel-dungeon with GNU General Public License v3.0 | 5 votes |
public PerksTab() { super(); float dotWidth = 0; String[] items = cl.perks(); float pos = MARGIN; for (int i=0; i < items.length; i++) { if (i > 0) { pos += GAP; } BitmapText dot = PixelScene.createText( DOT, 6 ); dot.x = MARGIN; dot.y = pos; if (dotWidth == 0) { dot.measure(); dotWidth = dot.width(); } add( dot ); BitmapTextMultiline item = PixelScene.createMultiline( items[i], 6 ); item.x = dot.x + dotWidth; item.y = pos; item.maxWidth = (int)(WIDTH - MARGIN * 2 - dotWidth); item.measure(); add( item ); pos += item.height(); float w = item.width(); if (w > width) { width = w; } } width += MARGIN + dotWidth; height = pos + MARGIN; }
Example 5
Source File: WndChallenges.java From pixel-dungeon with GNU General Public License v3.0 | 5 votes |
public WndChallenges( int checked, boolean editable ) { super(); this.editable = editable; 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 ); add( title ); boxes = new ArrayList<CheckBox>(); float pos = TTL_HEIGHT; for (int i=0; i < Challenges.NAMES.length; i++) { CheckBox cb = new CheckBox( Challenges.NAMES[i] ); cb.checked( (checked & Challenges.MASKS[i]) != 0 ); cb.active = editable; if (i > 0) { pos += GAP; } cb.setRect( 0, pos, WIDTH, BTN_HEIGHT ); pos = cb.bottom(); add( cb ); boxes.add( cb ); } resize( WIDTH, (int)pos ); }
Example 6
Source File: WndList.java From unleashed-pixel-dungeon with GNU General Public License v3.0 | 5 votes |
public WndList( String[] items ) { super(); float pos = MARGIN; float dotWidth = 0; float maxWidth = 0; for (int i=0; i < items.length; i++) { if (i > 0) { pos += GAP; } BitmapText dot = PixelScene.createText( DOT, 6 ); dot.x = MARGIN; dot.y = pos; if (dotWidth == 0) { dot.measure(); dotWidth = dot.width(); } add( dot ); BitmapTextMultiline item = PixelScene.createMultiline( items[i], 6 ); item.x = dot.x + dotWidth; item.y = pos; item.maxWidth = (int)(WIDTH - MARGIN * 2 - dotWidth); item.measure(); add( item ); pos += item.height(); float w = item.width(); if (w > maxWidth) { maxWidth = w; } } resize( (int)(maxWidth + dotWidth + MARGIN * 2), (int)(pos + MARGIN) ); }
Example 7
Source File: WndBadge.java From unleashed-pixel-dungeon with GNU General Public License v3.0 | 5 votes |
public WndBadge( Badges.Badge badge ) { super(); Image icon = BadgeBanner.image( badge.image ); icon.scale.set( 2 ); add( icon ); BitmapTextMultiline info = PixelScene.createMultiline( badge.description, 8 ); info.maxWidth = WIDTH - MARGIN * 2; info.measure(); float w = Math.max( icon.width(), info.width() ) + MARGIN * 2; icon.x = (w - icon.width()) / 2; icon.y = MARGIN; 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 ); add( line ); pos += line.height(); } resize( (int)w, (int)(pos + MARGIN) ); BadgeBanner.highlight( icon, badge.image ); }
Example 8
Source File: WndHero.java From unleashed-pixel-dungeon with GNU General Public License v3.0 | 5 votes |
private void statSlot( String label, String value ) { BitmapText txt = PixelScene.createText( label, 8 ); txt.y = pos; add( txt ); txt = PixelScene.createText( value, 8 ); txt.measure(); txt.x = PixelScene.align( WIDTH * 0.65f ); txt.y = pos; add( txt ); pos += GAP + txt.baseLine(); }
Example 9
Source File: WndRanking.java From unleashed-pixel-dungeon with GNU General Public License v3.0 | 5 votes |
private float statSlot( Group parent, String label, String value, float pos ) { BitmapText txt = PixelScene.createText( label, 7 ); txt.y = pos; parent.add( txt ); txt = PixelScene.createText( value, 7 ); txt.measure(); txt.x = PixelScene.align( WIDTH * 0.65f ); txt.y = pos; parent.add( txt ); return pos + GAP + txt.baseLine(); }
Example 10
Source File: WndClass.java From unleashed-pixel-dungeon with GNU General Public License v3.0 | 5 votes |
public PerksTab() { super(); float dotWidth = 0; String[] items = cl.perks(); float pos = MARGIN; for (int i=0; i < items.length; i++) { if (i > 0) { pos += GAP; } BitmapText dot = PixelScene.createText( DOT, 6 ); dot.x = MARGIN; dot.y = pos; if (dotWidth == 0) { dot.measure(); dotWidth = dot.width(); } add( dot ); BitmapTextMultiline item = PixelScene.createMultiline( items[i], 6 ); item.x = dot.x + dotWidth; item.y = pos; item.maxWidth = (int)(WIDTH - MARGIN * 2 - dotWidth); item.measure(); add( item ); pos += item.height(); float w = item.width(); if (w > width) { width = w; } } width += MARGIN + dotWidth; height = pos + MARGIN; }
Example 11
Source File: WndRanking.java From pixel-dungeon with GNU General Public License v3.0 | 5 votes |
private float statSlot( Group parent, String label, String value, float pos ) { BitmapText txt = PixelScene.createText( label, 7 ); txt.y = pos; parent.add( txt ); txt = PixelScene.createText( value, 7 ); txt.measure(); txt.x = PixelScene.align( WIDTH * 0.65f ); txt.y = pos; parent.add( txt ); return pos + GAP + txt.baseLine(); }
Example 12
Source File: WndChallenges.java From YetAnotherPixelDungeon with GNU General Public License v3.0 | 5 votes |
public WndChallenges(int checked, boolean editable) { super(); this.editable = editable; 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 ); add( title ); boxes = new ArrayList<CheckBox>(); float pos = TTL_HEIGHT; for (int i=0; i < Challenges.NAMES.length; i++) { CheckBox cb = new CheckBox( Challenges.NAMES[i] ); cb.checked( (checked & Challenges.MASKS[i]) != 0 ); cb.active = editable; if (i > 0) { pos += GAP; } cb.setRect( 0, pos, WIDTH, BTN_HEIGHT ); pos = cb.bottom(); add( cb ); boxes.add( cb ); } resize( WIDTH, (int)pos ); }
Example 13
Source File: WndHero.java From YetAnotherPixelDungeon with GNU General Public License v3.0 | 5 votes |
private void statSlot( String label, String value ) { BitmapText txt = PixelScene.createText( label, 6 ); txt.y = pos; add( txt ); txt = PixelScene.createText( value, 6 ); txt.measure(); txt.x = PixelScene.align( WIDTH * 0.65f ); txt.y = pos; add( txt ); pos += GAP + txt.baseLine(); }
Example 14
Source File: WndBag.java From unleashed-pixel-dungeon with GNU General Public License v3.0 | 4 votes |
public WndBag( Bag bag, Listener listener, Mode mode, String title ) { super(); this.listener = listener; this.mode = mode; this.title = title; lastMode = mode; lastBag = bag; nCols = ShatteredPixelDungeon.landscape() ? COLS_L : COLS_P; nRows = (Belongings.BACKPACK_SIZE + 4 + 1) / nCols + ((Belongings.BACKPACK_SIZE + 4 + 1) % nCols > 0 ? 1 : 0); int slotsWidth = SLOT_SIZE * nCols + SLOT_MARGIN * (nCols - 1); int slotsHeight = SLOT_SIZE * nRows + SLOT_MARGIN * (nRows - 1); BitmapText txtTitle = PixelScene.createText( title != null ? title : Utils.capitalize( bag.name() ), 9 ); txtTitle.hardlight( TITLE_COLOR ); txtTitle.measure(); txtTitle.x = (int)(slotsWidth - txtTitle.width()) / 2; txtTitle.y = (int)(TITLE_HEIGHT - txtTitle.height()) / 2; add( txtTitle ); placeItems( bag ); resize( slotsWidth, slotsHeight + TITLE_HEIGHT ); Belongings stuff = Dungeon.hero.belongings; Bag[] bags = { stuff.backpack, stuff.getItem( SeedPouch.class ), stuff.getItem( ScrollHolder.class ), stuff.getItem( PotionBandolier.class ), stuff.getItem( WandHolster.class ), stuff.getItem( AnkhChain.class )}; for (Bag b : bags) { if (b != null) { BagTab tab = new BagTab( b ); add( tab ); tab.select( b == bag ); } } layoutTabs(); }
Example 15
Source File: BadgesScene.java From unleashed-pixel-dungeon with GNU General Public License v3.0 | 4 votes |
@Override public void create() { super.create(); Music.INSTANCE.play( Assets.THEME, true ); Music.INSTANCE.volume( 1f ); uiCamera.visible = false; int w = Camera.main.width; int h = Camera.main.height; Archs archs = new Archs(); archs.setSize( w, h ); add( archs ); int pw = Math.min( MAX_PANE_WIDTH, w - 6 ); int ph = h - 30; NinePatch panel = Chrome.get( Chrome.Type.WINDOW ); panel.size( pw, ph ); panel.x = (w - pw) / 2; panel.y = (h - ph) / 2; add( panel ); 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 ); add( title ); Badges.loadGlobal(); ScrollPane list = new BadgesList( true ); add( list ); list.setRect( panel.x + panel.marginLeft(), panel.y + panel.marginTop(), panel.innerWidth(), panel.innerHeight() ); ExitButton btnExit = new ExitButton(); btnExit.setPos( Camera.main.width - btnExit.width(), 0 ); add( btnExit ); fadeIn(); Badges.loadingListener = new Callback() { @Override public void call() { if (Game.scene() == BadgesScene.this) { ShatteredPixelDungeon.switchNoFade( BadgesScene.class ); } } }; }
Example 16
Source File: StatusPane.java From YetAnotherPixelDungeon with GNU General Public License v3.0 | 4 votes |
@Override protected void createChildren() { shield = new NinePatch( Assets.STATUS, 80, 0, 48, 0 ); add( shield ); add( new TouchArea( 0, 1, 30, 30 ) { @Override protected void onClick( Touch touch ) { Image sprite = Dungeon.hero.sprite; if (!sprite.isVisible()) { Camera.main.focusOn( sprite ); } GameScene.show( new WndHero() ); }; } ); btnMenu = new MenuButton(); add( btnMenu ); difficulty = new IconDifficulty(); add(difficulty); avatar = HeroSprite.avatar( Dungeon.hero.heroClass, lastTier ); add(avatar); // blood = new Emitter(); // blood.pos(avatar); // blood.pour(BloodParticle.FACTORY, 0.3f); // blood.autoKill = false; // blood.on = false; // addFromDamage(blood); compass = new Compass( Dungeon.level.exit ); add( compass ); hp = new Image( Assets.HP_BAR ); add( hp ); exp = new Image( Assets.XP_BAR ); add(exp); level = new BitmapText( PixelScene.font1x ); level.hardlight(0xFFEBA4); add(level); health = new BitmapText( PixelScene.font1x ); health.hardlight(0xCACFC2); add(health); depth = new BitmapText( Integer.toString( Dungeon.depth ), PixelScene.font1x ); depth.hardlight(0xCACFC2); depth.measure(); add( depth ); Dungeon.hero.belongings.countIronKeys(); keys = new BitmapText( PixelScene.font1x ); keys.hardlight(0xCACFC2); add(keys); danger = new TagDanger(); add(danger); attack = new TagAttack(); add( attack ); pickup = new TagPickup(); add(pickup); resume = new TagResume(); add( resume ); btnWaterskin = new TagWaterskin(); add(btnWaterskin); btnOilLantern = new TagOilLantern(); add(btnOilLantern); buffs = new BuffIndicator( Dungeon.hero ); add( buffs ); }
Example 17
Source File: WndHero.java From pixel-dungeon with GNU General Public License v3.0 | 4 votes |
public StatsTab() { Hero hero = Dungeon.hero; BitmapText title = PixelScene.createText( Utils.format( TXT_TITLE, hero.lvl, hero.className() ).toUpperCase( Locale.ENGLISH ), 9 ); title.hardlight( TITLE_COLOR ); title.measure(); add( title ); RedButton btnCatalogus = new RedButton( TXT_CATALOGUS ) { @Override protected void onClick() { hide(); GameScene.show( new WndCatalogus() ); } }; btnCatalogus.setRect( 0, title.y + title.height(), btnCatalogus.reqWidth() + 2, btnCatalogus.reqHeight() + 2 ); add( btnCatalogus ); RedButton btnJournal = new RedButton( TXT_JOURNAL ) { @Override protected void onClick() { hide(); GameScene.show( new WndJournal() ); } }; btnJournal.setRect( btnCatalogus.right() + 1, btnCatalogus.top(), btnJournal.reqWidth() + 2, btnJournal.reqHeight() + 2 ); add( btnJournal ); pos = btnCatalogus.bottom() + GAP; statSlot( TXT_STR, hero.STR() ); statSlot( TXT_HEALTH, hero.HP + "/" + hero.HT ); statSlot( TXT_EXP, hero.exp + "/" + hero.maxExp() ); pos += GAP; statSlot( TXT_GOLD, Statistics.goldCollected ); statSlot( TXT_DEPTH, Statistics.deepestFloor ); pos += GAP; }
Example 18
Source File: BadgesScene.java From pixel-dungeon with GNU General Public License v3.0 | 4 votes |
@Override public void create() { super.create(); Music.INSTANCE.play( Assets.THEME, true ); Music.INSTANCE.volume( 1f ); uiCamera.visible = false; int w = Camera.main.width; int h = Camera.main.height; Archs archs = new Archs(); archs.setSize( w, h ); add( archs ); int pw = (int)Math.min( w, (PixelDungeon.landscape() ? MIN_WIDTH_L : MIN_WIDTH_P) * 3 ) - 16; int ph = (int)Math.min( h, (PixelDungeon.landscape() ? MIN_HEIGHT_L : MIN_HEIGHT_P) * 3 ) - 32; float size = (float)Math.sqrt( pw * ph / 27f ); int nCols = (int)Math.ceil( pw / size ); int nRows = (int)Math.ceil( ph / size ); size = Math.min( pw / nCols, ph / nRows ); float left = (w - size * nCols) / 2; float top = (h - size * nRows) / 2; BitmapText title = PixelScene.createText( TXT_TITLE, 9 ); title.hardlight( Window.TITLE_COLOR ); title.measure(); title.x = align( (w - title.width()) / 2 ); title.y = align( (top - title.baseLine()) / 2 ); add( title ); Badges.loadGlobal(); List<Badges.Badge> badges = Badges.filtered( true ); for (int i=0; i < nRows; i++) { for (int j=0; j < nCols; j++) { int index = i * nCols + j; Badges.Badge b = index < badges.size() ? badges.get( index ) : null; BadgeButton button = new BadgeButton( b ); button.setPos( left + j * size + (size - button.width()) / 2, top + i * size + (size - button.height()) / 2); add( button ); } } ExitButton btnExit = new ExitButton(); btnExit.setPos( Camera.main.width - btnExit.width(), 0 ); add( btnExit ); fadeIn(); Badges.loadingListener = new Callback() { @Override public void call() { if (Game.scene() == BadgesScene.this) { PixelDungeon.switchNoFade( BadgesScene.class ); } } }; }
Example 19
Source File: StatusPane.java From pixel-dungeon with GNU General Public License v3.0 | 4 votes |
@Override protected void createChildren() { shield = new NinePatch( Assets.STATUS, 80, 0, 30 + 18, 0 ); add( shield ); add( new TouchArea( 0, 1, 30, 30 ) { @Override protected void onClick( Touch touch ) { Image sprite = Dungeon.hero.sprite; if (!sprite.isVisible()) { Camera.main.focusOn( sprite ); } GameScene.show( new WndHero() ); }; } ); btnMenu = new MenuButton(); add( btnMenu ); avatar = HeroSprite.avatar( Dungeon.hero.heroClass, lastTier ); add( avatar ); blood = new BitmaskEmitter( avatar ); blood.pour( BloodParticle.FACTORY, 0.3f ); blood.autoKill = false; blood.on = false; add( blood ); compass = new Compass( Dungeon.level.exit ); add( compass ); hp = new Image( Assets.HP_BAR ); add( hp ); exp = new Image( Assets.XP_BAR ); add( exp ); level = new BitmapText( PixelScene.font1x ); level.hardlight( 0xFFEBA4 ); add( level ); depth = new BitmapText( Integer.toString( Dungeon.depth ), PixelScene.font1x ); depth.hardlight( 0xCACFC2 ); depth.measure(); add( depth ); Dungeon.hero.belongings.countIronKeys(); keys = new BitmapText( PixelScene.font1x ); keys.hardlight( 0xCACFC2 ); add( keys ); danger = new DangerIndicator(); add( danger ); loot = new LootIndicator(); add( loot ); resume = new ResumeButton(); add( resume ); buffs = new BuffIndicator( Dungeon.hero ); add( buffs ); }
Example 20
Source File: BadgesScene.java From YetAnotherPixelDungeon with GNU General Public License v3.0 | 4 votes |
@Override public void create() { super.create(); Music.INSTANCE.play( Assets.TRACK_MAIN_THEME, true ); Music.INSTANCE.volume( 1f ); uiCamera.visible = false; int w = Camera.main.width; int h = Camera.main.height; Archs archs = new Archs(); archs.setSize( w, h ); add( archs ); int pw = Math.min( MAX_PANE_WIDTH, w - 6 ); int ph = h - 30; NinePatch panel = Chrome.get( Chrome.Type.WINDOW ); panel.size( pw, ph ); panel.x = (w - pw) / 2; panel.y = (h - ph) / 2; add( panel ); 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 ); add( title ); ScrollPane list = new BadgesList( true ); add( list ); list.setRect( panel.x + panel.marginLeft(), panel.y + panel.marginTop(), panel.innerWidth(), panel.innerHeight() ); ExitButton btnExit = new ExitButton(); btnExit.setPos( Camera.main.width - btnExit.width(), 0 ); add( btnExit ); fadeIn(); // Badges.loadingListener = new Callback() { // @Override // public void call() { // if (Game.scene() == BadgesScene.this) { // YetAnotherPixelDungeon.switchNoFade(BadgesScene.class); // } // } // }; }