From 8dc0d56eb0643b74fb72aed35b3f40ab13f0a26b Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Sat, 27 Aug 2016 18:14:06 -0400 Subject: [PATCH] v0.4.2: (hopefully) solved concurrency issues with bitmaptext --- .../java/com/watabou/noosa/BitmapText.java | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/SPD-classes/src/main/java/com/watabou/noosa/BitmapText.java b/SPD-classes/src/main/java/com/watabou/noosa/BitmapText.java index fe9b71108..74e54becf 100644 --- a/SPD-classes/src/main/java/com/watabou/noosa/BitmapText.java +++ b/SPD-classes/src/main/java/com/watabou/noosa/BitmapText.java @@ -104,113 +104,113 @@ public class BitmapText extends Visual { buffer.delete(); } - protected void updateVertices() { - + protected synchronized void updateVertices() { + width = 0; height = 0; - + if (text == null) { text = ""; } - + quads = Quad.createSet( text.length() ); realLength = 0; - + int length = text.length(); for (int i=0; i < length; i++) { RectF rect = font.get( text.charAt( i ) ); - + if (rect == null) { rect=null; } float w = font.width( rect ); float h = font.height( rect ); - + vertices[0] = width; vertices[1] = 0; - + vertices[2] = rect.left; vertices[3] = rect.top; - + vertices[4] = width + w; vertices[5] = 0; - + vertices[6] = rect.right; vertices[7] = rect.top; - + vertices[8] = width + w; vertices[9] = h; - + vertices[10] = rect.right; vertices[11] = rect.bottom; - + vertices[12] = width; vertices[13] = h; - + vertices[14] = rect.left; vertices[15] = rect.bottom; - + quads.put( vertices ); realLength++; - + width += w + font.tracking; if (h > height) { height = h; } } - + if (length > 0) { width -= font.tracking; } - + dirty = false; - + } - - public void measure() { - + + public synchronized void measure() { + width = 0; height = 0; - + if (text == null) { text = ""; } - + int length = text.length(); for (int i=0; i < length; i++) { RectF rect = font.get( text.charAt( i ) ); - + float w = font.width( rect ); float h = font.height( rect ); - + width += w + font.tracking; if (h > height) { height = h; } } - + if (length > 0) { width -= font.tracking; } } - + public float baseLine() { return font.baseLine * scale.y; } - + public Font font() { return font; } - - public void font( Font value ) { + + public synchronized void font( Font value ) { font = value; } - + public String text() { return text; } - - public void text( String str ) { + + public synchronized void text( String str ) { text = str; dirty = true; }