Java Code Examples for com.watabou.noosa.BitmapText#width()

The following examples show how to use com.watabou.noosa.BitmapText#width() . 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 vote down vote up
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 vote down vote up
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: WndClass.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
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 4
Source File: WndList.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
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 5
Source File: WndClass.java    From pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
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 6
Source File: WndBag.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
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 7
Source File: RankingsScene.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@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 = new Archs();
	archs.setSize( w, h );
	add( archs );
	
	Rankings.INSTANCE.load();

	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 );
	add(title);
	
	if (Rankings.INSTANCE.records.size() > 0) {

		//attempts to give each record as much space as possible, ideally as much space as portrait mode
		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 );
		
		int pos = 0;
		
		for (Rankings.Record rec : Rankings.INSTANCE.records) {
			Record row = new Record( pos, pos == Rankings.INSTANCE.lastRecord, rec );
			float offset = rowHeight <= 14 ?
							pos %2 == 1? 5 : -5
							: 0;
			row.setRect( left+offset, top + pos * rowHeight, w - left * 2, rowHeight );
			try {
				add(row);
				pos++;
			} catch (Exception e) {
				//
			}
		}
		
		if (Rankings.INSTANCE.totalNumber >= Rankings.TABLE_SIZE) {
			BitmapText label = PixelScene.createText( TXT_TOTAL, 8 );
			label.hardlight( 0xCCCCCC );
			label.measure();
			add( label );

			BitmapText won = PixelScene.createText( Integer.toString( Rankings.INSTANCE.wonNumber ), 8 );
			won.hardlight( Window.SHPX_COLOR );
			won.measure();
			add( won );

			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 );
			add( total );

			float tw = label.width() + won.width() + total.width();
			label.x = align( (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 );

		}
		
	} else {

		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);
		add(noRec);
		
	}

	ExitButton btnExit = new ExitButton();
	btnExit.setPos( Camera.main.width - btnExit.width(), 0 );
	add( btnExit );

	fadeIn();
}
 
Example 8
Source File: WndBag.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
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 9
Source File: WndBag.java    From pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
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 = PixelDungeon.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( WandHolster.class ),
		stuff.getItem( Keyring.class )};
	
	for (Bag b : bags) {
		if (b != null) {
			BagTab tab = new BagTab( b );
			tab.setSize( TAB_WIDTH, tabHeight() );
			add( tab );
			
			tab.select( b == bag );
		}
	}
}