public void setStyle (TextFieldStyle style) { if (style == null) throw new IllegalArgumentException("style cannot be null."); this.style = style; textHeight = style.font.getCapHeight() - style.font.getDescent() * 2; invalidateHierarchy(); }
public void setStyle (TextFieldStyle style) { if (style == null) throw new IllegalArgumentException("style cannot be null."); this.style = style; textHeight = style.font.getCapHeight() - style.font.getDescent() * 2; invalidateHierarchy(); }
@Override public void render () { Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); stage.act(Math.min(Gdx.graphics.getDeltaTime(), 1 / 30f)); stage.draw(); float x = 40, y = 15 + 20 * scale; BitmapFont font = skin.getFont("default-font"); batch.begin(); font.draw(batch, "The quick brown fox jumped over the lazy cow.", x, y); batch.end(); drawLine(x, y - font.getDescent(), x + 1000, y - font.getDescent()); drawLine(x, y - font.getCapHeight() + font.getDescent(), x + 1000, y - font.getCapHeight() + font.getDescent()); }
@Override public void layout () { Drawable bg = style.background; BitmapFont font = style.font; if (bg != null) { prefHeight = Math.max(bg.getTopHeight() + bg.getBottomHeight() + font.getCapHeight() - font.getDescent() * 2, bg.getMinHeight()); } else prefHeight = font.getCapHeight() - font.getDescent() * 2; float maxItemWidth = 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))); maxItemWidth = Math.max(layout.width, maxItemWidth); } layoutPool.free(layout); prefWidth = maxItemWidth; if (bg != null) prefWidth += bg.getLeftWidth() + bg.getRightWidth(); ListStyle listStyle = style.listStyle; ScrollPaneStyle scrollStyle = style.scrollStyle; float listWidth = maxItemWidth + listStyle.selection.getLeftWidth() + listStyle.selection.getRightWidth(); if (scrollStyle.background != null) listWidth += scrollStyle.background.getLeftWidth() + scrollStyle.background.getRightWidth(); if (selectBoxList == null || !selectBoxList.disableY) listWidth += Math.max(style.scrollStyle.vScroll != null ? style.scrollStyle.vScroll.getMinWidth() : 0, style.scrollStyle.vScrollKnob != null ? style.scrollStyle.vScrollKnob.getMinWidth() : 0); prefWidth = Math.max(prefWidth, listWidth); }
@Override public void layout () { Drawable bg = style.background; BitmapFont font = style.font; if (bg != null) { prefHeight = Math.max(bg.getTopHeight() + bg.getBottomHeight() + font.getCapHeight() - font.getDescent() * 2, bg.getMinHeight()); } else prefHeight = font.getCapHeight() - font.getDescent() * 2; float maxItemWidth = 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))); maxItemWidth = Math.max(layout.width, maxItemWidth); } layoutPool.free(layout); prefWidth = maxItemWidth; if (bg != null) prefWidth += bg.getLeftWidth() + bg.getRightWidth(); ListStyle listStyle = style.listStyle; ScrollPaneStyle scrollStyle = style.scrollStyle; float listWidth = maxItemWidth + listStyle.selection.getLeftWidth() + listStyle.selection.getRightWidth(); if (scrollStyle.background != null) listWidth += scrollStyle.background.getLeftWidth() + scrollStyle.background.getRightWidth(); if (selectBoxList == null || !selectBoxList.disableY) listWidth += Math.max(style.scrollStyle.vScroll != null ? style.scrollStyle.vScroll.getMinWidth() : 0, style.scrollStyle.vScrollKnob != null ? style.scrollStyle.vScrollKnob.getMinWidth() : 0); prefWidth = Math.max(prefWidth, listWidth); }
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(); } }
final float capHeight = generatedFont.getCapHeight(); final float lineHeight = generatedFont.getLineHeight(); final float spaceXadvance = generatedFont.getSpaceXadvance(); final float loadedFontcapHeight = loadedFont.getCapHeight(); final float loadedFontlineHeight = loadedFont.getLineHeight(); final float loadedFontspaceXadvance = loadedFont.getSpaceXadvance();
@Override public void render () { Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); camera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); batch.setProjectionMatrix(camera.combined); batch.begin(); float x = 10; float y = Gdx.graphics.getHeight() - 10; int renderCalls = 0; // NOTE: Before production release on mobile, you should cache the array from values() // inside the Enum in order to reduce allocations in the render loop. for (FontStyle style : FontStyle.values()) { for (FontSize size : FontSize.values()) { BitmapFont fnt = getFont(style, size); fnt.draw(batch, style.name() + " " + size.size + "pt: The quick brown fox jumps over the lazy dog", x, y); y -= fnt.getLineHeight() + 10; } y -= 20; } BitmapFont font = getFont(FontStyle.Regular, FontSize.Medium); font.draw(batch, text, 10, font.getCapHeight() + 10); // draw all glyphs in background batch.setColor(1f, 1f, 1f, 0.15f); batch.draw(regions.first(), 0, 0); batch.setColor(1f, 1f, 1f, 1f); batch.end(); }
@Override public void render() { Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); camera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); batch.setProjectionMatrix(camera.combined); batch.begin(); float x = 10; float y = Gdx.graphics.getHeight() - 10; int renderCalls = 0; // NOTE: Before production release on mobile, you should cache the array from values() // inside the Enum in order to reduce allocations in the render loop. for (FontStyle style : FontStyle.values()) { for (FontSize size : FontSize.values()) { BitmapFont fnt = getFont(style, size); fnt.draw(batch, style.name() + " " + size.size + "pt: The quick brown fox jumps over the lazy dog", x, y); y -= fnt.getLineHeight() + 10; } y -= 20; } BitmapFont font = getFont(FontStyle.Regular, FontSize.Medium); font.draw(batch, text, 10, font.getCapHeight() + 10); // draw all glyphs in background batch.setColor(1f, 1f, 1f, 0.15f); batch.draw(packer.getPages().first().getTexture(), 0, 0); batch.setColor(1f, 1f, 1f, 1f); batch.end(); }
if (scaledSize != -1) font.getData().setScale(scaledSize / font.getCapHeight()); return font; } catch (RuntimeException ex) {
if (scaledSize != -1) font.getData().setScale(scaledSize / font.getCapHeight()); return font; } catch (RuntimeException ex) {
private void renderFontWithMetrics (BitmapFont font, String text, float x, float y) { float alignmentWidth; spriteBatch.begin(); GlyphLayout layout = font.draw(spriteBatch, text, x, y); spriteBatch.end(); renderer.begin(ShapeRenderer.ShapeType.Filled); renderer.setColor(Color.BLACK); renderer.rect(x - 3, y - 3, 6, 6); renderer.end(); float baseline = y - font.getCapHeight(); renderer.begin(ShapeRenderer.ShapeType.Line); renderer.setColor(Color.LIGHT_GRAY); renderer.line(0, y, 9999, y); renderer.setColor(Color.MAGENTA); renderer.line(0, baseline, 9999, baseline); renderer.setColor(Color.GREEN); renderer.line(0, baseline + font.getXHeight(), 9999, baseline + font.getXHeight()); renderer.setColor(Color.CYAN); renderer.line(0, y + font.getAscent(), 9999, y + font.getAscent()); renderer.setColor(Color.RED); renderer.line(0, baseline + font.getDescent(), 9999, baseline + font.getDescent()); renderer.setColor(Color.ORANGE); renderer.line(0, y - font.getLineHeight(), 9999, y - font.getLineHeight()); renderer.end(); renderer.begin(ShapeRenderer.ShapeType.Line); renderer.setColor(Color.BLUE); renderer.rect(x, y, layout.width, -layout.height); renderer.end(); }
renderer.end(); float baseline = y - font.getCapHeight(); renderer.begin(ShapeType.Line); renderer.setColor(Color.LIGHT_GRAY);
renderer.end(); float baseline = y - font.getCapHeight(); renderer.begin(ShapeType.Line); renderer.setColor(Color.LIGHT_GRAY);
public void setStyle (VisTextFieldStyle style) { if (style == null) throw new IllegalArgumentException("style cannot be null."); this.style = style; textHeight = style.font.getCapHeight() - style.font.getDescent() * 2; invalidateHierarchy(); }
public void setStyle (TextFieldStyle style) { if (style == null) throw new IllegalArgumentException("style cannot be null."); this.style = style; textHeight = style.font.getCapHeight() - style.font.getDescent() * 2; invalidateHierarchy(); }
public void setStyle(TextFieldStyle style) { if (style == null) throw new IllegalArgumentException("style cannot be null."); this.style = style; textHeight = style.font.getCapHeight() - style.font.getDescent() * 2; invalidateHierarchy(); }
public void drawString(String text, int x, int y) { beginBatch(); drawFont(text, x, y - font.getFont().getCapHeight()); }
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(); }