import { Game } from "../Game" ; import { SceneNode , SceneNodeArgs } from "./SceneNode" ; import { BitmapFont } from "../BitmapFont" ; /**
 * Constructor arguments for [[TextNode]].
 */ export interface TextNodeArgs extends SceneNodeArgs { /** The initial font used to draw the text. */ font : BitmapFont ; /** Optional initial text to draw. Defaults to empty string. */ text ? : string ; /** Optional initial text color. Defaults to "white". */ color ? : string ; /** Optional initial outline text color. Default is null which means no outline is drawn. */ outlineColor ? : string | null ; } param T export class TextNode < T extends Game = Game > extends SceneNode < T > { /** The font used to draw the text. */ private font : BitmapFont ; /** The text to draw. */ private text : string ; /** The text color. */ private color : string ; /** Optional outline color. */ private outlineColor : string | null ; /**
     * Creates a new scene node displaying the given image.
     */ public constructor ( { font , text = "" , color = "white" , outlineColor = null , ... args } ) { super ( args ) ; this . font = font ; this . text = text ; this . color = color ; this . outlineColor = outlineColor ; this . updateSize ( ) ; } return public getText ( ) { return this . text ; } param text public setText ( text ) { if ( text !== this . text ) { this . text = text ; this . updateSize ( ) ; this . invalidate ( ) ; } return this ; } return public getFont ( ) { return this . font ; } param font public setFont ( font ) { if ( font !== this . font ) { this . font = font ; this . updateSize ( ) ; this . invalidate ( ) ; } return this ; } return public getColor ( ) { return this . color ; } param color public setColor ( color ) { if ( color !== this . color ) { this . color = color ; this . invalidate ( ) ; } return this ; } return public getOutlineColor ( ) { return this . outlineColor ; } param outlineColor public setOutlineColor ( outlineColor ) { if ( outlineColor !== this . outlineColor ) { this . outlineColor = outlineColor ; this . invalidate ( ) ; } return this ; } /**
     * Updates the node size according to the text measurements.
     */ private updateSize ( ) { const size = this . font . measureText ( this . text ) ; this . resizeTo ( size . width , size . height ) ; } inheritDoc public draw ( ctx ) { if ( this . outlineColor != null ) { this . font . drawTextWithOutline ( ctx , this . text , 0 , 0 , this . color , this . outlineColor ) ; } else { this . font . drawText ( ctx , this . text , 0 , 0 , this . color ) ; } } }