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