From 88506617ce623f6eda31852e41c28f9d8759de2f Mon Sep 17 00:00:00 2001 From: "PSp..om" Date: Wed, 16 Mar 2011 15:23:26 +0000 Subject: [PATCH] BitmapText.setColor(color) now behaves as expected and sets the default color for all letters even after a text change. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@6999 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- engine/src/core/com/jme3/font/BitmapText.java | 2 +- engine/src/core/com/jme3/font/Letters.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/engine/src/core/com/jme3/font/BitmapText.java b/engine/src/core/com/jme3/font/BitmapText.java index 8de72137f..1042ae740 100644 --- a/engine/src/core/com/jme3/font/BitmapText.java +++ b/engine/src/core/com/jme3/font/BitmapText.java @@ -143,7 +143,7 @@ public class BitmapText extends Node { * @param color new color of text */ public void setColor(ColorRGBA color) { - letters.setColor(0, block.getText().length(), color); + letters.setColor(color); letters.invalidate(); // TODO: Don't have to align. needRefresh = true; } diff --git a/engine/src/core/com/jme3/font/Letters.java b/engine/src/core/com/jme3/font/Letters.java index bbb47a467..f99bc98ea 100644 --- a/engine/src/core/com/jme3/font/Letters.java +++ b/engine/src/core/com/jme3/font/Letters.java @@ -20,6 +20,7 @@ class Letters { private float totalWidth; private float totalHeight; private ColorTags colorTags = new ColorTags(); + private ColorRGBA baseColor = null; Letters(BitmapFont font, StringBlock bound, boolean rightToLeft) { final String text = bound.getText(); @@ -41,6 +42,11 @@ class Letters { LetterQuad l = head; for (int i = 0; i < plainText.length(); i++) { l = l.addNextCharacter(plainText.charAt(i)); + if (baseColor != null) { + // Give the letter a default color if + // one has been provided. + l.setColor( baseColor ); + } } } @@ -296,6 +302,15 @@ class Letters { } } + /** + * Sets the base color for all new letter quads and resets + * the color of existing letter quads. + */ + void setColor( ColorRGBA color ) { + baseColor = color; + setColor( 0, block.getText().length(), color ); + } + /** * @param start start index to set style. inclusive. * @param end end index to set style. EXCLUSIVE.