From e6e8226e7e7a601b758690593c0930c03c8d1333 Mon Sep 17 00:00:00 2001 From: "nathan.sweet" Date: Sat, 23 Oct 2010 23:06:40 +0000 Subject: [PATCH] [fixed] gdx-twl, wounded by Mario's vicious refactoring. ;) --- .../src/com/badlogic/gdx/twl/renderer/GdxFont.java | 41 +++++++++++++--------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/extensions/twl/gdx-twl/src/com/badlogic/gdx/twl/renderer/GdxFont.java b/extensions/twl/gdx-twl/src/com/badlogic/gdx/twl/renderer/GdxFont.java index 75166b6d4..e389acfae 100644 --- a/extensions/twl/gdx-twl/src/com/badlogic/gdx/twl/renderer/GdxFont.java +++ b/extensions/twl/gdx-twl/src/com/badlogic/gdx/twl/renderer/GdxFont.java @@ -89,15 +89,18 @@ class GdxFont implements Font { } public FontCache cacheText (FontCache cache, CharSequence str, int start, int end) { - if (cache == null) cache = new GdxFontCache(this, str.length()); - return (GdxFontCache)bitmapFont - .cacheText((GdxFontCache)cache, str, 0, 0, com.badlogic.gdx.graphics.Color.WHITE, start, end); + if (cache == null) cache = new GdxFontCache(); + BitmapFontCache bitmapCache = ((GdxFontCache)cache).bitmapCache; + bitmapFont.cacheText(bitmapCache, str, 0, 0, com.badlogic.gdx.graphics.Color.WHITE, start, end); + return cache; } public FontCache cacheMultiLineText (FontCache cache, CharSequence str, int width, de.matthiasmann.twl.HAlignment align) { - if (cache == null) cache = new GdxFontCache(this, str.length()); - return (GdxFontCache)bitmapFont.cacheMultiLineText((GdxFontCache)cache, str, 0, 0, com.badlogic.gdx.graphics.Color.WHITE, - width, HAlignment.values()[align.ordinal()]); + if (cache == null) cache = new GdxFontCache(); + BitmapFontCache bitmapCache = ((GdxFontCache)cache).bitmapCache; + bitmapFont.cacheMultiLineText(bitmapCache, str, 0, 0, com.badlogic.gdx.graphics.Color.WHITE, width, + HAlignment.values()[align.ordinal()]); + return cache; } public void destroy () { @@ -166,21 +169,27 @@ class GdxFont implements Font { } } - static private class GdxFontCache extends BitmapFontCache implements FontCache { - private final GdxFont font; + private class GdxFontCache implements FontCache { + final BitmapFontCache bitmapCache; - public GdxFontCache (GdxFont font, int glyphCount) { - super(font.bitmapFont.getTexture(), glyphCount); - this.font = font; + public GdxFontCache () { + bitmapCache = bitmapFont.newCache(); } public void draw (AnimationState as, int x, int y) { y = Gdx.graphics.getHeight() - y; - GdxFont.FontState fontState = font.evalFontState(as); - TwlRenderer renderer = font.renderer; - setColor(renderer.getColor(fontState.color)); - setPosition(x + fontState.offsetX, y + fontState.offsetY); - draw(renderer.spriteBatch); + GdxFont.FontState fontState = evalFontState(as); + bitmapCache.setColor(renderer.getColor(fontState.color)); + bitmapCache.setPosition(x + fontState.offsetX, y + fontState.offsetY); + bitmapCache.draw(renderer.spriteBatch); + } + + public int getWidth () { + return bitmapCache.getWidth(); + } + + public int getHeight () { + return bitmapCache.getHeight(); } public void destroy () { -- 2.11.0