// ================================================================================================= // // Starling Framework // Copyright 2011 Gamua OG. All Rights Reserved. // // This program is free software. You can redistribute and/or modify it // in accordance with the terms of the accompanying license agreement. // // ================================================================================================= package starling.text { import flash.display.BitmapData; import flash.geom.Matrix; import flash.geom.Rectangle; import flash.text.AntiAliasType; import flash.text.TextField; import flash.text.TextFormat; import flash.utils.Dictionary; import starling.core.RenderSupport; import starling.display.DisplayObject; import starling.display.DisplayObjectContainer; import starling.display.Image; import starling.display.Quad; import starling.display.Sprite; import starling.events.Event; import starling.textures.Texture; import starling.utils.HAlign; import starling.utils.VAlign; /** A TextField displays text, either using standard true type fonts or custom bitmap fonts. * *
You can set all properties you are used to, like the font name and size, a color, the * horizontal and vertical alignment, etc. The border property is helpful during development, * because it lets you see the bounds of the textfield.
* *There are two types of fonts that can be displayed:
* *registerBitmapFont, and then pass
* the font name to the corresponding property of the text field.BitmapFont.NATIVE_SIZE for
* the original size. */
public function get fontSize():Number { return mFontSize; }
public function set fontSize(value:Number):void
{
if (mFontSize != value)
{
mFontSize = value;
mRequiresRedraw = true;
}
}
/** The color of the text. For bitmap fonts, use Color.WHITE to use the
* original, untinted color. @default black */
public function get color():uint { return mColor; }
public function set color(value:uint):void
{
if (mColor != value)
{
mColor = value;
updateBorder();
if (mContents)
{
if (mIsRenderedText)
(mContents as Image).color = value;
else
mRequiresRedraw = true;
}
}
}
/** The horizontal alignment of the text. @default center @see starling.utils.HAlign */
public function get hAlign():String { return mHAlign; }
public function set hAlign(value:String):void
{
if (!HAlign.isValid(value))
throw new ArgumentError("Invalid horizontal align: " + value);
if (mHAlign != value)
{
mHAlign = value;
mRequiresRedraw = true;
}
}
/** The vertical alignment of the text. @default center @see starling.utils.VAlign */
public function get vAlign():String { return mVAlign; }
public function set vAlign(value:String):void
{
if (!VAlign.isValid(value))
throw new ArgumentError("Invalid vertical align: " + value);
if (mVAlign != value)
{
mVAlign = value;
mRequiresRedraw = true;
}
}
/** Draws a border around the edges of the text field. Useful for visual debugging.
* @default false */
public function get border():Boolean { return mBorder != null; }
public function set border(value:Boolean):void
{
if (value && mBorder == null)
{
mBorder = new Sprite();
addChild(mBorder);
for (var i:int=0; i<4; ++i)
mBorder.addChild(new Quad(1.0, 1.0));
updateBorder();
}
else if (!value && mBorder != null)
{
mBorder.removeFromParent(true);
mBorder = null;
}
}
/** Indicates whether the text is bold. @default false */
public function get bold():Boolean { return mBold; }
public function set bold(value:Boolean):void
{
if (mBold != value)
{
mBold = value;
mRequiresRedraw = true;
}
}
/** Indicates whether the text is italicized. @default false */
public function get italic():Boolean { return mItalic; }
public function set italic(value:Boolean):void
{
if (mItalic != value)
{
mItalic = value;
mRequiresRedraw = true;
}
}
/** Indicates whether the text is underlined. @default false */
public function get underline():Boolean { return mUnderline; }
public function set underline(value:Boolean):void
{
if (mUnderline != value)
{
mUnderline = value;
mRequiresRedraw = true;
}
}
/** Indicates whether kerning is enabled. @default true */
public function get kerning():Boolean { return mKerning; }
public function set kerning(value:Boolean):void
{
if (mKerning != value)
{
mKerning = value;
mRequiresRedraw = true;
}
}
/** Indicates whether the font size is scaled down so that the complete text fits
* into the text field. @default false */
public function get autoScale():Boolean { return mAutoScale; }
public function set autoScale(value:Boolean):void
{
if (mAutoScale != value)
{
mAutoScale = value;
mRequiresRedraw = true;
}
}
/** Makes a bitmap font available at any text field. Set the fontName property
* of a text field to the name value of the bitmap font to use the bitmap
* font for rendering. */
public static function registerBitmapFont(bitmapFont:BitmapFont):void
{
sBitmapFonts[bitmapFont.name] = bitmapFont;
}
/** Unregisters the bitmap font and, optionally, disposes it. */
public static function unregisterBitmapFont(name:String, dispose:Boolean=true):void
{
if (dispose && sBitmapFonts[name] != undefined)
sBitmapFonts[name].dispose();
delete sBitmapFonts[name];
}
}
}