public float getCursorX () { return textOffset + fontOffset + style.font.getData().cursorX; }
public float getCursorX () { return textOffset + fontOffset + style.font.getData().cursorX; }
private void scaleAndComputePrefSize () { BitmapFont font = cache.getFont(); float oldScaleX = font.getScaleX(); float oldScaleY = font.getScaleY(); if (fontScaleChanged) font.getData().setScale(fontScaleX, fontScaleY); computePrefSize(); if (fontScaleChanged) font.getData().setScale(oldScaleX, oldScaleY); }
private void scaleAndComputePrefSize () { BitmapFont font = cache.getFont(); float oldScaleX = font.getScaleX(); float oldScaleY = font.getScaleY(); if (fontScaleChanged) font.getData().setScale(fontScaleX, fontScaleY); computePrefSize(); if (fontScaleChanged) font.getData().setScale(oldScaleX, oldScaleY); }
protected int letterUnderCursor (float x) { x -= textOffset + fontOffset - style.font.getData().cursorX - glyphPositions.get(visibleTextStart); Drawable background = getBackgroundDrawable(); if (background != null) x -= style.background.getLeftWidth(); int n = this.glyphPositions.size; float[] glyphPositions = this.glyphPositions.items; for (int i = 1; i < n; i++) { if (glyphPositions[i] > x) { if (glyphPositions[i] - x <= x - glyphPositions[i - 1]) return i; return i - 1; } } return n - 1; }
void paste (String content, boolean fireChangeEvent) { if (content == null) return; StringBuilder buffer = new StringBuilder(); int textLength = text.length(); if (hasSelection) textLength -= Math.abs(cursor - selectionStart); BitmapFontData data = style.font.getData(); for (int i = 0, n = content.length(); i < n; i++) { if (!withinMaxLength(textLength + buffer.length())) break; char c = content.charAt(i); if (!(writeEnters && (c == ENTER_ANDROID || c == ENTER_DESKTOP))) { if (c == '\r' || c == '\n') continue; if (onlyFontChars && !data.hasGlyph(c)) continue; if (filter != null && !filter.acceptChar(this, c)) continue; } buffer.append(c); } content = buffer.toString(); if (hasSelection) cursor = delete(fireChangeEvent); if (fireChangeEvent) changeText(text, insert(cursor, content, text)); else text = insert(cursor, content, text); updateDisplayText(); cursor += content.length(); }
protected int letterUnderCursor (float x) { x -= textOffset + fontOffset - style.font.getData().cursorX - glyphPositions.get(visibleTextStart); Drawable background = getBackgroundDrawable(); if (background != null) x -= style.background.getLeftWidth(); int n = this.glyphPositions.size; float[] glyphPositions = this.glyphPositions.items; for (int i = 1; i < n; i++) { if (glyphPositions[i] > x) { if (glyphPositions[i] - x <= x - glyphPositions[i - 1]) return i; return i - 1; } } return n - 1; }
void paste (String content, boolean fireChangeEvent) { if (content == null) return; StringBuilder buffer = new StringBuilder(); int textLength = text.length(); if (hasSelection) textLength -= Math.abs(cursor - selectionStart); BitmapFontData data = style.font.getData(); for (int i = 0, n = content.length(); i < n; i++) { if (!withinMaxLength(textLength + buffer.length())) break; char c = content.charAt(i); if (!(writeEnters && (c == ENTER_ANDROID || c == ENTER_DESKTOP))) { if (c == '\r' || c == '\n') continue; if (onlyFontChars && !data.hasGlyph(c)) continue; if (filter != null && !filter.acceptChar(this, c)) continue; } buffer.append(c); } content = buffer.toString(); if (hasSelection) cursor = delete(fireChangeEvent); if (fireChangeEvent) changeText(text, insert(cursor, content, text)); else text = insert(cursor, content, text); updateDisplayText(); cursor += content.length(); }
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('\ufffd'); cache = bitmapFont.newFontCache(); layout = new GlyphLayout(); } } }
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('\ufffd'); cache = bitmapFont.newFontCache(); layout = new GlyphLayout(); } } }
@Override public void render () { red.a = (red.a + Gdx.graphics.getDeltaTime() * 0.1f) % 1; Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); spriteBatch.begin(); logoSprite.draw(spriteBatch); switch (renderMode) { case 0: font.getData().setScale(1); renderNormal("normal"); break; case 1: font.getData().setScale(1); renderCached(); break; case 2: font.getData().setScale(red.a + 0.5f); renderNormal("normal scaled"); break; case 3: font.getData().setScale(1); renderCachedScaled(); break; } spriteBatch.end(); }
protected void drawCursor (Drawable cursorPatch, Batch batch, BitmapFont font, float x, float y) { cursorPatch.draw(batch, x + textOffset + glyphPositions.get(cursor) - glyphPositions.get(visibleTextStart) + fontOffset + font.getData().cursorX, y - textHeight - font.getDescent(), cursorPatch.getMinWidth(), textHeight); }
protected void drawCursor (Drawable cursorPatch, Batch batch, BitmapFont font, float x, float y) { cursorPatch.draw(batch, x + textOffset + glyphPositions.get(cursor) - glyphPositions.get(visibleTextStart) + fontOffset + font.getData().cursorX, y - textHeight - font.getDescent(), cursorPatch.getMinWidth(), textHeight); }
@Override protected void drawCursor (Drawable cursorPatch, Batch batch, BitmapFont font, float x, float y) { float textOffset = cursor >= glyphPositions.size || cursorLine * 2 >= linesBreak.size ? 0 : glyphPositions.get(cursor) - glyphPositions.get(linesBreak.items[cursorLine * 2]); cursorPatch.draw(batch, x + textOffset + fontOffset + font.getData().cursorX, y - font.getDescent() / 2 - (cursorLine - firstLineShowing + 1) * font.getLineHeight(), cursorPatch.getMinWidth(), font.getLineHeight()); }
@Override protected void drawCursor (Drawable cursorPatch, Batch batch, BitmapFont font, float x, float y) { float textOffset = cursor >= glyphPositions.size || cursorLine * 2 >= linesBreak.size ? 0 : glyphPositions.get(cursor) - glyphPositions.get(linesBreak.items[cursorLine * 2]); cursorPatch.draw(batch, x + textOffset + fontOffset + font.getData().cursorX, y - font.getDescent() / 2 - (cursorLine - firstLineShowing + 1) * font.getLineHeight(), cursorPatch.getMinWidth(), font.getLineHeight()); }
@Override public void create () { spriteBatch = new SpriteBatch(); // font = new BitmapFont(Gdx.files.internal("data/verdana39.fnt"), false); font = new BitmapFont(Gdx.files.internal("data/arial-32-pad.fnt"), false); // font = new FreeTypeFontGenerator(Gdx.files.internal("data/arial.ttf")).generateFont(new FreeTypeFontParameter()); font.getData().markupEnabled = true; font.getData().breakChars = new char[] {'-'}; multiPageFont = new BitmapFont(Gdx.files.internal("data/multipagefont.fnt")); // Add user defined color Colors.put("PERU", Color.valueOf("CD853F")); renderer = new ShapeRenderer(); renderer.setProjectionMatrix(spriteBatch.getProjectionMatrix()); stage = new Stage(new ScreenViewport()); Skin skin = new Skin(Gdx.files.internal("data/uiskin.json")); BitmapFont labelFont = skin.get("default-font", BitmapFont.class); labelFont.getData().markupEnabled = true; // Notice that the last [] has been deliberately added to test the effect of excessive pop operations. // They are silently ignored, as expected. label = new Label("<<[BLUE]M[RED]u[YELLOW]l[GREEN]t[OLIVE]ic[]o[]l[]o[]r[]*[MAROON]Label[][] [Unknown Color]>>", skin); label.setPosition(100, 200); stage.addActor(label); Window window = new Window("[RED]Multicolor[GREEN] Title", skin); window.setPosition(400, 300); window.pack(); stage.addActor(window); layout = new GlyphLayout(); }
font.getData().setScale(scale); layout.setText(font, TEXT); maxWidth = Math.max(maxWidth, layout.width);
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(); } }
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(); } }
@Override public void create () { Gdx.input.setInputProcessor(new InputAdapter() { public boolean touchDown (int x, int y, int pointer, int newParam) { renderMode = (renderMode + 1) % 4; return false; } }); spriteBatch = new SpriteBatch(); spriteBatch.setProjectionMatrix(new Matrix4().setToOrtho(0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), 0, 0, 1)); texture = new Texture(Gdx.files.internal("data/badlogic.jpg")); logoSprite = new Sprite(texture); logoSprite.flip(false, true); logoSprite.setPosition(0, 320 - 256); logoSprite.setColor(1, 1, 1, 0.5f); font = new BitmapFont(Gdx.files.internal("data/verdana39.fnt"), Gdx.files.internal("data/verdana39.png"), true); cache1 = font.newFontCache(); cache2 = font.newFontCache(); cache3 = font.newFontCache(); cache4 = font.newFontCache(); cache5 = font.newFontCache(); createCaches("cached", cache1, cache2, cache3, cache4, cache5); font.getData().setScale(1.33f); cacheScaled1 = font.newFontCache(); cacheScaled2 = font.newFontCache(); cacheScaled3 = font.newFontCache(); cacheScaled4 = font.newFontCache(); cacheScaled5 = font.newFontCache(); createCaches("cache scaled", cacheScaled1, cacheScaled2, cacheScaled3, cacheScaled4, cacheScaled5); }