Search in sources :

Example 1 with GlyphLayout

use of com.badlogic.gdx.graphics.g2d.GlyphLayout in project libgdx by libgdx.

the class SelectBox method layout.

@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);
}
Also used : ListStyle(com.badlogic.gdx.scenes.scene2d.ui.List.ListStyle) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) GlyphLayout(com.badlogic.gdx.graphics.g2d.GlyphLayout) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) ScrollPaneStyle(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane.ScrollPaneStyle)

Example 2 with GlyphLayout

use of com.badlogic.gdx.graphics.g2d.GlyphLayout in project libgdx by libgdx.

the class TextArea method calculateOffsets.

@Override
protected void calculateOffsets() {
    super.calculateOffsets();
    if (!this.text.equals(lastText)) {
        this.lastText = text;
        BitmapFont font = style.font;
        float maxWidthLine = this.getWidth() - (style.background != null ? style.background.getLeftWidth() + style.background.getRightWidth() : 0);
        linesBreak.clear();
        int lineStart = 0;
        int lastSpace = 0;
        char lastCharacter;
        Pool<GlyphLayout> layoutPool = Pools.get(GlyphLayout.class);
        GlyphLayout layout = layoutPool.obtain();
        for (int i = 0; i < text.length(); i++) {
            lastCharacter = text.charAt(i);
            if (lastCharacter == ENTER_DESKTOP || lastCharacter == ENTER_ANDROID) {
                linesBreak.add(lineStart);
                linesBreak.add(i);
                lineStart = i + 1;
            } else {
                lastSpace = (continueCursor(i, 0) ? lastSpace : i);
                layout.setText(font, text.subSequence(lineStart, i + 1));
                if (layout.width > maxWidthLine) {
                    if (lineStart >= lastSpace) {
                        lastSpace = i - 1;
                    }
                    linesBreak.add(lineStart);
                    linesBreak.add(lastSpace + 1);
                    lineStart = lastSpace + 1;
                    lastSpace = lineStart;
                }
            }
        }
        layoutPool.free(layout);
        // Add last line
        if (lineStart < text.length()) {
            linesBreak.add(lineStart);
            linesBreak.add(text.length());
        }
        showCursor();
    }
}
Also used : GlyphLayout(com.badlogic.gdx.graphics.g2d.GlyphLayout) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 3 with GlyphLayout

use of com.badlogic.gdx.graphics.g2d.GlyphLayout in project libgdx by libgdx.

the class Label method layout.

public void layout() {
    BitmapFont font = cache.getFont();
    float oldScaleX = font.getScaleX();
    float oldScaleY = font.getScaleY();
    if (fontScaleChanged)
        font.getData().setScale(fontScaleX, fontScaleY);
    boolean wrap = this.wrap && ellipsis == null;
    if (wrap) {
        float prefHeight = getPrefHeight();
        if (prefHeight != lastPrefHeight) {
            lastPrefHeight = prefHeight;
            invalidateHierarchy();
        }
    }
    float width = getWidth(), height = getHeight();
    Drawable background = style.background;
    float x = 0, y = 0;
    if (background != null) {
        x = background.getLeftWidth();
        y = background.getBottomHeight();
        width -= background.getLeftWidth() + background.getRightWidth();
        height -= background.getBottomHeight() + background.getTopHeight();
    }
    GlyphLayout layout = this.layout;
    float textWidth, textHeight;
    if (wrap || text.indexOf("\n") != -1) {
        // If the text can span multiple lines, determine the text's actual size so it can be aligned within the label.
        layout.setText(font, text, 0, text.length, Color.WHITE, width, lineAlign, wrap, ellipsis);
        textWidth = layout.width;
        textHeight = layout.height;
        if ((labelAlign & Align.left) == 0) {
            if ((labelAlign & Align.right) != 0)
                x += width - textWidth;
            else
                x += (width - textWidth) / 2;
        }
    } else {
        textWidth = width;
        textHeight = font.getData().capHeight;
    }
    if ((labelAlign & Align.top) != 0) {
        y += cache.getFont().isFlipped() ? 0 : height - textHeight;
        y += style.font.getDescent();
    } else if ((labelAlign & Align.bottom) != 0) {
        y += cache.getFont().isFlipped() ? height - textHeight : 0;
        y -= style.font.getDescent();
    } else {
        y += (height - textHeight) / 2;
    }
    if (!cache.getFont().isFlipped())
        y += textHeight;
    layout.setText(font, text, 0, text.length, Color.WHITE, textWidth, lineAlign, wrap, ellipsis);
    cache.setText(layout, x, y);
    if (fontScaleChanged)
        font.getData().setScale(oldScaleX, oldScaleY);
}
Also used : Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) GlyphLayout(com.badlogic.gdx.graphics.g2d.GlyphLayout) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 4 with GlyphLayout

use of com.badlogic.gdx.graphics.g2d.GlyphLayout in project libgdx by libgdx.

the class Label method computePrefSize.

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);
}
Also used : GlyphLayout(com.badlogic.gdx.graphics.g2d.GlyphLayout)

Example 5 with GlyphLayout

use of com.badlogic.gdx.graphics.g2d.GlyphLayout in project libgdx by libgdx.

the class UnicodeFont method setRenderType.

public void setRenderType(RenderType renderType) {
    this.renderType = renderType;
    if (renderType != RenderType.FreeType) {
        if (bitmapFont != null) {
            bitmapFont.dispose();
            generator.dispose();
        }
    } else {
        String fontFile = getFontFile();
        if (fontFile != null) {
            generator = new FreeTypeFontGenerator(Gdx.files.absolute(fontFile));
            FreeTypeFontParameter param = new FreeTypeFontParameter();
            param.size = font.getSize();
            param.incremental = true;
            param.flip = true;
            param.mono = mono;
            param.gamma = gamma;
            bitmapFont = generator.generateFont(param);
            if (bitmapFont.getData().missingGlyph == null)
                bitmapFont.getData().missingGlyph = bitmapFont.getData().getGlyph('�');
            cache = bitmapFont.newFontCache();
            layout = new GlyphLayout();
        }
    }
}
Also used : FreeTypeFontGenerator(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator) FreeTypeFontParameter(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter) GlyphLayout(com.badlogic.gdx.graphics.g2d.GlyphLayout)

Aggregations

GlyphLayout (com.badlogic.gdx.graphics.g2d.GlyphLayout)24 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)8 Drawable (com.badlogic.gdx.scenes.scene2d.utils.Drawable)5 Color (com.badlogic.gdx.graphics.Color)2 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)2 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)2 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)2 ListStyle (com.badlogic.gdx.scenes.scene2d.ui.List.ListStyle)2 ScrollPaneStyle (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane.ScrollPaneStyle)2 ReverseListIterator (org.apache.commons.collections.iterators.ReverseListIterator)2 InputAdapter (com.badlogic.gdx.InputAdapter)1 FileHandle (com.badlogic.gdx.files.FileHandle)1 Texture (com.badlogic.gdx.graphics.Texture)1 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)1 FreeTypeFontGenerator (com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator)1 FreeTypeFontParameter (com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter)1 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)1 Stage (com.badlogic.gdx.scenes.scene2d.Stage)1 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)1 Window (com.badlogic.gdx.scenes.scene2d.ui.Window)1