Added a form of line wrap mode that does a hard
clip, to include truncating the letter quad at the border. This is better when text needs to be hard constrained for UI type fields. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9947 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
580579285b
commit
4610dbdacc
@ -382,6 +382,7 @@ public class BitmapText extends Node {
|
||||
* @param wrap NoWrap : Letters over the text bound is not shown. the last character is set to '...'(0x2026)
|
||||
* Character: Character is split at the end of the line.
|
||||
* Word : Word is split at the end of the line.
|
||||
* Clip : The text is hard-clipped at the border including showing only a partial letter if it goes beyond the text bound.
|
||||
*/
|
||||
public void setLineWrapMode(LineWrapMode wrap) {
|
||||
if (block.getLineWrapMode() != wrap) {
|
||||
|
@ -173,6 +173,23 @@ class LetterQuad {
|
||||
return x0 > 0 && bound.x+bound.width-gap < getX1();
|
||||
}
|
||||
|
||||
void clip(StringBlock block) {
|
||||
Rectangle bound = block.getTextBox();
|
||||
if (bound == null)
|
||||
return;
|
||||
|
||||
// Clip the right x position and texture coordinate
|
||||
// to the string block
|
||||
float x1 = Math.min(bound.x + bound.width, x0 + width);
|
||||
float newWidth = x1 - x0;
|
||||
if( newWidth == width )
|
||||
return;
|
||||
|
||||
float rescale = newWidth / width;
|
||||
u1 = u0 + (u1 - u0) * rescale;
|
||||
width = newWidth;
|
||||
}
|
||||
|
||||
float getX0() {
|
||||
return x0;
|
||||
}
|
||||
|
@ -145,7 +145,6 @@ class Letters {
|
||||
}
|
||||
break;
|
||||
case NoWrap:
|
||||
// search last blank character before this word
|
||||
LetterQuad cursor = l.getPrevious();
|
||||
while (cursor.isInvalid(block, ellipsisWidth) && !cursor.isLineStart()) {
|
||||
cursor = cursor.getPrevious();
|
||||
@ -159,6 +158,16 @@ class Letters {
|
||||
cursor = cursor.getNext();
|
||||
}
|
||||
break;
|
||||
case Clip:
|
||||
// Clip the character that falls out of bounds
|
||||
l.clip(block);
|
||||
|
||||
// Clear the rest up to the next line feed.
|
||||
for( LetterQuad q = l.getNext(); !q.isTail() && !q.isLineFeed(); q = q.getNext() ) {
|
||||
q.setBitmapChar(null);
|
||||
q.update(block);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (current.isInvalid(block)) {
|
||||
|
@ -38,5 +38,6 @@ package com.jme3.font;
|
||||
public enum LineWrapMode {
|
||||
NoWrap,
|
||||
Character,
|
||||
Word
|
||||
Word,
|
||||
Clip
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user