OSDN Git Service

[fixed] LWJGL not having Gdx.gl* set.
authornathan.sweet <nathan.sweet@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Sun, 24 Oct 2010 07:46:10 +0000 (07:46 +0000)
committernathan.sweet <nathan.sweet@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Sun, 24 Oct 2010 07:46:10 +0000 (07:46 +0000)
[changed] Bunch of code to use Gdx.gl* rather than getGL*().
[changed] gdx-twl uses SpriteBatch for images. TextAreaTest is still fubar.
[fixed] gdx-twl uses the flipped y-coordinate system TWL expects.
[added] Method to SpriteBatch that takes precomputed tex coords and color. SpriteBatch methods need clean up?
[changed] BitmapFont computes glyph tex coords up front and supports being used with a flipped y-coordinate system.
[added] BitmapFontFlipTest to test flipped y-coordinate system.
[added] getColor to Sprite.

28 files changed:
backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/desktop/LwjglGraphics.java
extensions/twl/gdx-twl-tests/src/com/badlogic/gdx/twl/tests/ButtonTest.java [new file with mode: 0644]
extensions/twl/gdx-twl-tests/src/com/badlogic/gdx/twl/tests/ButtonTestDesktop.java [new file with mode: 0644]
extensions/twl/gdx-twl-tests/src/com/badlogic/gdx/twl/tests/TextAreaTest.java
extensions/twl/gdx-twl/src/com/badlogic/gdx/twl/renderer/GdxCacheContext.java
extensions/twl/gdx-twl/src/com/badlogic/gdx/twl/renderer/GdxFont.java
extensions/twl/gdx-twl/src/com/badlogic/gdx/twl/renderer/GdxImage.java [new file with mode: 0644]
extensions/twl/gdx-twl/src/com/badlogic/gdx/twl/renderer/GdxTexture.java
extensions/twl/gdx-twl/src/com/badlogic/gdx/twl/renderer/TextureArea.java [deleted file]
extensions/twl/gdx-twl/src/com/badlogic/gdx/twl/renderer/TextureAreaBase.java [deleted file]
extensions/twl/gdx-twl/src/com/badlogic/gdx/twl/renderer/TwlInputListener.java
extensions/twl/gdx-twl/src/com/badlogic/gdx/twl/renderer/TwlRenderer.java
gdx/src/com/badlogic/gdx/graphics/BitmapFont.java
gdx/src/com/badlogic/gdx/graphics/BitmapFontCache.java
gdx/src/com/badlogic/gdx/graphics/ImmediateModeRenderer.java
gdx/src/com/badlogic/gdx/graphics/Mesh.java
gdx/src/com/badlogic/gdx/graphics/OrthographicCamera.java
gdx/src/com/badlogic/gdx/graphics/PerspectiveCamera.java
gdx/src/com/badlogic/gdx/graphics/Sprite.java
gdx/src/com/badlogic/gdx/graphics/SpriteBatch.java
tests/gdx-tests-android/AndroidManifest.xml
tests/gdx-tests-android/src/com/badlogic/gdx/BitmapFontFlipTest.java [new file with mode: 0644]
tests/gdx-tests-android/src/com/badlogic/gdx/GDXTester.java
tests/gdx-tests-desktop/src/com/badlogic/gdx/tests/desktop/BitmapFontFlipTest.java [new file with mode: 0644]
tests/gdx-tests-desktop/src/com/badlogic/gdx/tests/desktop/BitmapFontTest.java
tests/gdx-tests-lwjgl/src/com/badlogic/gdx/tests/lwjgl/BitmapFontFlipTest.java [new file with mode: 0644]
tests/gdx-tests/src/com/badlogic/gdx/tests/BitmapFontFlipTest.java [new file with mode: 0644]
tests/gdx-tests/src/com/badlogic/gdx/tests/BitmapFontTest.java

index 350213f..ea93b58 100644 (file)
@@ -19,6 +19,7 @@ import java.io.InputStream;
 \r
 import javax.imageio.ImageIO;\r
 \r
+import com.badlogic.gdx.Gdx;\r
 import com.badlogic.gdx.GdxRuntimeException;\r
 import com.badlogic.gdx.Graphics;\r
 import com.badlogic.gdx.RenderListener;\r
@@ -201,6 +202,11 @@ public final class LwjglGraphics implements Graphics, RenderListener {
                        gl = gl10;\r
                }\r
 \r
+               Gdx.gl = gl;\r
+               Gdx.gl10 = gl10;\r
+               Gdx.gl11 = gl11;\r
+               Gdx.gl20 = gl20;\r
+\r
                lastTime = System.nanoTime();\r
        }\r
 \r
diff --git a/extensions/twl/gdx-twl-tests/src/com/badlogic/gdx/twl/tests/ButtonTest.java b/extensions/twl/gdx-twl-tests/src/com/badlogic/gdx/twl/tests/ButtonTest.java
new file mode 100644 (file)
index 0000000..e958542
--- /dev/null
@@ -0,0 +1,52 @@
+\r
+package com.badlogic.gdx.twl.tests;\r
+\r
+import com.badlogic.gdx.Files.FileType;\r
+import com.badlogic.gdx.Gdx;\r
+import com.badlogic.gdx.RenderListener;\r
+import com.badlogic.gdx.graphics.GL10;\r
+import com.badlogic.gdx.twl.renderer.TwlRenderer;\r
+\r
+import de.matthiasmann.twl.Button;\r
+import de.matthiasmann.twl.DialogLayout;\r
+import de.matthiasmann.twl.FPSCounter;\r
+import de.matthiasmann.twl.GUI;\r
+import de.matthiasmann.twl.ScrollPane;\r
+import de.matthiasmann.twl.TextArea;\r
+import de.matthiasmann.twl.Timer;\r
+import de.matthiasmann.twl.textarea.HTMLTextAreaModel;\r
+import de.matthiasmann.twl.textarea.Style;\r
+import de.matthiasmann.twl.textarea.StyleAttribute;\r
+import de.matthiasmann.twl.textarea.TextAreaModel.Element;\r
+import de.matthiasmann.twl.textarea.Value;\r
+\r
+public class ButtonTest implements RenderListener {\r
+       GUI gui;\r
+\r
+       public void surfaceCreated () {\r
+               if (gui != null) return;\r
+\r
+               Button button = new Button("Click Me");\r
+               FPSCounter fpsCounter = new FPSCounter(4, 2);\r
+\r
+               DialogLayout layout = new DialogLayout();\r
+               layout.setTheme("");\r
+               layout.setHorizontalGroup(layout.createParallelGroup().addWidgets(button, fpsCounter));\r
+               layout.setVerticalGroup(layout.createSequentialGroup().addWidget(button).addGap(5).addWidget(fpsCounter).addGap(5));\r
+\r
+               gui = TwlRenderer.createGUI(layout, Gdx.files.getFileHandle("data/widgets.xml", FileType.Internal));\r
+       }\r
+\r
+       public void render () {\r
+               Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);\r
+               gui.update();\r
+       }\r
+\r
+       public void surfaceChanged (int width, int height) {\r
+               gui.setSize();\r
+       }\r
+\r
+       public void dispose () {\r
+               gui.destroy();\r
+       }\r
+}\r
diff --git a/extensions/twl/gdx-twl-tests/src/com/badlogic/gdx/twl/tests/ButtonTestDesktop.java b/extensions/twl/gdx-twl-tests/src/com/badlogic/gdx/twl/tests/ButtonTestDesktop.java
new file mode 100644 (file)
index 0000000..3b30509
--- /dev/null
@@ -0,0 +1,11 @@
+\r
+package com.badlogic.gdx.twl.tests;\r
+\r
+import com.badlogic.gdx.backends.desktop.JoglApplication;\r
+\r
+public class ButtonTestDesktop {\r
+       public static void main (String[] argv) {\r
+               JoglApplication app = new JoglApplication("Button Test", 480, 320, false);\r
+               app.getGraphics().setRenderListener(new ButtonTest());\r
+       }\r
+}\r
index 4cb1646..4c48f9d 100644 (file)
@@ -70,7 +70,7 @@ public class TextAreaTest implements RenderListener {
        }\r
 \r
        public void render () {\r
-               Gdx.graphics.getGL10().glClear(GL10.GL_COLOR_BUFFER_BIT);\r
+               Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);\r
                gui.update();\r
        }\r
 \r
index cc2bf39..b9d98ae 100644 (file)
@@ -37,15 +37,15 @@ import de.matthiasmann.twl.renderer.CacheContext;
 
 class GdxCacheContext implements CacheContext {
        final TwlRenderer renderer;
-       final HashMap<String, GdxTexture> textures = new HashMap();
-       final HashMap<String, BitmapFont> fonts = new HashMap();
-       boolean valid = true;
+       private final HashMap<String, GdxTexture> textures = new HashMap();
+       private final HashMap<String, BitmapFont> fonts = new HashMap();
+       private boolean valid = true;
 
        GdxCacheContext (TwlRenderer renderer) {
                this.renderer = renderer;
        }
 
-       // BOZO - This URL stuff sucks.
+       // BOZO - This URL stuff sucks. Look at URLStreamHandler.
 
        GdxTexture loadTexture (URL url) throws IOException {
                String urlString = url.toString();
@@ -81,7 +81,7 @@ class GdxCacheContext implements CacheContext {
                        String textureFile = fontFile.endsWith(".fnt") ? fontFile.substring(0, fontFile.length() - 3) + "png" : fontFile
                                + ".png";
                        bitmapFont = new BitmapFont(Gdx.files.getFileHandle(fontFile, FileType.Internal), Gdx.files.getFileHandle(textureFile,
-                               FileType.Internal));
+                               FileType.Internal), true);
                        fonts.put(urlString, bitmapFont);
                }
                return bitmapFont;
