v0.4.2: (hopefully) solved concurrency issues with bitmaptext

This commit is contained in:
Evan Debenham 2016-08-27 18:14:06 -04:00 committed by Evan Debenham
parent 824c8f789c
commit 8dc0d56eb0

View File

@ -104,113 +104,113 @@ public class BitmapText extends Visual {
buffer.delete(); buffer.delete();
} }
protected void updateVertices() { protected synchronized void updateVertices() {
width = 0; width = 0;
height = 0; height = 0;
if (text == null) { if (text == null) {
text = ""; text = "";
} }
quads = Quad.createSet( text.length() ); quads = Quad.createSet( text.length() );
realLength = 0; realLength = 0;
int length = text.length(); int length = text.length();
for (int i=0; i < length; i++) { for (int i=0; i < length; i++) {
RectF rect = font.get( text.charAt( i ) ); RectF rect = font.get( text.charAt( i ) );
if (rect == null) { if (rect == null) {
rect=null; rect=null;
} }
float w = font.width( rect ); float w = font.width( rect );
float h = font.height( rect ); float h = font.height( rect );
vertices[0] = width; vertices[0] = width;
vertices[1] = 0; vertices[1] = 0;
vertices[2] = rect.left; vertices[2] = rect.left;
vertices[3] = rect.top; vertices[3] = rect.top;
vertices[4] = width + w; vertices[4] = width + w;
vertices[5] = 0; vertices[5] = 0;
vertices[6] = rect.right; vertices[6] = rect.right;
vertices[7] = rect.top; vertices[7] = rect.top;
vertices[8] = width + w; vertices[8] = width + w;
vertices[9] = h; vertices[9] = h;
vertices[10] = rect.right; vertices[10] = rect.right;
vertices[11] = rect.bottom; vertices[11] = rect.bottom;
vertices[12] = width; vertices[12] = width;
vertices[13] = h; vertices[13] = h;
vertices[14] = rect.left; vertices[14] = rect.left;
vertices[15] = rect.bottom; vertices[15] = rect.bottom;
quads.put( vertices ); quads.put( vertices );
realLength++; realLength++;
width += w + font.tracking; width += w + font.tracking;
if (h > height) { if (h > height) {
height = h; height = h;
} }
} }
if (length > 0) { if (length > 0) {
width -= font.tracking; width -= font.tracking;
} }
dirty = false; dirty = false;
} }
public void measure() { public synchronized void measure() {
width = 0; width = 0;
height = 0; height = 0;
if (text == null) { if (text == null) {
text = ""; text = "";
} }
int length = text.length(); int length = text.length();
for (int i=0; i < length; i++) { for (int i=0; i < length; i++) {
RectF rect = font.get( text.charAt( i ) ); RectF rect = font.get( text.charAt( i ) );
float w = font.width( rect ); float w = font.width( rect );
float h = font.height( rect ); float h = font.height( rect );
width += w + font.tracking; width += w + font.tracking;
if (h > height) { if (h > height) {
height = h; height = h;
} }
} }
if (length > 0) { if (length > 0) {
width -= font.tracking; width -= font.tracking;
} }
} }
public float baseLine() { public float baseLine() {
return font.baseLine * scale.y; return font.baseLine * scale.y;
} }
public Font font() { public Font font() {
return font; return font;
} }
public void font( Font value ) { public synchronized void font( Font value ) {
font = value; font = value;
} }
public String text() { public String text() {
return text; return text;
} }
public void text( String str ) { public synchronized void text( String str ) {
text = str; text = str;
dirty = true; dirty = true;
} }