/** @see #setText(BitmapFont, CharSequence) */ public GlyphLayout (BitmapFont font, CharSequence str) { setText(font, str); }
/** @see #setText(BitmapFont, CharSequence) */ public GlyphLayout (BitmapFont font, CharSequence str, int start, int end, Color color, float targetWidth, int halign, boolean wrap, String truncate) { setText(font, str, start, end, color, targetWidth, halign, wrap, truncate); }
/** @see #setText(BitmapFont, CharSequence) */ public GlyphLayout (BitmapFont font, CharSequence str, int start, int end, Color color, float targetWidth, int halign, boolean wrap, String truncate) { setText(font, str, start, end, color, targetWidth, halign, wrap, truncate); }
/** @see #setText(BitmapFont, CharSequence) */ public GlyphLayout (BitmapFont font, CharSequence str, Color color, float targetWidth, int halign, boolean wrap) { setText(font, str, color, targetWidth, halign, wrap); }
/** @see #setText(BitmapFont, CharSequence) */ public GlyphLayout (BitmapFont font, CharSequence str, Color color, float targetWidth, int halign, boolean wrap) { setText(font, str, color, targetWidth, halign, wrap); }
/** @see #setText(BitmapFont, CharSequence) */ public GlyphLayout (BitmapFont font, CharSequence str) { setText(font, str); }
/** Calls {@link #setText(BitmapFont, CharSequence, int, int, Color, float, int, boolean, String) setText} with the whole * string and no truncation. */ public void setText (BitmapFont font, CharSequence str, Color color, float targetWidth, int halign, boolean wrap) { setText(font, str, 0, str.length(), color, targetWidth, halign, wrap, null); }
/** Calls {@link #setText(BitmapFont, CharSequence, int, int, Color, float, int, boolean, String) setText} with the whole * string and no truncation. */ public void setText (BitmapFont font, CharSequence str, Color color, float targetWidth, int halign, boolean wrap) { setText(font, str, 0, str.length(), color, targetWidth, halign, wrap, null); }
/** Calls {@link #setText(BitmapFont, CharSequence, int, int, Color, float, int, boolean, String) setText} with the whole * string, the font's current color, and no alignment or wrapping. */ public void setText (BitmapFont font, CharSequence str) { setText(font, str, 0, str.length(), font.getColor(), 0, Align.left, false, null); }
/** Calls {@link #setText(BitmapFont, CharSequence, int, int, Color, float, int, boolean, String) setText} with the whole * string, the font's current color, and no alignment or wrapping. */ public void setText (BitmapFont font, CharSequence str) { setText(font, str, 0, str.length(), font.getColor(), 0, Align.left, false, null); }
private void computePrefSize () { prefSizeInvalid = false; GlyphLayout prefSizeLayout = Label.prefSizeLayout; if (wrap && ellipsis == null) { float width = getWidth(); if (style.background != null) width -= style.background.getLeftWidth() + style.background.getRightWidth(); prefSizeLayout.setText(cache.getFont(), text, Color.WHITE, width, Align.left, true); } else prefSizeLayout.setText(cache.getFont(), text); prefSize.set(prefSizeLayout.width, prefSizeLayout.height); }
private void computePrefSize () { prefSizeInvalid = false; GlyphLayout prefSizeLayout = Label.prefSizeLayout; if (wrap && ellipsis == null) { float width = getWidth(); if (style.background != null) width -= style.background.getLeftWidth() + style.background.getRightWidth(); prefSizeLayout.setText(cache.getFont(), text, Color.WHITE, width, Align.left, true); } else prefSizeLayout.setText(cache.getFont(), text); prefSize.set(prefSizeLayout.width, prefSizeLayout.height); }
/** Adds glyphs for the the specified text. * @param x The x position for the left most character. * @param y The y position for the top of most capital letters in the font (the {@link BitmapFontData#capHeight cap height}). * @param start The first character of the string to draw. * @param end The last character of the string to draw (exclusive). * @param targetWidth The width of the area the text will be drawn, for wrapping or truncation. * @param halign Horizontal alignment of the text, see {@link Align}. * @param wrap If true, the text will be wrapped within targetWidth. * @param truncate If not null, the text will be truncated within targetWidth with this string appended. May be an empty * string. * @return The glyph layout for the cached string (the layout's height is the distance from y to the baseline). */ public GlyphLayout addText (CharSequence str, float x, float y, int start, int end, float targetWidth, int halign, boolean wrap, String truncate) { GlyphLayout layout = Pools.obtain(GlyphLayout.class); pooledLayouts.add(layout); layout.setText(font, str, start, end, color, targetWidth, halign, wrap, truncate); addText(layout, x, y); return layout; }
/** Adds glyphs for the the specified text. * @param x The x position for the left most character. * @param y The y position for the top of most capital letters in the font (the {@link BitmapFontData#capHeight cap height}). * @param start The first character of the string to draw. * @param end The last character of the string to draw (exclusive). * @param targetWidth The width of the area the text will be drawn, for wrapping or truncation. * @param halign Horizontal alignment of the text, see {@link Align}. * @param wrap If true, the text will be wrapped within targetWidth. * @param truncate If not null, the text will be truncated within targetWidth with this string appended. May be an empty * string. * @return The glyph layout for the cached string (the layout's height is the distance from y to the baseline). */ public GlyphLayout addText (CharSequence str, float x, float y, int start, int end, float targetWidth, int halign, boolean wrap, String truncate) { GlyphLayout layout = Pools.obtain(GlyphLayout.class); pooledLayouts.add(layout); layout.setText(font, str, start, end, color, targetWidth, halign, wrap, truncate); addText(layout, x, y); return layout; }
private void renderSingleLine () { String text = "Single Line"; float x = logoSprite.getX(); float y = logoSprite.getY(); float width = logoSprite.getWidth(); float height = logoSprite.getHeight(); layout.setText(font, text); x += width / 2 - layout.width / 2; y += height / 2 + layout.height / 2; font.draw(spriteBatch, text, x, y); }
private void renderMultiLine () { String text = "Multi\nLine"; float x = logoSprite.getX(); float y = logoSprite.getY(); float width = logoSprite.getWidth(); float height = logoSprite.getHeight(); layout.setText(font, text); x += width / 2 - layout.width / 2; y += height / 2 + layout.height / 2; font.draw(spriteBatch, text, x, y); // Note that multi line text can be aligned: // font.draw(spriteBatch, text, x, y, width, Align.center, false); }
private void renderWrapped () { String text = "Wrapped Wrapped Wrapped Wrapped"; float x = logoSprite.getX(); float y = logoSprite.getY(); float width = logoSprite.getWidth(); float height = logoSprite.getHeight(); layout.setText(font, text, Color.WHITE, width, Align.left, true); x += width / 2 - layout.width / 2; y += height / 2 + layout.height / 2; font.draw(spriteBatch, text, x, y, width, Align.left, true); // More efficient to draw the layout used for bounds: // font.draw(spriteBatch, layout, x, y); // Note that wrapped text can be aligned: // font.draw(spriteBatch, text, x, y, width, Align.center, true); }
public void layout () { BitmapFont font = style.font; Drawable selectedDrawable = style.selection; itemHeight = font.getCapHeight() - font.getDescent() * 2; itemHeight += selectedDrawable.getTopHeight() + selectedDrawable.getBottomHeight(); prefWidth = 0; Pool<GlyphLayout> layoutPool = Pools.get(GlyphLayout.class); GlyphLayout layout = layoutPool.obtain(); for (int i = 0; i < items.size; i++) { layout.setText(font, toString(items.get(i))); prefWidth = Math.max(layout.width, prefWidth); } layoutPool.free(layout); prefWidth += selectedDrawable.getLeftWidth() + selectedDrawable.getRightWidth(); prefHeight = items.size * itemHeight; Drawable background = style.background; if (background != null) { prefWidth += background.getLeftWidth() + background.getRightWidth(); prefHeight += background.getTopHeight() + background.getBottomHeight(); } }
public void layout () { BitmapFont font = style.font; Drawable selectedDrawable = style.selection; itemHeight = font.getCapHeight() - font.getDescent() * 2; itemHeight += selectedDrawable.getTopHeight() + selectedDrawable.getBottomHeight(); prefWidth = 0; Pool<GlyphLayout> layoutPool = Pools.get(GlyphLayout.class); GlyphLayout layout = layoutPool.obtain(); for (int i = 0; i < items.size; i++) { layout.setText(font, toString(items.get(i))); prefWidth = Math.max(layout.width, prefWidth); } layoutPool.free(layout); prefWidth += selectedDrawable.getLeftWidth() + selectedDrawable.getRightWidth(); prefHeight = items.size * itemHeight; Drawable background = style.background; if (background != null) { prefWidth += background.getLeftWidth() + background.getRightWidth(); prefHeight += background.getTopHeight() + background.getBottomHeight(); } }
private void drawBitmap (String text, int startIndex, int endIndex) { BitmapFontData data = bitmapFont.getData(); int padY = paddingTop + paddingBottom + paddingAdvanceY; data.setLineHeight(data.lineHeight + padY); layout.setText(bitmapFont, text); data.setLineHeight(data.lineHeight - padY); for (GlyphRun run : layout.runs) for (int i = 0, n = run.xAdvances.size; i < n; i++) run.xAdvances.incr(i, paddingAdvanceX + paddingLeft + paddingRight); cache.setText(layout, paddingLeft, paddingRight); Array<TextureRegion> regions = bitmapFont.getRegions(); for (int i = 0, n = regions.size; i < n; i++) { regions.get(i).getTexture().bind(); GL11.glBegin(GL11.GL_QUADS); float[] vertices = cache.getVertices(i); for (int ii = 0, nn = vertices.length; ii < nn; ii += 20) { GL11.glTexCoord2f(vertices[ii + U], vertices[ii + V]); GL11.glVertex3f(vertices[ii + X], vertices[ii + Y], 0); GL11.glTexCoord2f(vertices[ii + U], vertices[ii + V2]); GL11.glVertex3f(vertices[ii + X], vertices[ii + Y2], 0); GL11.glTexCoord2f(vertices[ii + U2], vertices[ii + V2]); GL11.glVertex3f(vertices[ii + X2], vertices[ii + Y2], 0); GL11.glTexCoord2f(vertices[ii + U2], vertices[ii + V]); GL11.glVertex3f(vertices[ii + X2], vertices[ii + Y], 0); } GL11.glEnd(); } }