|
@@ -13,14 +13,15 @@ class Text extends Drawable {
|
|
public var textColor(default, set) : Int;
|
|
public var textColor(default, set) : Int;
|
|
public var maxWidth(default, set) : Null<Float>;
|
|
public var maxWidth(default, set) : Null<Float>;
|
|
public var dropShadow : { dx : Float, dy : Float, color : Int, alpha : Float };
|
|
public var dropShadow : { dx : Float, dy : Float, color : Int, alpha : Float };
|
|
-
|
|
|
|
|
|
+
|
|
public var textWidth(get, null) : Int;
|
|
public var textWidth(get, null) : Int;
|
|
public var textHeight(get, null) : Int;
|
|
public var textHeight(get, null) : Int;
|
|
public var textAlign(default, set) : Align;
|
|
public var textAlign(default, set) : Align;
|
|
- public var letterSpacing(default,set) : Int;
|
|
|
|
-
|
|
|
|
|
|
+ public var letterSpacing(default, set) : Int;
|
|
|
|
+ public var lineSpacing(default,set) : Int;
|
|
|
|
+
|
|
var glyphs : TileGroup;
|
|
var glyphs : TileGroup;
|
|
-
|
|
|
|
|
|
+
|
|
public function new( font : Font, ?parent ) {
|
|
public function new( font : Font, ?parent ) {
|
|
super(parent);
|
|
super(parent);
|
|
this.font = font;
|
|
this.font = font;
|
|
@@ -29,7 +30,7 @@ class Text extends Drawable {
|
|
text = "";
|
|
text = "";
|
|
textColor = 0xFFFFFF;
|
|
textColor = 0xFFFFFF;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
function set_font(font) {
|
|
function set_font(font) {
|
|
this.font = font;
|
|
this.font = font;
|
|
if( glyphs != null ) glyphs.remove();
|
|
if( glyphs != null ) glyphs.remove();
|
|
@@ -38,7 +39,7 @@ class Text extends Drawable {
|
|
rebuild();
|
|
rebuild();
|
|
return font;
|
|
return font;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
function set_textAlign(a) {
|
|
function set_textAlign(a) {
|
|
textAlign = a;
|
|
textAlign = a;
|
|
rebuild();
|
|
rebuild();
|
|
@@ -50,12 +51,18 @@ class Text extends Drawable {
|
|
rebuild();
|
|
rebuild();
|
|
return s;
|
|
return s;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ function set_lineSpacing(s) {
|
|
|
|
+ lineSpacing = s;
|
|
|
|
+ rebuild();
|
|
|
|
+ return s;
|
|
|
|
+ }
|
|
|
|
+
|
|
override function onAlloc() {
|
|
override function onAlloc() {
|
|
super.onAlloc();
|
|
super.onAlloc();
|
|
rebuild();
|
|
rebuild();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
override function draw(ctx:RenderContext) {
|
|
override function draw(ctx:RenderContext) {
|
|
glyphs.blendMode = blendMode;
|
|
glyphs.blendMode = blendMode;
|
|
if( dropShadow != null ) {
|
|
if( dropShadow != null ) {
|
|
@@ -72,7 +79,7 @@ class Text extends Drawable {
|
|
}
|
|
}
|
|
super.draw(ctx);
|
|
super.draw(ctx);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
function set_text(t) {
|
|
function set_text(t) {
|
|
var t = t == null ? "null" : t;
|
|
var t = t == null ? "null" : t;
|
|
if( t == this.text ) return t;
|
|
if( t == this.text ) return t;
|
|
@@ -80,11 +87,11 @@ class Text extends Drawable {
|
|
rebuild();
|
|
rebuild();
|
|
return t;
|
|
return t;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
function rebuild() {
|
|
function rebuild() {
|
|
if( allocated && text != null && font != null ) initGlyphs(text);
|
|
if( allocated && text != null && font != null ) initGlyphs(text);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function calcTextWidth( text : String ) {
|
|
public function calcTextWidth( text : String ) {
|
|
return initGlyphs(text,false).width;
|
|
return initGlyphs(text,false).width;
|
|
}
|
|
}
|
|
@@ -104,6 +111,7 @@ class Text extends Drawable {
|
|
x = lines.shift();
|
|
x = lines.shift();
|
|
default:
|
|
default:
|
|
}
|
|
}
|
|
|
|
+ var dl = font.lineHeight + lineSpacing;
|
|
var calcLines = !rebuild && lines != null;
|
|
var calcLines = !rebuild && lines != null;
|
|
for( i in 0...text.length ) {
|
|
for( i in 0...text.length ) {
|
|
var cc = text.charCodeAt(i);
|
|
var cc = text.charCodeAt(i);
|
|
@@ -143,29 +151,29 @@ class Text extends Drawable {
|
|
}
|
|
}
|
|
else
|
|
else
|
|
x = 0;
|
|
x = 0;
|
|
- y += font.lineHeight;
|
|
|
|
|
|
+ y += dl;
|
|
prevChar = -1;
|
|
prevChar = -1;
|
|
} else
|
|
} else
|
|
prevChar = cc;
|
|
prevChar = cc;
|
|
}
|
|
}
|
|
if( calcLines ) lines.push(x);
|
|
if( calcLines ) lines.push(x);
|
|
- return { width : x > xMax ? x : xMax, height : x > 0 ? y + font.lineHeight : y > 0 ? y : font.lineHeight };
|
|
|
|
|
|
+ return { width : x > xMax ? x : xMax, height : x > 0 ? y + dl : y > 0 ? y : dl };
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
function get_textHeight() {
|
|
function get_textHeight() {
|
|
return initGlyphs(text,false).height;
|
|
return initGlyphs(text,false).height;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
function get_textWidth() {
|
|
function get_textWidth() {
|
|
return initGlyphs(text,false).width;
|
|
return initGlyphs(text,false).width;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
function set_maxWidth(w) {
|
|
function set_maxWidth(w) {
|
|
maxWidth = w;
|
|
maxWidth = w;
|
|
rebuild();
|
|
rebuild();
|
|
return w;
|
|
return w;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
function set_textColor(c) {
|
|
function set_textColor(c) {
|
|
this.textColor = c;
|
|
this.textColor = c;
|
|
glyphs.color = h3d.Vector.fromColor(c);
|
|
glyphs.color = h3d.Vector.fromColor(c);
|