Added cloneFields() method to BitmapText thought it's probably

fruitless since BitmapText isn't even properly saveable and couldn't
possibly have worked for any dynamic text with the old clone()
method.
Also a bunch of white space changes removing spaces at the ends of
lines.
cleanup_build_scripts
Paul Speed 9 years ago
parent 3f1c696e26
commit 2f246b25bb
  1. 48
      jme3-core/src/main/java/com/jme3/font/BitmapText.java
  2. 62
      jme3-core/src/main/java/com/jme3/font/Letters.java

@ -38,6 +38,7 @@ import com.jme3.material.Material;
import com.jme3.math.ColorRGBA; import com.jme3.math.ColorRGBA;
import com.jme3.renderer.RenderManager; import com.jme3.renderer.RenderManager;
import com.jme3.scene.Node; import com.jme3.scene.Node;
import com.jme3.util.clone.Cloner;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -84,6 +85,25 @@ public class BitmapText extends Node {
return clone; return clone;
} }
/**
* Called internally by com.jme3.util.clone.Cloner. Do not call directly.
*/
@Override
public void cloneFields( Cloner cloner, Object original ) {
for( int i = 0; i < textPages.length; i++ ) {
textPages[i] = cloner.clone(textPages[i]);
}
this.block = cloner.clone(block);
// Change in behavior: The 'letters' field was not cloned or recreated
// before. I'm not sure how this worked and suspect BitmapText was just
// not cloneable if you planned to change the text later. -pspeed
this.letters = new Letters(font, block, letters.getQuad().isRightToLeft());
// Just noticed BitmapText is not even writable/readable really...
// so I guess cloning doesn't come up that often.
}
public BitmapFont getFont() { public BitmapFont getFont() {
return font; return font;
} }
@ -115,10 +135,10 @@ public class BitmapText extends Node {
* *
* @param text String to change text to * @param text String to change text to
*/ */
public void setText(String text) { public void setText(String text) {
text = text == null ? "" : text; text = text == null ? "" : text;
if (text == block.getText() || block.getText().equals(text)) { if (text == block.getText() || block.getText().equals(text)) {
return; return;
} }
@ -126,24 +146,24 @@ public class BitmapText extends Node {
The problem with the below block is that StringBlock carries The problem with the below block is that StringBlock carries
pretty much all of the text-related state of the BitmapText such pretty much all of the text-related state of the BitmapText such
as size, text box, alignment, etc. as size, text box, alignment, etc.
I'm not sure why this change was needed and the commit message was I'm not sure why this change was needed and the commit message was
not entirely helpful because it purports to fix a problem that I've not entirely helpful because it purports to fix a problem that I've
never encountered. never encountered.
If block.setText("") doesn't do the right thing then that's where If block.setText("") doesn't do the right thing then that's where
the fix should go because StringBlock carries too much information to the fix should go because StringBlock carries too much information to
be blown away every time. -pspeed be blown away every time. -pspeed
Change was made: Change was made:
http://code.google.com/p/jmonkeyengine/source/detail?spec=svn9389&r=9389 http://code.google.com/p/jmonkeyengine/source/detail?spec=svn9389&r=9389
Diff: Diff:
http://code.google.com/p/jmonkeyengine/source/diff?path=/trunk/engine/src/core/com/jme3/font/BitmapText.java&format=side&r=9389&old_path=/trunk/engine/src/core/com/jme3/font/BitmapText.java&old=8843 http://code.google.com/p/jmonkeyengine/source/diff?path=/trunk/engine/src/core/com/jme3/font/BitmapText.java&format=side&r=9389&old_path=/trunk/engine/src/core/com/jme3/font/BitmapText.java&old=8843
// If the text is empty, reset // If the text is empty, reset
if (text.isEmpty()) { if (text.isEmpty()) {
detachAllChildren(); detachAllChildren();
for (int page = 0; page < textPages.length; page++) { for (int page = 0; page < textPages.length; page++) {
textPages[page] = new BitmapTextPage(font, true, page); textPages[page] = new BitmapTextPage(font, true, page);
attachChild(textPages[page]); attachChild(textPages[page]);
@ -153,7 +173,7 @@ public class BitmapText extends Node {
letters = new Letters(font, block, letters.getQuad().isRightToLeft()); letters = new Letters(font, block, letters.getQuad().isRightToLeft());
} }
*/ */
// Update the text content // Update the text content
block.setText(text); block.setText(text);
letters.setText(text); letters.setText(text);
@ -185,7 +205,7 @@ public class BitmapText extends Node {
letters.invalidate(); // TODO: Don't have to align. letters.invalidate(); // TODO: Don't have to align.
needRefresh = true; needRefresh = true;
} }
/** /**
* Sets an overall alpha that will be applied to all * Sets an overall alpha that will be applied to all
* letters. If the alpha passed is -1 then alpha reverts * letters. If the alpha passed is -1 then alpha reverts
@ -196,7 +216,7 @@ public class BitmapText extends Node {
public void setAlpha(float alpha) { public void setAlpha(float alpha) {
letters.setBaseAlpha(alpha); letters.setBaseAlpha(alpha);
needRefresh = true; needRefresh = true;
} }
public float getAlpha() { public float getAlpha() {
return letters.getBaseAlpha(); return letters.getBaseAlpha();
@ -414,17 +434,17 @@ public class BitmapText extends Node {
if( mp == null ) { if( mp == null ) {
return null; return null;
} }
return (ColorRGBA)mp.getValue(); return (ColorRGBA)mp.getValue();
} }
public void render(RenderManager rm, ColorRGBA color) { public void render(RenderManager rm, ColorRGBA color) {
for (BitmapTextPage page : textPages) { for (BitmapTextPage page : textPages) {
Material mat = page.getMaterial(); Material mat = page.getMaterial();
mat.setTexture("ColorMap", page.getTexture()); mat.setTexture("ColorMap", page.getTexture());
//ColorRGBA original = getColor(mat, "Color"); //ColorRGBA original = getColor(mat, "Color");
//mat.setColor("Color", color); //mat.setColor("Color", color);
mat.render(page, rm); mat.render(page, rm);
//if( original == null ) { //if( original == null ) {
// mat.clearParam("Color"); // mat.clearParam("Color");
//} else { //} else {

@ -53,7 +53,7 @@ class Letters {
private ColorRGBA baseColor = null; private ColorRGBA baseColor = null;
private float baseAlpha = -1; private float baseAlpha = -1;
private String plainText; private String plainText;
Letters(BitmapFont font, StringBlock bound, boolean rightToLeft) { Letters(BitmapFont font, StringBlock bound, boolean rightToLeft) {
final String text = bound.getText(); final String text = bound.getText();
this.block = bound; this.block = bound;
@ -78,10 +78,10 @@ class Letters {
// Give the letter a default color if // Give the letter a default color if
// one has been provided. // one has been provided.
l.setColor( baseColor ); l.setColor( baseColor );
} }
} }
} }
LinkedList<Range> ranges = colorTags.getTags(); LinkedList<Range> ranges = colorTags.getTags();
if (!ranges.isEmpty()) { if (!ranges.isEmpty()) {
for (int i = 0; i < ranges.size()-1; i++) { for (int i = 0; i < ranges.size()-1; i++) {
@ -92,7 +92,7 @@ class Letters {
Range end = ranges.getLast(); Range end = ranges.getLast();
setColor(end.start, plainText.length(), end.color); setColor(end.start, plainText.length(), end.color);
} }
invalidate(); invalidate();
} }
@ -103,17 +103,17 @@ class Letters {
LetterQuad getTail() { LetterQuad getTail() {
return tail; return tail;
} }
void update() { void update() {
LetterQuad l = head; LetterQuad l = head;
int lineCount = 1; int lineCount = 1;
BitmapCharacter ellipsis = font.getCharSet().getCharacter(block.getEllipsisChar()); BitmapCharacter ellipsis = font.getCharSet().getCharacter(block.getEllipsisChar());
float ellipsisWidth = ellipsis!=null? ellipsis.getWidth()*getScale(): 0; float ellipsisWidth = ellipsis!=null? ellipsis.getWidth()*getScale(): 0;
while (!l.isTail()) { while (!l.isTail()) {
if (l.isInvalid()) { if (l.isInvalid()) {
l.update(block); l.update(block);
if (l.isInvalid(block)) { if (l.isInvalid(block)) {
switch (block.getLineWrapMode()) { switch (block.getLineWrapMode()) {
case Character: case Character:
@ -144,7 +144,7 @@ class Letters {
} }
} }
break; break;
case NoWrap: case NoWrap:
LetterQuad cursor = l.getPrevious(); LetterQuad cursor = l.getPrevious();
while (cursor.isInvalid(block, ellipsisWidth) && !cursor.isLineStart()) { while (cursor.isInvalid(block, ellipsisWidth) && !cursor.isLineStart()) {
cursor = cursor.getPrevious(); cursor = cursor.getPrevious();
@ -158,10 +158,10 @@ class Letters {
cursor = cursor.getNext(); cursor = cursor.getNext();
} }
break; break;
case Clip: case Clip:
// Clip the character that falls out of bounds // Clip the character that falls out of bounds
l.clip(block); l.clip(block);
// Clear the rest up to the next line feed. // Clear the rest up to the next line feed.
for( LetterQuad q = l.getNext(); !q.isTail() && !q.isLineFeed(); q = q.getNext() ) { for( LetterQuad q = l.getNext(); !q.isTail() && !q.isLineFeed(); q = q.getNext() ) {
q.setBitmapChar(null); q.setBitmapChar(null);
@ -178,12 +178,12 @@ class Letters {
} }
l = l.getNext(); l = l.getNext();
} }
align(); align();
block.setLineCount(lineCount); block.setLineCount(lineCount);
rewind(); rewind();
} }
private void align() { private void align() {
final Align alignment = block.getAlignment(); final Align alignment = block.getAlignment();
final VAlign valignment = block.getVerticalAlignment(); final VAlign valignment = block.getVerticalAlignment();
@ -233,7 +233,7 @@ class Letters {
l.invalidate(); l.invalidate();
l.update(block); // TODO: update from l l.update(block); // TODO: update from l
} }
float getCharacterX0() { float getCharacterX0() {
return current.getX0(); return current.getX0();
} }
@ -241,54 +241,54 @@ class Letters {
float getCharacterY0() { float getCharacterY0() {
return current.getY0(); return current.getY0();
} }
float getCharacterX1() { float getCharacterX1() {
return current.getX1(); return current.getX1();
} }
float getCharacterY1() { float getCharacterY1() {
return current.getY1(); return current.getY1();
} }
float getCharacterAlignX() { float getCharacterAlignX() {
return current.getAlignX(); return current.getAlignX();
} }
float getCharacterAlignY() { float getCharacterAlignY() {
return current.getAlignY(); return current.getAlignY();
} }
float getCharacterWidth() { float getCharacterWidth() {
return current.getWidth(); return current.getWidth();
} }
float getCharacterHeight() { float getCharacterHeight() {
return current.getHeight(); return current.getHeight();
} }
public boolean nextCharacter() { public boolean nextCharacter() {
if (current.isTail()) if (current.isTail())
return false; return false;
current = current.getNext(); current = current.getNext();
return true; return true;
} }
public int getCharacterSetPage() { public int getCharacterSetPage() {
return current.getBitmapChar().getPage(); return current.getBitmapChar().getPage();
} }
public LetterQuad getQuad() { public LetterQuad getQuad() {
return current; return current;
} }
public void rewind() { public void rewind() {
current = head; current = head;
} }
public void invalidate() { public void invalidate() {
invalidate(head); invalidate(head);
} }
public void invalidate(LetterQuad cursor) { public void invalidate(LetterQuad cursor) {
totalWidth = -1; totalWidth = -1;
totalHeight = -1; totalHeight = -1;
@ -298,7 +298,7 @@ class Letters {
cursor = cursor.getNext(); cursor = cursor.getNext();
} }
} }
float getScale() { float getScale() {
return block.getSize() / font.getCharSet().getRenderedSize(); return block.getSize() / font.getCharSet().getRenderedSize();
} }
@ -306,7 +306,7 @@ class Letters {
public boolean isPrintable() { public boolean isPrintable() {
return current.getBitmapChar() != null; return current.getBitmapChar() != null;
} }
float getTotalWidth() { float getTotalWidth() {
validateSize(); validateSize();
return totalWidth; return totalWidth;
@ -316,7 +316,7 @@ class Letters {
validateSize(); validateSize();
return totalHeight; return totalHeight;
} }
void validateSize() { void validateSize() {
if (totalWidth < 0) { if (totalWidth < 0) {
LetterQuad l = head; LetterQuad l = head;
@ -371,11 +371,11 @@ class Letters {
cursor = cursor.getNext(); cursor = cursor.getNext();
} }
} }
float getBaseAlpha() { float getBaseAlpha() {
return baseAlpha; return baseAlpha;
} }
void setBaseAlpha( float alpha ) { this.baseAlpha = alpha; void setBaseAlpha( float alpha ) { this.baseAlpha = alpha;
colorTags.setBaseAlpha(alpha); colorTags.setBaseAlpha(alpha);
@ -409,7 +409,7 @@ class Letters {
setColor(end.start, plainText.length(), end.color); setColor(end.start, plainText.length(), end.color);
} }
} }
invalidate(); invalidate();
} }

Loading…
Cancel
Save