public void draw(SpriteBatch batch, float parentAlpha) { super.draw(batch, parentAlpha); (selected ? checked : active) .draw(batch, getX(), getY(), checked.getMinWidth(), checked.getMinHeight()); font.draw(batch, text, getX() + checked.getMinWidth() + pad, getY() + font.getCapHeight()); }
public void setItems(Object[] objects) { if (objects == null) throw new IllegalArgumentException("items cannot be null."); if (!(objects instanceof String[])) { String[] strings = new String[objects.length]; for (int i = 0, n = objects.length; i < n; i++) strings[i] = String.valueOf(objects[i]); objects = strings; } this.items = (String[]) objects; selectedIndex = 0; Drawable bg = style.background; BitmapFont font = style.font; prefHeight = Math.max( bg.getTopHeight() + bg.getBottomHeight() + font.getCapHeight() - font.getDescent() * 2, bg.getMinHeight()); float max = 0; for (int i = 0; i < items.length; i++) max = Math.max(font.getBounds(items[i]).width, max); prefWidth = bg.getLeftWidth() + bg.getRightWidth() + max; prefWidth = Math.max( prefWidth, max + style.listBackground.getLeftWidth() + style.listBackground.getRightWidth() + 2 * style.itemSpacing); invalidateHierarchy(); }
@Override public void renderContent(@NtN Batch batch, @NtN Vector2 pos, @NtN Vector2 size) { batch.flush(); ScissorStack.pushScissors(new Rectangle(pos.x, pos.y, size.x, size.y)); checkGlyphLayout(size); float yOffset = (font.getLineHeight() - font.getAscent() - font.getCapHeight() - font.getDescent()) / 2; font.draw( batch, glyphLayout, pos.x, pos.y + size.y - yOffset + currentLine * font.getLineHeight()); batch.flush(); ScissorStack.popScissors(); }
public void render(float delta) { Gdx.gl.glClearColor(0.9f, 0.9f, 0.9f, 1); Gdx.gl.glClear(Gdx.gl.GL_COLOR_BUFFER_BIT); float font = text.getBounds(message).width; batch.begin(); { text.draw(batch, message, (width / 2F) - (font / 2F), height - text.getCapHeight()); replay.render(batch); menu.render(batch); } batch.end(); }
public void render() { // System.out.println(font.getBounds(" ").width); float textWidth = font.getBounds(text).width; // float textHeight = font.getBounds(text).height; // TextureRegion background = allocTextureRegion("grid"); // spriteBatch.setColor(0.0f, 0.0f, 0.0f, color.a * 0.7f); // spriteBatch.draw(background, // oringinX - textWidth * 0.5f - PAD, oringinY - PAD, // textWidth + PAD * 2.0f, textHeight + PAD * 2.0f); // spriteBatch.setColor(Color.WHITE); // font.get font.setColor(color); font.draw(spriteBatch, text, oringinX - textWidth * 0.5f, oringinY + font.getCapHeight()); font.setColor(Color.WHITE); }
private void drawEnemyState(SpriteBatch batch) { for (Enemy enemy : GameController.getInstance().getEnemiesMap().values()) { IEnemyState state = GdxController.getInstance().getEnemyGdx().getStateMap().get(enemy.getId()); GlyphLayout glyphLayout = new GlyphLayout(); String item = state.getClass().getSimpleName(); glyphLayout.setText(font, item); Float fwidth = glyphLayout.width; font.draw( batch, item, enemy.getX() + enemy.getWidth() / 2 - fwidth / 2, enemy.getY() + enemy.getHeight() + font.getCapHeight()); } }
private void layout() { final BitmapFont font = style.font; final Drawable listSelection = style.listSelection; final Drawable listBackground = style.listBackground; itemHeight = font.getCapHeight() + -font.getDescent() * 2 + style.itemSpacing; itemHeight += listSelection.getTopHeight() + listSelection.getBottomHeight(); textOffsetX = listSelection.getLeftWidth() + style.itemSpacing; textOffsetY = listSelection.getTopHeight() + -font.getDescent() + style.itemSpacing / 2; setWidth(SelectBox.this.getWidth()); setHeight( items.length * itemHeight + listBackground.getTopHeight() + listBackground.getBottomHeight()); }
public void layout(CustomListStyle style) { this.style = style; BitmapFont font = style.font; Drawable selectedDrawable = style.selection; textOffsetX = selectedDrawable.getLeftWidth(); textOffsetY = selectedDrawable.getTopHeight() - font.getDescent(); itemHeight = font.getCapHeight() - font.getDescent() * 2; if (hasSubtitle()) { itemHeight += style.subtitleFont.getCapHeight() - style.subtitleFont.getDescent() * 2; ; } itemHeight += selectedDrawable.getTopHeight() + selectedDrawable.getBottomHeight(); }
public ToggleBox(String text, Skin skin) { this.text = text; this.skin = skin; font = skin.getFont("default-font"); checked = skin.getDrawable("check-on"); active = skin.getDrawable("check-off"); setTouchable(Touchable.enabled); addListener( new ClickListener() { public void clicked(InputEvent ev, float x, float y) { setSelected(!isSelected()); } }); TextBounds fb = font.getBounds(text); setSize( checked.getMinWidth() + pad + fb.width, Math.max(checked.getMinHeight(), font.getCapHeight())); }
public static float getTipsHeight() { return font.getCapHeight(); }
public void draw( Batch batch, float parentAlpha, T item, boolean selected, float x, float y, float width, float height) { BitmapFont font = style.font; Drawable selectedDrawable = style.selection; Color fontColorSelected = style.fontColorSelected; Color fontColorUnselected = style.fontColorUnselected; if (selected) { selectedDrawable.draw(batch, x, y - height, width, height); font.setColor( fontColorSelected.r, fontColorSelected.g, fontColorSelected.b, fontColorSelected.a * parentAlpha); } else { font.setColor( fontColorUnselected.r, fontColorUnselected.g, fontColorUnselected.b, fontColorUnselected.a * parentAlpha); } if (hasImage()) { TextureRegion r = getCellImage(item); float ih = r.getRegionHeight(); float iw = r.getRegionWidth(); if (ih > getItemHeight() - MARGIN) { ih = getItemHeight() - MARGIN; iw *= ih / r.getRegionHeight(); } batch.draw(r, x, y - ih - MARGIN / 2, iw, ih); x += iw; } font.draw(batch, getCellTitle(item), x + textOffsetX, y - textOffsetY); if (hasSubtitle()) { if (selected) { style.subtitleFont.setColor( fontColorSelected.r, fontColorSelected.g, fontColorSelected.b, fontColorSelected.a * parentAlpha * 0.5f); } else { style.subtitleFont.setColor( fontColorUnselected.r, fontColorUnselected.g, fontColorUnselected.b, fontColorUnselected.a * parentAlpha * 0.5f); } style.subtitleFont.draw( batch, getCellSubTitle(item), x + textOffsetX, y - textOffsetY - (font.getCapHeight() - font.getDescent() * 2)); } }
public int getBaseLine() { return (int) bitmapFont.getCapHeight(); }