index 3fa8256..7ef9641 100644 (file)
@@ -46,10 +46,13 @@ class GdxFont implements Font {
        final TwlRenderer renderer;
        final BitmapFont bitmapFont;
        private final FontState[] fontStates;
+       private final int yOffset;
 
        public GdxFont (TwlRenderer renderer, BitmapFont bitmapFont, Map<String, String> params, Collection<FontParameter> condParams) {
                this.bitmapFont = bitmapFont;
                this.renderer = renderer;
+               yOffset = bitmapFont.getLineHeight() - bitmapFont.getBaseLine();
+
                ArrayList<FontState> states = new ArrayList<FontState>();
                for (FontParameter p : condParams) {
                        HashMap<String, String> effective = new HashMap<String, String>(params);
@@ -65,20 +68,18 @@ class GdxFont implements Font {
        }
 
        public int drawText (AnimationState as, int x, int y, CharSequence str, int start, int end) {
-               y = Gdx.graphics.getHeight() - y;
                FontState fontState = evalFontState(as);
                x += fontState.offsetX;
-               y += fontState.offsetY;
+               y += fontState.offsetY + yOffset;
                com.badlogic.gdx.graphics.Color color = renderer.getColor(fontState.color);
                return bitmapFont.draw(renderer.spriteBatch, str, x, y, color);
        }
 
        public int drawMultiLineText (AnimationState as, int x, int y, CharSequence str, int width,
                de.matthiasmann.twl.HAlignment align) {
-               y = Gdx.graphics.getHeight() - y;
                FontState fontState = evalFontState(as);
                x += fontState.offsetX;
-               y += fontState.offsetY;
+               y += fontState.offsetY + yOffset;
                com.badlogic.gdx.graphics.Color color = renderer.getColor(fontState.color);
                return bitmapFont.drawMultiLineText(renderer.spriteBatch, str, x, y, color, width, HAlignment.values()[align.ordinal()]);
        }
@@ -90,14 +91,14 @@ class GdxFont implements Font {
        public FontCache cacheText (FontCache cache, CharSequence str, int start, int 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);
+               bitmapFont.cacheText(bitmapCache, str, 0, yOffset, 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();
                BitmapFontCache bitmapCache = ((GdxFontCache)cache).bitmapCache;
-               bitmapFont.cacheMultiLineText(bitmapCache, str, 0, 0, com.badlogic.gdx.graphics.Color.WHITE, width,
+               bitmapFont.cacheMultiLineText(bitmapCache, str, 0, yOffset, com.badlogic.gdx.graphics.Color.WHITE, width,
                        HAlignment.values()[align.ordinal()]);
                return cache;
        }
@@ -119,11 +120,11 @@ class GdxFont implements Font {
        }
 
        public int getEM () {
-               return bitmapFont.getEM();
+               return bitmapFont.getLineHeight();
        }
 
        public int getEX () {
-               return bitmapFont.getEX();
+               return bitmapFont.getXHeight();
        }
 
        public int computeMultiLineTextWidth (CharSequence str) {
@@ -176,7 +177,6 @@ class GdxFont implements Font {
                }
 
                public void draw (AnimationState as, int x, int y) {
-                       y = Gdx.graphics.getHeight() - y;
                        GdxFont.FontState fontState = evalFontState(as);
                        bitmapCache.setColor(renderer.getColor(fontState.color));
                        bitmapCache.setPosition(x + fontState.offsetX, y + fontState.offsetY);
diff --git a/extensions/twl/gdx-twl/src/com/badlogic/gdx/twl/renderer/GdxImage.java b/extensions/twl/gdx-twl/src/com/badlogic/gdx/twl/renderer/GdxImage.java
new file mode 100644 (file)
index 0000000..0bf64d6
--- /dev/null
@@ -0,0 +1,150 @@
+\r
+package com.badlogic.gdx.twl.renderer;\r
+\r
+import com.badlogic.gdx.graphics.Sprite;\r
+import com.badlogic.gdx.graphics.Texture;\r
+\r
+import de.matthiasmann.twl.Color;\r
+import de.matthiasmann.twl.renderer.AnimationState;\r
+import de.matthiasmann.twl.renderer.Image;\r
+import de.matthiasmann.twl.renderer.SupportsDrawRepeat;\r
+\r
+class GdxImage implements Image, SupportsDrawRepeat {\r
+       private final TwlRenderer renderer;\r
+       private final Sprite sprite;\r
+       private final Color tintColor;\r
+       private final int width;\r
+       private final int height;\r
+       private final boolean tile;\r
+\r
+       public GdxImage (TwlRenderer renderer, Texture texture, int srcX, int srcY, int srcWidth, int srcHeight, Color color,\r
+               boolean tile) {\r
+               this.renderer = renderer;\r
+               width = Math.abs(srcWidth);\r
+               height = Math.abs(srcHeight);\r
+               this.tintColor = color == null ? Color.WHITE : color;\r
+               this.tile = tile;\r
+               sprite = new Sprite(texture, srcX, srcY, srcWidth, srcHeight);\r
+               sprite.flip(false, true);\r
+       }\r
+\r
+       public GdxImage (GdxImage image, Color tintColor) {\r
+               renderer = image.renderer;\r
+               width = image.width;\r
+               height = image.height;\r
+               sprite = image.sprite;\r
+               this.tintColor = tintColor;\r
+               tile = image.tile;\r
+       }\r
+\r
+       public void draw (AnimationState as, int x, int y) {\r
+               sprite.setColor(tintColor.getRedFloat(), tintColor.getGreenFloat(), tintColor.getBlueFloat(), tintColor.getAlphaFloat());\r
+               if (tile) {\r
+                       drawTiled(x, y, width, height);\r
+               } else {\r
+                       sprite.setBounds(x, y, width, height);\r
+                       sprite.draw(renderer.spriteBatch);\r
+               }\r
+       }\r
+\r
+       public void draw (AnimationState as, int x, int y, int width, int height) {\r
+               sprite.setColor(tintColor.getRedFloat(), tintColor.getGreenFloat(), tintColor.getBlueFloat(), tintColor.getAlphaFloat());\r
+               if (tile) {\r
+                       drawTiled(x, y, width, height);\r
+               } else {\r
+                       sprite.setBounds(x, y, width, height);\r
+                       sprite.draw(renderer.spriteBatch);\r
+               }\r
+       }\r
+\r
+       public void draw (AnimationState as, int x, int y, int width, int height, int repeatCountX, int repeatCountY) {\r
+               sprite.setColor(tintColor.getRedFloat(), tintColor.getGreenFloat(), tintColor.getBlueFloat(), tintColor.getAlphaFloat());\r
+               if (repeatCountX * this.width != width || repeatCountY * this.height != height)\r
+                       drawRepeatSlow(x, y, width, height, repeatCountX, repeatCountY);\r
+               else\r
+                       drawRepeat(x, y, repeatCountX, repeatCountY);\r
+       }\r
+\r
+       private void drawRepeatSlow (int x, int y, int width, int height, int repeatCountX, int repeatCountY) {\r
+               while (repeatCountY > 0) {\r
+                       int rowHeight = height / repeatCountY;\r
+\r
+                       int cx = 0;\r
+                       int xi = 0;\r
+                       while (xi < repeatCountX) {\r
+                               int nx = ++xi * width / repeatCountX;\r
+                               sprite.setBounds(x + cx, y, nx - cx, rowHeight);\r
+                               sprite.draw(renderer.spriteBatch);\r
+                               cx = nx;\r
+                       }\r
+\r
+                       y += rowHeight;\r
+                       height -= rowHeight;\r
+                       repeatCountY--;\r
+               }\r
+       }\r
+\r
+       private void drawRepeat (int x, int y, int repeatCountX, int repeatCountY) {\r
+               final int w = width;\r
+               final int h = height;\r
+               while (repeatCountY-- > 0) {\r
+                       int curX = x;\r
+                       int cntX = repeatCountX;\r
+                       while (cntX-- > 0) {\r
+                               sprite.setBounds(curX, y, w, h);\r
+                               sprite.draw(renderer.spriteBatch);\r
+                               curX += w;\r
+                       }\r
+                       y += h;\r
+               }\r
+       }\r
+\r
+       private void drawTiled (int x, int y, int width, int height) {\r
+               int repeatCountX = width / this.width;\r
+               int repeatCountY = height / this.height;\r
+\r
+               drawRepeat(x, y, repeatCountX, repeatCountY);\r
+\r
+               int drawnX = repeatCountX * this.width;\r
+               int drawnY = repeatCountY * this.height;\r
+               int restWidth = width - drawnX;\r
+               int restHeight = height - drawnY;\r
+               if (restWidth > 0 || restHeight > 0) {\r
+                       if (restWidth > 0 && repeatCountY > 0) drawClipped(x + drawnX, y, restWidth, this.height, 1, repeatCountY);\r
+                       if (restHeight > 0) {\r
+                               if (repeatCountX > 0) drawClipped(x, y + drawnY, this.width, restHeight, repeatCountX, 1);\r
+                               if (restWidth > 0) drawClipped(x + drawnX, y + drawnY, restWidth, restHeight, 1, 1);\r
+                       }\r
+               }\r
+       }\r
+\r
+       private void drawClipped (int x, int y, int width, int height, int repeatCountX, int repeatCountY) {\r
+               while (repeatCountY-- > 0) {\r
+                       int y1 = y + height;\r
+                       int x0 = x;\r
+                       int cx = repeatCountX;\r
+                       while (cx-- > 0) {\r
+                               int x1 = x0 + width;\r
+                               sprite.setBounds(x0, y, x1, y1);\r
+                               sprite.draw(renderer.spriteBatch);\r
+                               x0 = x1;\r
+                       }\r
+                       y = y1;\r
+               }\r
+       }\r
+\r
+       public Image createTintedVersion (Color color) {\r
+               if (color == null) throw new IllegalArgumentException("color cannot be null.");\r
+               color = tintColor.multiply(color);\r
+               if (tintColor.equals(color)) return this;\r
+               return new GdxImage(this, color);\r
+       }\r
+\r
+       public int getWidth () {\r
+               return width;\r
+       }\r
+\r
+       public int getHeight () {\r
+               return height;\r
+       }\r
+}\r
index df86b69..a20e422 100644 (file)
@@ -24,7 +24,6 @@ package com.badlogic.gdx.twl.renderer;
 
 import com.badlogic.gdx.Files.FileType;
 import com.badlogic.gdx.Gdx;
-import com.badlogic.gdx.graphics.GL10;
 import com.badlogic.gdx.graphics.Texture.TextureFilter;
 import com.badlogic.gdx.graphics.Texture.TextureWrap;
 
@@ -35,18 +34,8 @@ import de.matthiasmann.twl.renderer.Resource;
 import de.matthiasmann.twl.renderer.Texture;
 
 class GdxTexture implements Texture, Resource {
-       public enum Filter {
-               NEAREST(GL10.GL_NEAREST), LINEAR(GL10.GL_LINEAR);
-
-               final int glValue;
-
-               Filter (int value) {
-                       this.glValue = value;
-               }
-       }
-
-       final TwlRenderer renderer;
-       final com.badlogic.gdx.graphics.Texture texture;
+       private final TwlRenderer renderer;
+       private final com.badlogic.gdx.graphics.Texture texture;
 
        public GdxTexture (TwlRenderer renderer, String path) {
                this.renderer = renderer;
@@ -55,53 +44,32 @@ class GdxTexture implements Texture, Resource {
                        TextureFilter.Linear, TextureWrap.ClampToEdge, TextureWrap.ClampToEdge);
        }
 
-       public void destroy () {
-               texture.dispose();
-       }
-
-       public int getWidth () {
-               return texture.getWidth();
-       }
-
-       public int getHeight () {
-               return texture.getHeight();
+       public Image getImage (int x, int y, int width, int height, Color tintColor, boolean tiled) {
+               if (x < 0 || x >= getWidth()) throw new IllegalArgumentException("x");
+               if (y < 0 || y >= getHeight()) throw new IllegalArgumentException("y");
+               if (x + Math.abs(width) > getWidth()) throw new IllegalArgumentException("width");
+               if (y + Math.abs(height) > getHeight()) throw new IllegalArgumentException("height");
+               if (tiled && (width <= 0 || height <= 0))
+                       throw new IllegalArgumentException("Tiled rendering requires positive width & height.");
+               return new GdxImage(renderer, texture, x, y, width, height, tintColor, tiled);
        }
 
-       // BOZO
-       boolean bind (Color color) {
-               texture.bind();
-               // renderer.tintStack.setColor(color);
-               return true;
+       public MouseCursor createCursor (int x, int y, int width, int height, int hotSpotX, int hotSpotY, Image imageRef) {
+               return null;
        }
 
-       boolean bind () {
-               texture.bind();
-               return true;
+       public void themeLoadingDone () {
        }
 
-       public Image getImage (int x, int y, int width, int height, Color tintColor, boolean tiled) {
-               if (x < 0 || x >= getWidth()) {
-                       throw new IllegalArgumentException("x");
-               }
-               if (y < 0 || y >= getHeight()) {
-                       throw new IllegalArgumentException("y");
-               }
-               if (x + Math.abs(width) > getWidth()) {
-                       throw new IllegalArgumentException("width");
-               }
-               if (y + Math.abs(height) > getHeight()) {
-                       throw new IllegalArgumentException("height");
-               }
-               if (tiled && (width <= 0 || height <= 0)) {
-                       throw new IllegalArgumentException("Tiled rendering requires positive width & height");
-               }
-               return new TextureArea(this, x, y, width, height, tintColor, tiled);
+       public int getWidth () {
+               return texture.getWidth();
        }
 
-       public MouseCursor createCursor (int x, int y, int width, int height, int hotSpotX, int hotSpotY, Image imageRef) {
-               return null;
+       public int getHeight () {
+               return texture.getHeight();
        }
 
-       public void themeLoadingDone () {
+       public void destroy () {
+               texture.dispose();
        }
 }
diff --git a/extensions/twl/gdx-twl/src/com/badlogic/gdx/twl/renderer/TextureArea.java b/extensions/twl/gdx-twl/src/com/badlogic/gdx/twl/renderer/TextureArea.java
deleted file mode 100644 (file)
index d9b43ca..0000000
+++ /dev/null
@@ -1,188 +0,0 @@
-\r
-package com.badlogic.gdx.twl.renderer;\r
-\r
-import java.nio.ByteBuffer;\r
-import java.nio.ByteOrder;\r
-import java.nio.FloatBuffer;\r
-\r
-import com.badlogic.gdx.Gdx;\r
-import com.badlogic.gdx.graphics.GL10;\r
-\r
-import de.matthiasmann.twl.Color;\r
-import de.matthiasmann.twl.renderer.AnimationState;\r
-import de.matthiasmann.twl.renderer.Image;\r
-import de.matthiasmann.twl.renderer.SupportsDrawRepeat;\r
-\r
-class TextureArea extends TextureAreaBase implements Image, SupportsDrawRepeat {\r
-       private static final FloatBuffer texCoords = ByteBuffer.allocateDirect(8 * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();\r
-       private static final FloatBuffer vertices = ByteBuffer.allocateDirect(8 * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();\r
-\r
-       private static final int REPEAT_CACHE_SIZE = 10;\r
-\r
-       private final GdxTexture texture;\r
-       private final Color tintColor;\r
-       private final boolean tile;\r
-       private int repeatCacheID = -1;\r
-\r
-       public TextureArea (GdxTexture texture, int x, int y, int width, int height, Color tintColor, boolean tile) {\r
-               super(texture.renderer, x, y, width, height, texture.getWidth(), texture.getHeight());\r
-               this.texture = texture;\r
-               this.tintColor = (tintColor == null) ? Color.WHITE : tintColor;\r
-               this.tile = tile;\r
-       }\r
-\r
-       TextureArea (TextureArea src, Color tintColor) {\r
-               super(src);\r
-               this.texture = src.texture;\r
-               this.tintColor = tintColor;\r
-               this.tile = src.tile;\r
-       }\r
-\r
-       public void draw (AnimationState as, int x, int y) {\r
-               draw(as, x, y, width, height);\r
-       }\r
-\r
-       public void draw (AnimationState as, int x, int y, int w, int h) {\r
-               if (texture.bind(tintColor)) {\r
-                       if (tile) {\r
-                               drawTiled(x, y, w, h);\r
-                       } else {\r
-                               drawQuad(x, y, w, h);\r
-                       }\r
-               }\r
-       }\r
-\r
-       public void draw (AnimationState as, int x, int y, int width, int height, int repeatCountX, int repeatCountY) {\r
-               if (texture.bind(tintColor)) {\r
-                       if ((repeatCountX * this.width != width) || (repeatCountY * this.height != height)) {\r
-                               drawRepeatSlow(x, y, width, height, repeatCountX, repeatCountY);\r
-                               return;\r
-                       }\r
-                       drawRepeat(x, y, repeatCountX, repeatCountY);\r
-               }\r
-       }\r
-\r
-       private void drawRepeatSlow (int x, int y, int width, int height, int repeatCountX, int repeatCountY) {\r
-               while (repeatCountY > 0) {\r
-                       int rowHeight = height / repeatCountY;\r
-\r
-                       int cx = 0;\r
-                       for (int xi = 0; xi < repeatCountX;) {\r
-                               int nx = ++xi * width / repeatCountX;\r
-                               drawQuad(x + cx, y, nx - cx, rowHeight);\r
-                               cx = nx;\r
-                       }\r
-\r
-                       y += rowHeight;\r
-                       height -= rowHeight;\r
-                       repeatCountY--;\r
-               }\r
-       }\r
-\r
-       private void drawRepeat (int x, int y, int repeatCountX, int repeatCountY) {\r
-               final int w = width;\r
-               final int h = height;\r
-               while (repeatCountY-- > 0) {\r
-                       int curX = x;\r
-                       int cntX = repeatCountX;\r
-                       while (cntX-- > 0) {\r
-                               drawQuad(curX, y, w, h);\r
-                               curX += w;\r
-                       }\r
-                       y += h;\r
-               }\r
-       }\r
-\r
-       private void drawTiled (int x, int y, int width, int height) {\r
-               int repeatCountX = width / this.width;\r
-               int repeatCountY = height / this.height;\r
-\r
-               drawRepeat(x, y, repeatCountX, repeatCountY);\r
-\r
-               int drawnX = repeatCountX * this.width;\r
-               int drawnY = repeatCountY * this.height;\r
-               int restWidth = width - drawnX;\r
-               int restHeight = height - drawnY;\r
-               if (restWidth > 0 || restHeight > 0) {\r
-                       if (restWidth > 0 && repeatCountY > 0) {\r
-                               drawClipped(x + drawnX, y, restWidth, this.height, 1, repeatCountY);\r
-                       }\r
-                       if (restHeight > 0) {\r
-                               if (repeatCountX > 0) {\r
-                                       drawClipped(x, y + drawnY, this.width, restHeight, repeatCountX, 1);\r
-                               }\r
-                               if (restWidth > 0) {\r
-                                       drawClipped(x + drawnX, y + drawnY, restWidth, restHeight, 1, 1);\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-\r
-       private void drawClipped (int x, int y, int width, int height, int repeatCountX, int repeatCountY) {\r
-               float ctx0 = tx0;\r
-               float cty0 = ty0;\r
-               float ctx1 = tx1;\r
-               float cty1 = ty1;\r
-               if (this.width > 1) {\r
-                       ctx1 = ctx0 + width / (float)texture.getWidth();\r
-               }\r
-               if (this.height > 1) {\r
-                       cty1 = cty0 + height / (float)texture.getHeight();\r
-               }\r
-\r
-               texCoords.clear();\r
-               vertices.clear();\r
-\r
-               GL10 gl = Gdx.graphics.getGL10();\r
-\r
-               while (repeatCountY-- > 0) {\r
-                       int y1 = y + height;\r
-                       int x0 = x;\r
-                       for (int cx = repeatCountX; cx-- > 0;) {\r
-                               int x1 = x0 + width;\r
-\r
-                               texCoords.put(ctx0);\r
-                               texCoords.put(cty0);\r
-                               vertices.put(x0);\r
-                               vertices.put(y);\r
-\r
-                               texCoords.put(ctx0);\r
-                               texCoords.put(cty1);\r
-                               vertices.put(x0);\r
-                               vertices.put(y1);\r
-\r
-                               texCoords.put(ctx1);\r
-                               texCoords.put(cty1);\r
-                               vertices.put(x1);\r
-                               vertices.put(y1);\r
-\r
-                               texCoords.put(ctx1);\r
-                               texCoords.put(cty0);\r
-                               vertices.put(x1);\r
-                               vertices.put(y);\r
-\r
-                               texCoords.flip();\r
-                               vertices.flip();\r
-\r
-                               gl.glVertexPointer(2, GL10.GL_FLOAT, 0, vertices);\r
-                               gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, texCoords);\r
-                               gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);\r
-\r
-                               x0 = x1;\r
-                       }\r
-                       y = y1;\r
-               }\r
-       }\r
-\r
-       public Image createTintedVersion (Color color) {\r
-               if (color == null) {\r
-                       throw new NullPointerException("color");\r
-               }\r
-               Color newTintColor = tintColor.multiply(color);\r
-               if (newTintColor.equals(tintColor)) {\r
-                       return this;\r
-               }\r
-               return new TextureArea(this, newTintColor);\r
-       }\r
-\r
-}\r
diff --git a/extensions/twl/gdx-twl/src/com/badlogic/gdx/twl/renderer/TextureAreaBase.java b/extensions/twl/gdx-twl/src/com/badlogic/gdx/twl/renderer/TextureAreaBase.java
deleted file mode 100644 (file)
index 46aa36a..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-\r
-package com.badlogic.gdx.twl.renderer;\r
-\r
-import java.nio.ByteBuffer;\r
-import java.nio.ByteOrder;\r
-import java.nio.FloatBuffer;\r
-\r
-import com.badlogic.gdx.Gdx;\r
-import com.badlogic.gdx.graphics.GL10;\r
-\r
-class TextureAreaBase {\r
-       protected final float tx0;\r
-       protected final float ty0;\r
-       protected final float tx1;\r
-       protected final float ty1;\r
-       protected final short width;\r
-       protected final short height;\r
-\r
-       FloatBuffer texCoords = ByteBuffer.allocateDirect(8 * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();\r
-       FloatBuffer vertices = ByteBuffer.allocateDirect(8 * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();\r
-       final TwlRenderer renderer;\r
-\r
-       TextureAreaBase (TwlRenderer renderer, int x, int y, int width, int height, float texWidth, float texHeight) {\r
-               this.renderer = renderer;\r
-               // negative size allows for flipping\r
-               this.width = (short)Math.abs(width);\r
-               this.height = (short)Math.abs(height);\r
-               float fx = x;\r
-               float fy = y;\r
-               if (width == 1) {\r
-                       fx += 0.5f;\r
-                       width = 0;\r
-               }\r
-               if (height == 1) {\r
-                       fy += 0.5f;\r
-                       height = 0;\r
-               }\r
-               this.tx0 = fx / texWidth;\r
-               this.ty0 = fy / texHeight;\r
-               this.tx1 = tx0 + width / texWidth;\r
-               this.ty1 = ty0 + height / texHeight;\r
-       }\r
-\r
-       TextureAreaBase (TextureAreaBase src) {\r
-               this.renderer = src.renderer;\r
-               this.tx0 = src.tx0;\r
-               this.ty0 = src.ty0;\r
-               this.tx1 = src.tx1;\r
-               this.ty1 = src.ty1;\r
-               this.width = src.width;\r
-               this.height = src.height;\r
-       }\r
-\r
-       public int getWidth () {\r
-               return width;\r
-       }\r
-\r
-       public int getHeight () {\r
-               return height;\r
-       }\r
-\r
-       void drawQuad (int x, int y, int w, int h) {\r
-               texCoords.clear();\r
-               vertices.clear();\r
-\r
-               texCoords.put(tx0);\r
-               texCoords.put(ty0);\r
-               vertices.put(x);\r
-               vertices.put(y);\r
-\r
-               texCoords.put(tx0);\r
-               texCoords.put(ty1);\r
-               vertices.put(x);\r
-               vertices.put(y + h);\r
-\r
-               texCoords.put(tx1);\r
-               texCoords.put(ty0);\r
-               vertices.put(x + w);\r
-               vertices.put(y);\r
-\r
-               texCoords.put(tx1);\r
-               texCoords.put(ty1);\r
-               vertices.put(x + w);\r
-               vertices.put(y + h);\r
-\r
-               texCoords.flip();\r
-               vertices.flip();\r
-\r
-               GL10 gl = Gdx.graphics.getGL10();\r
-               gl.glVertexPointer(2, GL10.GL_FLOAT, 0, vertices);\r
-               gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, texCoords);\r
-               gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);\r
-       }\r
-}\r
index 59f2df0..5889c8f 100644 (file)
@@ -6,7 +6,7 @@ import com.badlogic.gdx.RenderListener;
 \r
 import de.matthiasmann.twl.GUI;\r
 \r
-public class TwlInputListener implements InputListener, RenderListener {\r
+public class TwlInputListener implements InputListener {\r
        private final GUI gui;\r
 \r
        public TwlInputListener (GUI gui) {\r
@@ -37,18 +37,4 @@ public class TwlInputListener implements InputListener, RenderListener {
        public boolean touchDragged (int x, int y, int pointer) {\r
                return gui.handleMouse(x, y, -1, true);\r
        }\r
-\r
-       public void surfaceCreated () {\r
-       }\r
-\r
-       public void surfaceChanged (int width, int height) {\r
-               gui.setSize();\r
-       }\r
-\r
-       public void render () {\r
-       }\r
-\r
-       public void dispose () {\r
-               gui.destroy();\r
-       }\r
 }\r
index 3fefa8f..7652169 100644 (file)
@@ -12,7 +12,9 @@ import com.badlogic.gdx.files.FileHandle;
 import com.badlogic.gdx.graphics.BitmapFont;\r
 import com.badlogic.gdx.graphics.Color;\r
 import com.badlogic.gdx.graphics.GL10;\r
+import com.badlogic.gdx.graphics.GLCommon;\r
 import com.badlogic.gdx.graphics.SpriteBatch;\r
+import com.badlogic.gdx.math.Matrix4;\r
 \r
 import de.matthiasmann.twl.GUI;\r
 import de.matthiasmann.twl.Rect;\r
@@ -28,8 +30,6 @@ import de.matthiasmann.twl.renderer.Texture;
 import de.matthiasmann.twl.theme.ThemeManager;\r
 \r
 public class TwlRenderer implements Renderer {\r
-       private final int[] temp = new int[1];\r
-\r
        private int mouseX, mouseY;\r
        private GdxCacheContext cacheContext;\r
        private boolean hasScissor;\r
@@ -38,6 +38,10 @@ public class TwlRenderer implements Renderer {
        private final Color tempColor = new Color(1, 1, 1, 1);\r
        final SpriteBatch spriteBatch = new SpriteBatch();\r
 \r
+       public TwlRenderer () {\r
+               spriteBatch.setProjectionMatrix(new Matrix4().setToOrtho(0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), 0, 0, 1));\r
+       }\r
+\r
        public GdxCacheContext createNewCacheContext () {\r
                return new GdxCacheContext(this);\r
        }\r
@@ -69,20 +73,19 @@ public class TwlRenderer implements Renderer {
        public void endRendering () {\r
                spriteBatch.end();\r
                if (hasScissor) {\r
-                       Gdx.graphics.getGL10().glDisable(GL10.GL_SCISSOR_TEST);\r
+                       Gdx.gl.glDisable(GL10.GL_SCISSOR_TEST);\r
                        hasScissor = false;\r
                }\r
        }\r
 \r
        public void setClipRect (Rect rect) {\r
                if (rect == null) {\r
-                       Gdx.graphics.getGL10().glDisable(GL10.GL_SCISSOR_TEST);\r
+                       Gdx.gl.glDisable(GL10.GL_SCISSOR_TEST);\r
                        hasScissor = false;\r
                } else {\r
-                       GL10 gl = Gdx.graphics.getGL10();\r
-                       gl.glScissor(rect.getX(), Gdx.graphics.getHeight() - rect.getBottom(), rect.getWidth(), rect.getHeight());\r
+                       Gdx.gl.glScissor(rect.getX(), Gdx.graphics.getHeight() - rect.getBottom(), rect.getWidth(), rect.getHeight());\r
                        if (!hasScissor) {\r
-                               gl.glEnable(GL10.GL_SCISSOR_TEST);\r
+                               Gdx.gl.glEnable(GL10.GL_SCISSOR_TEST);\r
                                hasScissor = true;\r
                        }\r
                }\r
index 5a15a9a..10d5829 100644 (file)
@@ -36,21 +36,26 @@ public class BitmapFont {
 \r
        private final Texture texture;\r
        private final Glyph[][] glyphs = new Glyph[PAGES][];\r
-       private int lineHeight;\r
-       private int baseLine;\r
-       private int spaceWidth;\r
-       private int ex;\r
-       private int capHeight;\r
+       private final int lineHeight;\r
+       private final int baseLine;\r
+       private final int spaceWidth;\r
+       private final int xHeight;\r
+       private final int capHeight;\r
+       private final int yOffset;\r
+       private final float down;\r
 \r
        /**\r
         * Creates a new BitmapFont instance based on a .fnt file and an image file holding the page with glyphs. Currently only\r
         * supports single page AngleCode fonts.\r
         * @param fontFile The font file\r
         * @param imageFile The image file\r
+        * @param flip If true, the glyphs will be flipped for use with a perspective where 0,0 is the upper left corner.\r
         */\r
-       public BitmapFont (FileHandle fontFile, FileHandle imageFile) {\r
+       public BitmapFont (FileHandle fontFile, FileHandle imageFile, boolean flip) {\r
                texture = Gdx.graphics.newTexture(imageFile, TextureFilter.Linear, TextureFilter.Linear, TextureWrap.ClampToEdge,\r
                        TextureWrap.ClampToEdge);\r
+               float invTexWidth = 1.0f / texture.getWidth();\r
+               float invTexHeight = 1.0f / texture.getHeight();\r
 \r
                BufferedReader reader = new BufferedReader(new InputStreamReader(fontFile.getInputStream()), 512);\r
                try {\r
@@ -85,9 +90,9 @@ public class BitmapFont {
                                } else\r
                                        continue;\r
                                tokens.nextToken();\r
-                               glyph.x = Integer.parseInt(tokens.nextToken());\r
+                               float srcX = Integer.parseInt(tokens.nextToken());\r
                                tokens.nextToken();\r
-                               glyph.y = Integer.parseInt(tokens.nextToken());\r
+                               float srcY = Integer.parseInt(tokens.nextToken());\r
                                tokens.nextToken();\r
                                glyph.width = (Integer.parseInt(tokens.nextToken()));\r
                                tokens.nextToken();\r
@@ -95,9 +100,22 @@ public class BitmapFont {
                                tokens.nextToken();\r
                                glyph.xoffset = Integer.parseInt(tokens.nextToken());\r
                                tokens.nextToken();\r
-                               glyph.yoffset = glyph.height + Integer.parseInt(tokens.nextToken());\r
+                               if (flip)\r
+                                       glyph.yoffset = Integer.parseInt(tokens.nextToken()) - lineHeight + baseLine;\r
+                               else\r
+                                       glyph.yoffset = -(glyph.height + Integer.parseInt(tokens.nextToken()));\r
                                tokens.nextToken();\r
                                glyph.xadvance = Integer.parseInt(tokens.nextToken());\r
+\r
+                               glyph.u = srcX * invTexWidth;\r
+                               glyph.u2 = (srcX + glyph.width) * invTexWidth;\r
+                               if (flip) {\r
+                                       glyph.v = srcY * invTexHeight;\r
+                                       glyph.v2 = (srcY + glyph.height) * invTexHeight;\r
+                               } else {\r
+                                       glyph.v2 = srcY * invTexHeight;\r
+                                       glyph.v = (srcY + glyph.height) * invTexHeight;\r
+                               }\r
                        }\r
 \r
                        while (true) {\r
@@ -121,8 +139,14 @@ public class BitmapFont {
                        Glyph g = getGlyph(' ');\r
                        spaceWidth = (g != null) ? g.xadvance + g.width : 1;\r
 \r
-                       Glyph gx = getGlyph('x');\r
-                       ex = gx != null ? gx.height : 1;\r
+                       g = getGlyph('x');\r
+                       xHeight = g != null ? g.height : 1;\r
+                       \r
+                       g = getGlyph('M');\r
+                       capHeight = g != null ? g.height : 1;\r
+\r
+                       yOffset = flip ? 0 : lineHeight - baseLine;\r
+                       down = flip ? 1 : -1;\r
                } catch (Exception ex) {\r
                        throw new GdxRuntimeException("Error loading font file: " + fontFile, ex);\r
                } finally {\r
@@ -160,20 +184,21 @@ public class BitmapFont {
         * @param str The string\r
         * @param x The x position of the left most character\r
         * @param y The y position of the left most character's top left corner\r
-        * @param color The color\r
+        * @param tint The color\r
         * @param start the first character of the string to draw\r
         * @param end the last character of the string to draw\r
         * @return the width of the rendered string\r
         */\r
-       public int draw (SpriteBatch spriteBatch, CharSequence str, int x, int y, Color color, int start, int end) {\r
-               y += capHeight;\r
+       public int draw (SpriteBatch spriteBatch, CharSequence str, int x, int y, Color tint, int start, int end) {\r
+               final float color = tint.toFloatBits();\r
+               y += yOffset;\r
                int startX = x;\r
                Glyph lastGlyph = null;\r
                while (start < end) {\r
                        lastGlyph = getGlyph(str.charAt(start++));\r
                        if (lastGlyph != null) {\r
-                               spriteBatch.draw(texture, x + lastGlyph.xoffset, y - lastGlyph.yoffset, lastGlyph.x, lastGlyph.y, lastGlyph.width,\r
-                                       lastGlyph.height, color);\r
+                               spriteBatch.draw(texture, x + lastGlyph.xoffset, y + lastGlyph.yoffset, lastGlyph.width, lastGlyph.height,\r
+                                       lastGlyph.u, lastGlyph.v, lastGlyph.u2, lastGlyph.v2, color);\r
                                x += lastGlyph.xadvance;\r
                                break;\r
                        }\r
@@ -184,8 +209,8 @@ public class BitmapFont {
                        if (g != null) {\r
                                x += lastGlyph.getKerning(ch);\r
                                lastGlyph = g;\r
-                               spriteBatch.draw(texture, x + lastGlyph.xoffset, y - lastGlyph.yoffset, lastGlyph.x, lastGlyph.y, lastGlyph.width,\r
-                                       lastGlyph.height, color);\r
+                               spriteBatch.draw(texture, x + lastGlyph.xoffset, y + lastGlyph.yoffset, lastGlyph.width, lastGlyph.height,\r
+                                       lastGlyph.u, lastGlyph.v, lastGlyph.u2, lastGlyph.v2, color);\r
                                x += g.xadvance;\r
                        }\r
                }\r
@@ -239,7 +264,7 @@ public class BitmapFont {
                        }\r
                        draw(spriteBatch, str, x + xOffset, y, color, start, lineEnd);\r
                        start = lineEnd + 1;\r
-                       y -= lineHeight;\r
+                       y += lineHeight * down;\r
                        numLines++;\r
                }\r
                return numLines * lineHeight;\r
@@ -299,19 +324,18 @@ public class BitmapFont {
                        }\r
                        draw(spriteBatch, str, x + xOffset, y, color, start, lineEnd);\r
                        start = lineEnd + 1;\r
-                       y -= lineHeight;\r
+                       y += lineHeight * down;\r
                        numLines++;\r
                }\r
                return numLines * lineHeight;\r
        }\r
 \r
-       private void addToCache (BitmapFontCache cache, CharSequence str, int x, int y, Color color, int start, int end) {\r
+       private void addToCache (BitmapFontCache cache, CharSequence str, int x, int y, float color, int start, int end) {\r
                Glyph lastGlyph = null;\r
                while (start < end) {\r
                        lastGlyph = getGlyph(str.charAt(start++));\r
                        if (lastGlyph != null) {\r
-                               cache.addGlyph(x + lastGlyph.xoffset, y - lastGlyph.yoffset, lastGlyph.x, lastGlyph.y, lastGlyph.width,\r
-                                       lastGlyph.height, color);\r
+                               cache.addGlyph(lastGlyph, x, y, color);\r
                                x += lastGlyph.xadvance;\r
                                break;\r
                        }\r
@@ -322,8 +346,7 @@ public class BitmapFont {
                        if (g != null) {\r
                                x += lastGlyph.getKerning(ch);\r
                                lastGlyph = g;\r
-                               cache.addGlyph(x + lastGlyph.xoffset, y - lastGlyph.yoffset, lastGlyph.x, lastGlyph.y, lastGlyph.width,\r
-                                       lastGlyph.height, color);\r
+                               cache.addGlyph(lastGlyph, x, y, color);\r
                                x += g.xadvance;\r
                        }\r
                }\r
@@ -334,7 +357,7 @@ public class BitmapFont {
         * @return The new cache\r
         */\r
        public BitmapFontCache newCache () {\r
-               return new BitmapFontCache(this.texture);\r
+               return new BitmapFontCache(texture);\r
        }\r
 \r
        /**\r
@@ -355,13 +378,14 @@ public class BitmapFont {
         * @param str The string\r
         * @param x The x position of the left most character\r
         * @param y The y position of the left most character's top left corner\r
-        * @param color The color\r
+        * @param tint The color\r
         * @param start The first character of the string to draw\r
         * @param end The last character of the string to draw\r
         */\r
-       public void cacheText (BitmapFontCache cache, CharSequence str, int x, int y, Color color, int start, int end) {\r
+       public void cacheText (BitmapFontCache cache, CharSequence str, int x, int y, Color tint, int start, int end) {\r
+               final float color = tint.toFloatBits();\r
                cache.reset(end - start);\r
-               y += capHeight;\r
+               y += yOffset;\r
                addToCache(cache, str, x, y, color, start, end);\r
                cache.width = x;\r
                cache.height = lineHeight;\r
@@ -391,12 +415,14 @@ public class BitmapFont {
         * @param str The string\r
         * @param x The x position of the left most character of the first line\r
         * @param y The y position of the left most character's top left corner of the first line\r
-        * @param color The color\r
+        * @param tint The color\r
         * @param alignmentWidth The alignment width\r
         * @param alignment The horizontal alignment\r
         */\r
-       public void cacheMultiLineText (BitmapFontCache cache, CharSequence str, int x, int y, Color color, int alignmentWidth,\r
+       public void cacheMultiLineText (BitmapFontCache cache, CharSequence str, int x, int y, Color tint, int alignmentWidth,\r
                HAlignment alignment) {\r
+               final float color = tint.toFloatBits();\r
+               y += yOffset;\r
                int length = str.length();\r
                cache.reset(length);\r
                int start = 0;\r
@@ -411,7 +437,7 @@ public class BitmapFont {
                        }\r
                        addToCache(cache, str, x + xOffset, y, color, start, lineEnd);\r
                        start = lineEnd + 1;\r
-                       y -= lineHeight;\r
+                       y += lineHeight * down;\r
                        numLines++;\r
                }\r
                cache.width = alignmentWidth;\r
@@ -421,7 +447,7 @@ public class BitmapFont {
        /**\r
         * Caches the given string at the given position with the given color in the provided {@link BitmapFontCache}. The position\r
         * coincides with the top left corner of the first line's glyph. This method interprets new lines and causes the text to wrap\r
-        * at spaces based on the given <code>wrapWidth</code>.\r
+        * at spaces based on the given <code>wrapWidth</code>. The wrapped text is left aligned.\r
         * @param cache The cache\r
         * @param str The string\r
         * @param x The x position of the left most character of the first line\r
@@ -444,11 +470,13 @@ public class BitmapFont {
         * @param str The string\r
         * @param x The x position of the left most character of the first line\r
         * @param y The y position of the left most character's top left corner of the first line\r
-        * @param color The color\r
+        * @param tint The color\r
         * @param wrapWidth The wrap width\r
         */\r
-       public void cacheWrappedText (BitmapFontCache cache, CharSequence str, int x, int y, Color color, int wrapWidth,\r
+       public void cacheWrappedText (BitmapFontCache cache, CharSequence str, int x, int y, Color tint, int wrapWidth,\r
                HAlignment alignment) {\r
+               final float color = tint.toFloatBits();\r
+               y += yOffset;\r
                int length = str.length();\r
                cache.reset(length);\r
                int start = 0;\r
@@ -471,7 +499,7 @@ public class BitmapFont {
                        }\r
                        addToCache(cache, str, x + xOffset, y, color, start, lineEnd);\r
                        start = lineEnd + 1;\r
-                       y -= lineHeight;\r
+                       y += lineHeight * down;\r
                        numLines++;\r
                }\r
                cache.width = wrapWidth;\r
@@ -591,7 +619,7 @@ public class BitmapFont {
         * @return The x-height, which is the typical height of lowercase characters\r
         */\r
        public int getXHeight () {\r
-               return ex;\r
+               return xHeight;\r
        }\r
 \r
        /**\r
@@ -609,8 +637,8 @@ public class BitmapFont {
        }\r
 \r
        static class Glyph {\r
-               int x, y;\r
                int width, height;\r
+               float u, v, u2, v2;\r
                int xoffset, yoffset;\r
                int xadvance;\r
                byte[][] kerning;\r
index 7e08b49..9497d8a 100644 (file)
@@ -1,6 +1,8 @@
 \r
 package com.badlogic.gdx.graphics;\r
 \r
+import com.badlogic.gdx.graphics.BitmapFont.Glyph;\r
+\r
 /**\r
  * A BitmapFontCache caches glyph geometry produced by a call to one of the\r
  * {@link BitmapFont#cacheText(BitmapFontCache, CharSequence, int, int, Color)} methods. It caches the glyph geometry, providing a\r
@@ -13,7 +15,6 @@ package com.badlogic.gdx.graphics;
 public class BitmapFontCache {\r
        private final Texture texture;\r
        private float[] vertices;\r
-       private final float invTexWidth, invTexHeight;\r
        private int idx;\r
        int width, height;\r
        private float x, y;\r
@@ -21,8 +22,6 @@ public class BitmapFontCache {
 \r
        BitmapFontCache (Texture texture) {\r
                this.texture = texture;\r
-               invTexWidth = 1.0f / texture.getWidth();\r
-               invTexHeight = 1.0f / texture.getHeight();\r
        }\r
 \r
        /**\r
@@ -76,14 +75,15 @@ public class BitmapFontCache {
                        vertices[i] = color;\r
        }\r
 \r
-       void addGlyph (float x, float y, int srcX, int srcY, int srcWidth, int srcHeight, Color tint) {\r
-               final float x2 = x + srcWidth;\r
-               final float y2 = y + srcHeight;\r
-               final float u = srcX * invTexWidth;\r
-               final float v = (srcY + srcHeight) * invTexHeight;\r
-               final float u2 = (srcX + srcWidth) * invTexWidth;\r
-               final float v2 = srcY * invTexHeight;\r
-               final float color = tint.toFloatBits();\r
+       void addGlyph (Glyph glyph, float x, float y, float color) {\r
+               x += glyph.xoffset;\r
+               y += glyph.yoffset;\r
+               final float x2 = x + glyph.width;\r
+               final float y2 = y + glyph.height;\r
+               final float u = glyph.u;\r
+               final float u2 = glyph.u2;\r
+               final float v = glyph.v;\r
+               final float v2 = glyph.v2;\r
 \r
                float[] vertices = this.vertices;\r
                vertices[idx++] = x;\r
index 99327be..12518a8 100644 (file)
@@ -172,7 +172,7 @@ public class ImmediateModeRenderer {
        public void end () {\r
                if (idxPos == 0) return;\r
 \r
-               GL10 gl = Gdx.graphics.getGL10();\r
+               GL10 gl = Gdx.gl10;\r
                gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);\r
                positionsBuffer.clear();\r
                positionsBuffer.put(positions, 0, idxPos);\r
index 9675582..764d7b4 100644 (file)
@@ -527,7 +527,7 @@ public class Mesh {
        }\r
 \r
        private void renderVA (int primitiveType, int offset, int count) {\r
-               GL10 gl = Gdx.graphics.getGL10();\r
+               GL10 gl = Gdx.gl10;\r
 \r
                int numAttributes = attributes.size();\r
                int type = useFixedPoint ? GL11.GL_FIXED : GL11.GL_FLOAT;\r
index c0ece12..385c29c 100644 (file)
@@ -162,7 +162,7 @@ public final class OrthographicCamera {
         */\r
        public void setMatrices () {\r
                update();\r
-               GL10 gl = Gdx.graphics.getGL10();\r
+               GL10 gl = Gdx.gl10;\r
                gl.glMatrixMode(GL10.GL_PROJECTION);\r
                gl.glLoadMatrixf(getCombinedMatrix().val, 0);\r
                gl.glMatrixMode(GL10.GL_MODELVIEW);\r
index f9b253e..9ee8d38 100644 (file)
@@ -167,7 +167,7 @@ public final class PerspectiveCamera {
        public void setMatrices () {\r
                setViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());\r
                update();\r
-               GL10 gl = Gdx.graphics.getGL10();\r
+               GL10 gl = Gdx.gl10;\r
                gl.glMatrixMode(GL10.GL_PROJECTION);\r
                gl.glLoadMatrixf(getCombinedMatrix().val, 0);\r
                gl.glMatrixMode(GL10.GL_MODELVIEW);\r
index e88f7cc..8bba261 100644 (file)
@@ -23,6 +23,7 @@ public class Sprite {
        private float originX, originY;\r
        private float rotation;\r
        private float scaleX = 1, scaleY = 1;\r
+       private Color color = new Color(1, 1, 1, 1);\r
        private boolean dirty;\r
 \r
        /**\r
@@ -48,8 +49,8 @@ public class Sprite {
                this.texture = texture;\r
                setTextureRegion(srcX, srcY, srcWidth, srcHeight);\r
                setColor(1, 1, 1, 1);\r
-               setBounds(0, 0, srcWidth, srcHeight);\r
-               setOrigin(srcWidth / 2, srcHeight / 2);\r
+               setBounds(0, 0, Math.abs(srcWidth), Math.abs(srcHeight));\r
+               setOrigin(width / 2, height / 2);\r
        }\r
 \r
        /**\r
@@ -146,7 +147,7 @@ public class Sprite {
         */\r
        public void setTextureRepeat (boolean x, boolean y) {\r
                texture.bind();\r
-               GL10 gl = Gdx.graphics.getGL10();\r
+               GL10 gl = Gdx.gl10;\r
                gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, x ? GL10.GL_REPEAT : GL10.GL_CLAMP_TO_EDGE);\r
                gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, y ? GL10.GL_REPEAT : GL10.GL_CLAMP_TO_EDGE);\r
        }\r
@@ -200,6 +201,7 @@ public class Sprite {
        }\r
 \r
        public void setColor (Color tint) {\r
+               this.color = tint;\r
                float color = tint.toFloatBits();\r
                float[] vertices = this.vertices;\r
                vertices[C1] = color;\r
@@ -209,6 +211,10 @@ public class Sprite {
        }\r
 \r
        public void setColor (float r, float g, float b, float a) {\r
+               color.r = r;\r
+               color.g = g;\r
+               color.b = b;\r
+               color.a = a;\r
                int intBits = ((int)(255 * a) << 24) | //\r
                        ((int)(255 * b) << 16) | //\r
                        ((int)(255 * g) << 8) | //\r
@@ -338,6 +344,10 @@ public class Sprite {
                return scaleY;\r
        }\r
 \r
+       public Color getColor () {\r
+               return color;\r
+       }\r
+\r
        static private final int X1 = 0;\r
        static private final int Y1 = 1;\r
        static private final int C1 = 2;\r
index 4613171..92eac8a 100644 (file)
@@ -202,7 +202,7 @@ public class SpriteBatch {
                renderCalls = 0;\r
 \r
                if (Gdx.graphics.isGL20Available() == false) {\r
-                       GL10 gl = Gdx.graphics.getGL10();\r
+                       GL10 gl = Gdx.gl10;\r
                        gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());\r
                        gl.glDisable(GL10.GL_LIGHTING);\r
                        gl.glDisable(GL10.GL_DEPTH_TEST);\r
@@ -219,7 +219,7 @@ public class SpriteBatch {
                } else {\r
                        combinedMatrix.set(projectionMatrix).mul(transformMatrix);\r
 \r
-                       GL20 gl = Gdx.graphics.getGL20();\r
+                       GL20 gl = Gdx.gl20;\r
                        gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());\r
                        gl.glDisable(GL20.GL_DEPTH_TEST);\r
                        gl.glDisable(GL20.GL_CULL_FACE);\r
@@ -248,13 +248,13 @@ public class SpriteBatch {
                drawing = false;\r
 \r
                if (Gdx.graphics.isGL20Available() == false) {\r
-                       GL10 gl = Gdx.graphics.getGL10();\r
+                       GL10 gl = Gdx.gl10;\r
                        gl.glDepthMask(true);\r
                        gl.glDisable(GL10.GL_BLEND);\r
                        gl.glDisable(GL10.GL_TEXTURE_2D);\r
                } else {\r
                        shader.end();\r
-                       GL20 gl = Gdx.graphics.getGL20();\r
+                       GL20 gl = Gdx.gl20;\r
                        gl.glDepthMask(true);\r
                        gl.glDisable(GL20.GL_BLEND);\r
                        gl.glDisable(GL20.GL_TEXTURE_2D);\r
@@ -562,6 +562,61 @@ public class SpriteBatch {
                if (idx == vertices.length) renderMesh();\r
        }\r
 \r
+       /**\r
+        * Draws a rectangle with the top left corner at x,y having the given width and height in pixels. The portion of the\r
+        * {@link Texture} given by u, v and u2, v2 are used. These coordinates and sizes are given in texture size percentage. The\r
+        * rectangle will have the given tint {@link Color}.\r
+        * \r
+        * @param texture the Texture\r
+        * @param x the x-coordinate in screen space\r
+        * @param y the y-coordinate in screen space\r
+        * @param srcWidth the source with in texels\r
+        * @param srcHeight the source height in texels\r
+        * @param color the tint Color\r
+        */\r
+       public void draw (Texture texture, float x, float y, int srcWidth, int srcHeight, float u, float v, float u2, float v2,\r
+               float color) {\r
+               if (!drawing) throw new IllegalStateException("you have to call SpriteBatch.begin() first");\r
+\r
+               if (texture != lastTexture) {\r
+                       renderMesh();\r
+                       lastTexture = texture;\r
+                       invTexWidth = 1.0f / texture.getWidth();\r
+                       invTexHeight = 1.0f / texture.getHeight();\r
+               }\r
+\r
+               useTextBlend = false;\r
+\r
+               final float fx2 = x + srcWidth;\r
+               final float fy2 = y + srcHeight;\r
+\r
+               vertices[idx++] = x;\r
+               vertices[idx++] = y;\r
+               vertices[idx++] = color;\r
+               vertices[idx++] = u;\r
+               vertices[idx++] = v;\r
+\r
+               vertices[idx++] = x;\r
+               vertices[idx++] = fy2;\r
+               vertices[idx++] = color;\r
+               vertices[idx++] = u;\r
+               vertices[idx++] = v2;\r
+\r
+               vertices[idx++] = fx2;\r
+               vertices[idx++] = fy2;\r
+               vertices[idx++] = color;\r
+               vertices[idx++] = u2;\r
+               vertices[idx++] = v2;\r
+\r
+               vertices[idx++] = fx2;\r
+               vertices[idx++] = y;\r
+               vertices[idx++] = color;\r
+               vertices[idx++] = u2;\r
+               vertices[idx++] = v;\r
+\r
+               if (idx == vertices.length) renderMesh();\r
+       }\r
+\r
        public void draw (Texture texture, float[] spriteVertices, int offset, int length) {\r
                if (!drawing) throw new IllegalStateException("you have to call SpriteBatch.begin() first");\r
 \r
@@ -590,29 +645,29 @@ public class SpriteBatch {
 \r
                if (Gdx.graphics.isGL20Available()) {\r
                        if (useTextBlend) {\r
-                               Gdx.graphics.getGL20().glBlendFunc(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA);\r
-                               Gdx.graphics.getGL20().glEnable(GL20.GL_BLEND);\r
+                               GL20 gl20 = Gdx.gl20;\r
+                               gl20.glBlendFunc(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA);\r
+                               gl20.glEnable(GL20.GL_BLEND);\r
+                       } else if (blendingDisabled) {\r
+                               Gdx.gl20.glDisable(GL20.GL_BLEND);\r
                        } else {\r
-                               if (blendingDisabled) {\r
-                                       Gdx.graphics.getGL20().glDisable(GL20.GL_BLEND);\r
-                               } else {\r
-                                       Gdx.graphics.getGL20().glEnable(GL20.GL_BLEND);\r
-                                       Gdx.graphics.getGL20().glBlendFunc(blendSrcFunc, blendDstFunc);\r
-                               }\r
+                               GL20 gl20 = Gdx.gl20;\r
+                               gl20.glEnable(GL20.GL_BLEND);\r
+                               gl20.glBlendFunc(blendSrcFunc, blendDstFunc);\r
                        }\r
 \r
                        mesh.render(shader, GL10.GL_TRIANGLES, 0, idx / 20 * 6);\r
                } else {\r
                        if (useTextBlend) {\r
-                               Gdx.graphics.getGL10().glBlendFunc(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA);\r
-                               Gdx.graphics.getGL10().glEnable(GL10.GL_BLEND);\r
+                               GL10 gl10 = Gdx.gl10;\r
+                               gl10.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA);\r
+                               gl10.glEnable(GL10.GL_BLEND);\r
+                       } else if (blendingDisabled) {\r
+                               Gdx.gl10.glDisable(GL10.GL_BLEND);\r
                        } else {\r
-                               if (blendingDisabled) {\r
-                                       Gdx.graphics.getGL10().glDisable(GL10.GL_BLEND);\r
-                               } else {\r
-                                       Gdx.graphics.getGL10().glEnable(GL10.GL_BLEND);\r
-                                       Gdx.graphics.getGL10().glBlendFunc(blendSrcFunc, blendDstFunc);\r
-                               }\r
+                               GL10 gl10 = Gdx.gl10;\r
+                               gl10.glEnable(GL10.GL_BLEND);\r
+                               gl10.glBlendFunc(blendSrcFunc, blendDstFunc);\r
                        }\r
                        mesh.render(GL10.GL_TRIANGLES, 0, idx / 20 * 6);\r
                }\r
index dc088bc..18e384e 100644 (file)
                <activity android:name=".FillrateTest" android:label="Fillrate Test"/>
                <activity android:name=".AlphaTest" android:label="Alpha Test"/>
                <activity android:name=".BitmapFontTest" android:label="BitmapFont Test"/>
+               <activity android:name=".BitmapFontFlipTest" android:label="BitmapFont Flip Test"/>
        </application>
        <uses-sdk android:minSdkVersion="3" android:targetSdkVersion="5"/>
        <uses-permission android:name="android.permission.RECORD_AUDIO"/>
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
 
-</manifest> 
\ No newline at end of file
+</manifest> 
diff --git a/tests/gdx-tests-android/src/com/badlogic/gdx/BitmapFontFlipTest.java b/tests/gdx-tests-android/src/com/badlogic/gdx/BitmapFontFlipTest.java
new file mode 100644 (file)
index 0000000..a3e09b2
--- /dev/null
@@ -0,0 +1,26 @@
+/*******************************************************************************\r
+ * Copyright 2010 mzechner\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the\r
+ * License. You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"\r
+ * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ ******************************************************************************/\r
+\r
+package com.badlogic.gdx;\r
+\r
+import android.os.Bundle;\r
+\r
+import com.badlogic.gdx.backends.android.AndroidApplication;\r
+\r
+public class BitmapFontFlipTest extends AndroidApplication {\r
+       public void onCreate (Bundle bundle) {\r
+               super.onCreate(bundle);\r
+               initialize(false);\r
+               getGraphics().setRenderListener(new com.badlogic.gdx.tests.BitmapFontFlipTest());\r
+       }\r
+}\r
index fc9b745..0a28f12 100644 (file)
@@ -29,7 +29,7 @@ public class GDXTester extends ListActivity {
                "Performance Test", "Mesh Shader Test", "SpriteBatch Test", "SpriteBatch Shader Test", "FrameBuffer Test",\r
                "SpriteBatch Rotation Test", "Box2D Test", "Audio Recorder Test", "Box2D Test Collection", "Resources Test", "MD5 Test",\r
                "Micro Benchmarks", "Multitouch Test", "BufferUtils Test", "Terrain Test", "Water Ripples", "Stage Test", "Windowed Test",\r
-               "Fillrate Test", "Alpha Test", "BitmapFont Test"};\r
+               "Fillrate Test", "Alpha Test", "BitmapFont Test", "BitmapFont Flip Test"};\r
 \r
        @Override public void onCreate (Bundle savedInstanceState) {\r
                super.onCreate(savedInstanceState);\r
@@ -82,6 +82,7 @@ public class GDXTester extends ListActivity {
                if (keyword.equals(items[36])) intent = new Intent(this, FillrateTest.class);\r
                if (keyword.equals(items[37])) intent = new Intent(this, AlphaTest.class);\r
                if (keyword.equals(items[38])) intent = new Intent(this, BitmapFontTest.class);\r
+               if (keyword.equals(items[39])) intent = new Intent(this, BitmapFontFlipTest.class);\r
 \r
                startActivity(intent);\r
        }\r
diff --git a/tests/gdx-tests-desktop/src/com/badlogic/gdx/tests/desktop/BitmapFontFlipTest.java b/tests/gdx-tests-desktop/src/com/badlogic/gdx/tests/desktop/BitmapFontFlipTest.java
new file mode 100644 (file)
index 0000000..a25491b
--- /dev/null
@@ -0,0 +1,23 @@
+/*******************************************************************************\r
+ * Copyright 2010 Mario Zechner (contact@badlogicgames.com)\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the\r
+ * License. You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"\r
+ * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ ******************************************************************************/\r
+\r
+package com.badlogic.gdx.tests.desktop;\r
+\r
+import com.badlogic.gdx.backends.desktop.JoglApplication;\r
+\r
+public class BitmapFontFlipTest {\r
+       public static void main (String[] argv) {\r
+               JoglApplication app = new JoglApplication("BitmapFont Flip Test", 480, 320, false);\r
+               app.getGraphics().setRenderListener(new com.badlogic.gdx.tests.BitmapFontFlipTest());\r
+       }\r
+}\r
index b86bd75..25e9b95 100644 (file)
@@ -17,7 +17,7 @@ import com.badlogic.gdx.backends.desktop.JoglApplication;
 \r
 public class BitmapFontTest {\r
        public static void main (String[] argv) {\r
-               JoglApplication app = new JoglApplication("BitmapFont Test", 480, 320, false);\r
+               JoglApplication app = new JoglApplication("BitmapFont Flip Test", 480, 320, false);\r
                app.getGraphics().setRenderListener(new com.badlogic.gdx.tests.BitmapFontTest());\r
        }\r
 }\r
diff --git a/tests/gdx-tests-lwjgl/src/com/badlogic/gdx/tests/lwjgl/BitmapFontFlipTest.java b/tests/gdx-tests-lwjgl/src/com/badlogic/gdx/tests/lwjgl/BitmapFontFlipTest.java
new file mode 100644 (file)
index 0000000..533ffd1
--- /dev/null
@@ -0,0 +1,23 @@
+/*******************************************************************************\r
+ * Copyright 2010 Mario Zechner (contact@badlogicgames.com)\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the\r
+ * License. You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"\r
+ * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ ******************************************************************************/\r
+\r
+package com.badlogic.gdx.tests.lwjgl;\r
+\r
+import com.badlogic.gdx.backends.desktop.LwjglApplication;\r
+\r
+public class BitmapFontFlipTest {\r
+       public static void main (String[] argv) {\r
+               LwjglApplication app = new LwjglApplication("BitmapFont Flip Test", 480, 320, false);\r
+               app.getGraphics().setRenderListener(new com.badlogic.gdx.tests.BitmapFontFlipTest());\r
+       }\r
+}\r
diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/BitmapFontFlipTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/BitmapFontFlipTest.java
new file mode 100644 (file)
index 0000000..a65f7c5
--- /dev/null
@@ -0,0 +1,126 @@
+\r
+package com.badlogic.gdx.tests;\r
+\r
+import com.badlogic.gdx.Files.FileType;\r
+import com.badlogic.gdx.Gdx;\r
+import com.badlogic.gdx.InputAdapter;\r
+import com.badlogic.gdx.RenderListener;\r
+import com.badlogic.gdx.graphics.BitmapFont;\r
+import com.badlogic.gdx.graphics.BitmapFont.HAlignment;\r
+import com.badlogic.gdx.graphics.BitmapFontCache;\r
+import com.badlogic.gdx.graphics.Color;\r
+import com.badlogic.gdx.graphics.GL10;\r
+import com.badlogic.gdx.graphics.Sprite;\r
+import com.badlogic.gdx.graphics.SpriteBatch;\r
+import com.badlogic.gdx.graphics.Texture.TextureFilter;\r
+import com.badlogic.gdx.graphics.Texture.TextureWrap;\r
+import com.badlogic.gdx.math.Matrix4;\r
+\r
+public class BitmapFontFlipTest implements RenderListener {\r
+       private SpriteBatch spriteBatch;\r
+       private BitmapFont font;\r
+       private Sprite logoSprite;\r
+       private Color red = new Color(1, 0, 0, 0.5f);\r
+       private BitmapFontCache cache1, cache2, cache3, cache4, cache5;\r
+       int renderMode;\r
+       private float alpha;\r
+\r
+       public void surfaceCreated () {\r
+               if (spriteBatch != null) return;\r
+               spriteBatch = new SpriteBatch();\r
+               spriteBatch.setProjectionMatrix(new Matrix4().setToOrtho(0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), 0, 0, 1));\r
+\r
+               logoSprite = new Sprite(Gdx.graphics.newTexture(Gdx.files.getFileHandle("data/badlogic.jpg", FileType.Internal),\r
+                       TextureFilter.Linear, TextureFilter.Linear, TextureWrap.ClampToEdge, TextureWrap.ClampToEdge));\r
+               logoSprite.flip(false, true);\r
+               logoSprite.setPosition(0, 320 - 256);\r
+               logoSprite.setColor(1, 1, 1, 0.5f);\r
+\r
+               font = new BitmapFont(Gdx.files.getFileHandle("data/verdana39.fnt", FileType.Internal), Gdx.files.getFileHandle(\r
+                       "data/verdana39.png", FileType.Internal), true);\r
+\r
+               Gdx.input.addInputListener(new InputAdapter() {\r
+                       public boolean touchDown (int x, int y, int pointer) {\r
+                               renderMode = (renderMode + 1) % 2;\r
+                               return false;\r
+                       }\r
+               });\r
+\r
+               cache1 = font.newCache();\r
+               cache2 = font.newCache();\r
+               cache3 = font.newCache();\r
+               cache4 = font.newCache();\r
+               cache5 = font.newCache();\r
+\r
+               font.cacheText(cache1, "(cached)", 10, 320 - 76, Color.WHITE);\r
+\r
+               String text = "Sphinx of black quartz,\njudge my vow.";\r
+               font.cacheMultiLineText(cache2, text, 5, 320 - 310, Color.RED);\r
+\r
+               text = "How quickly\ndaft jumping zebras vex.";\r
+               font.cacheMultiLineText(cache3, text, 5, 320 - 210, Color.BLUE, 470, BitmapFont.HAlignment.CENTER);\r
+\r
+               text = "Kerning: LYA moo";\r
+               font.cacheText(cache4, text, 210, 320 - 76, Color.WHITE, 0, text.length() - 3);\r
+\r
+               text = "Forsaking monastic tradition, twelve jovial friars gave\nup their vocation for a questionable existence on the flying trapeze.";\r
+               font.cacheWrappedText(cache5, text, 0, 320 - 310, red, 480, HAlignment.CENTER);\r
+       }\r
+\r
+       public void surfaceChanged (int width, int height) {\r
+       }\r
+\r
+       public void render () {\r
+               alpha = (alpha + Gdx.graphics.getDeltaTime() * 0.1f) % 1;\r
+\r
+               GL10 gl = Gdx.graphics.getGL10();\r
+               gl.glClear(GL10.GL_COLOR_BUFFER_BIT);\r
+               spriteBatch.begin();\r
+               logoSprite.draw(spriteBatch);\r
+               switch (renderMode) {\r
+               case 0:\r
+                       renderNormal();\r
+                       break;\r
+               case 1:\r
+                       renderCached();\r
+                       break;\r
+               }\r
+               spriteBatch.end();\r
+       }\r
+\r
+       private void renderNormal () {\r
+               String text = "Forsaking monastic tradition, twelve jovial friars gave\nup their vocation for a questionable existence on the flying trapeze.";\r
+               red.a = alpha;\r
+               font.drawWrappedText(spriteBatch, text, 0, 320 - 310, red, 480, HAlignment.CENTER);\r
+\r
+               font.draw(spriteBatch, "(normal)", 10, 320 - 76, Color.WHITE);\r
+\r
+               if (alpha > 0.6f) return;\r
+\r
+               text = "Sphinx of black quartz,\njudge my vow.";\r
+               font.drawMultiLineText(spriteBatch, text, 5, 320 - 310, Color.RED);\r
+\r
+               text = "How quickly\ndaft jumping zebras vex.";\r
+               font.drawMultiLineText(spriteBatch, text, 5, 320 - 210, Color.BLUE, 470, BitmapFont.HAlignment.RIGHT);\r
+\r
+               text = "Kerning: LYA moo";\r
+               font.draw(spriteBatch, text, 210, 320 - 76, Color.WHITE, 0, text.length() - 3);\r
+       }\r
+\r
+       private void renderCached () {\r
+               red.a = alpha;\r
+               cache5.setColor(red);\r
+               cache5.draw(spriteBatch);\r
+\r
+               cache1.draw(spriteBatch);\r
+\r
+               if (alpha > 0.6f) return;\r
+\r
+               cache2.draw(spriteBatch);\r
+               cache3.draw(spriteBatch);\r
+               cache4.draw(spriteBatch);\r
+       }\r
+\r
+       public void dispose () {\r
+       }\r
+}\r
index a3b88f7..294b954 100644 (file)
@@ -33,7 +33,7 @@ public class BitmapFontTest implements RenderListener {
                logoSprite.setColor(1, 1, 1, 0.5f);\r
 \r
                font = new BitmapFont(Gdx.files.getFileHandle("data/verdana39.fnt", FileType.Internal), Gdx.files.getFileHandle(\r
-                       "data/verdana39.png", FileType.Internal));\r
+                       "data/verdana39.png", FileType.Internal), false);\r
 \r
                Gdx.input.addInputListener(new InputAdapter() {\r
                        public boolean touchDown (int x, int y, int pointer) {\r
@@ -51,7 +51,7 @@ public class BitmapFontTest implements RenderListener {
                font.cacheText(cache1, "(cached)", 10, 76, Color.WHITE);\r
 \r
                String text = "Sphinx of black quartz,\njudge my vow.";\r
-               font.cacheMultiLineText(cache2, text, 5, 310, Color.RED, 470, BitmapFont.HAlignment.LEFT);\r
+               font.cacheMultiLineText(cache2, text, 5, 310, Color.RED);\r
 \r
                text = "How quickly\ndaft jumping zebras vex.";\r
                font.cacheMultiLineText(cache3, text, 5, 210, Color.BLUE, 470, BitmapFont.HAlignment.CENTER);\r
@@ -88,10 +88,11 @@ public class BitmapFontTest implements RenderListener {
                String text = "Forsaking monastic tradition, twelve jovial friars gave\nup their vocation for a questionable existence on the flying trapeze.";\r
                red.a = alpha;\r
                font.drawWrappedText(spriteBatch, text, 0, 310, red, 480, HAlignment.CENTER);\r
-               if (alpha > 0.66f) return;\r
 \r
                font.draw(spriteBatch, "(normal)", 10, 76, Color.WHITE);\r
 \r
+               if (alpha > 0.6f) return;\r
+\r
                text = "Sphinx of black quartz,\njudge my vow.";\r
                font.drawMultiLineText(spriteBatch, text, 5, 310, Color.RED);\r
 \r
@@ -106,9 +107,11 @@ public class BitmapFontTest implements RenderListener {
                red.a = alpha;\r
                cache5.setColor(red);\r
                cache5.draw(spriteBatch);\r
-               if (alpha > 0.66f) return;\r
 \r
                cache1.draw(spriteBatch);\r
+\r
+               if (alpha > 0.6f) return;\r
+\r
                cache2.draw(spriteBatch);\r
                cache3.draw(spriteBatch);\r
                cache4.draw(spriteBatch);\r