|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright (c) 2009-2010 jMonkeyEngine |
|
|
|
* Copyright (c) 2009-2012 jMonkeyEngine |
|
|
|
* All rights reserved. |
|
|
|
* All rights reserved. |
|
|
|
* |
|
|
|
* |
|
|
|
* Redistribution and use in source and binary forms, with or without |
|
|
|
* Redistribution and use in source and binary forms, with or without |
|
|
@ -44,6 +44,7 @@ import java.util.regex.Pattern; |
|
|
|
* @author YongHoon |
|
|
|
* @author YongHoon |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class BitmapText extends Node { |
|
|
|
public class BitmapText extends Node { |
|
|
|
|
|
|
|
|
|
|
|
private BitmapFont font; |
|
|
|
private BitmapFont font; |
|
|
|
private StringBlock block; |
|
|
|
private StringBlock block; |
|
|
|
private boolean needRefresh = true; |
|
|
|
private boolean needRefresh = true; |
|
|
@ -102,7 +103,7 @@ public class BitmapText extends Node { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setText(CharSequence text) { |
|
|
|
public void setText(CharSequence text) { |
|
|
|
// note: text.toString() is free if text is already a java.lang.String.
|
|
|
|
// note: text.toString() is free if text is already a java.lang.String.
|
|
|
|
setText( text != null ? text.toString() : null ); |
|
|
|
setText(text != null ? text.toString() : null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -110,14 +111,36 @@ 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) { |
|
|
|
|
|
|
|
System.out.println("HI"); |
|
|
|
|
|
|
|
|
|
|
|
text = text == null ? "" : text; |
|
|
|
text = text == null ? "" : text; |
|
|
|
if (text == block.getText() || block.getText().equals(text)) { |
|
|
|
if (block.getText().equals(text)) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// If the text is empty, reset
|
|
|
|
|
|
|
|
if (text.isEmpty()) { |
|
|
|
|
|
|
|
System.out.println("text is different"); |
|
|
|
|
|
|
|
detachAllChildren(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int page = 0; page < textPages.length; page++) { |
|
|
|
|
|
|
|
textPages[page] = new BitmapTextPage(font, true, page); |
|
|
|
|
|
|
|
attachChild(textPages[page]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println("Creating new StringBlock and Letters"); |
|
|
|
|
|
|
|
block = new StringBlock(); |
|
|
|
|
|
|
|
letters = new Letters(font, block, letters.getQuad().isRightToLeft()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update the text content
|
|
|
|
|
|
|
|
block.setText(text); |
|
|
|
|
|
|
|
letters.setText(text); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Flat for refresh
|
|
|
|
|
|
|
|
needRefresh = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
block.setText(text); |
|
|
|
|
|
|
|
letters.setText(text); |
|
|
|
|
|
|
|
needRefresh = true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -168,7 +191,7 @@ public class BitmapText extends Node { |
|
|
|
if (needRefresh) { |
|
|
|
if (needRefresh) { |
|
|
|
assemble(); |
|
|
|
assemble(); |
|
|
|
} |
|
|
|
} |
|
|
|
float height = getLineHeight()*block.getLineCount(); |
|
|
|
float height = getLineHeight() * block.getLineCount(); |
|
|
|
Rectangle textBox = block.getTextBox(); |
|
|
|
Rectangle textBox = block.getTextBox(); |
|
|
|
if (textBox != null) { |
|
|
|
if (textBox != null) { |
|
|
|
return Math.max(height, textBox.height); |
|
|
|
return Math.max(height, textBox.height); |
|
|
|