UNPKG

laya-coreui-es

Version:

laya核心库、ui库es版本,剔除了媒体、TTF等功能。基于 LayaAir-release_2.12.0 修改

95 lines (94 loc) 3.31 kB
import { Context } from "../../resource/Context"; import { ColorUtils } from "../../utils/ColorUtils"; import { FontInfo } from "../../utils/FontInfo"; import { Pool } from "../../utils/Pool"; import { WordText } from "../../utils/WordText"; import { ILaya } from "../../../ILaya"; export class FillTextCmd { constructor() { this._textIsWorldText = false; this._fontColor = 0xffffffff; this._strokeColor = 0; this._fontObj = FillTextCmd._defFontObj; this._nTexAlign = 0; } static create(text, words, x, y, font, color, textAlign, lineWidth, borderColor) { var cmd = Pool.getItemByClass("FillTextCmd", FillTextCmd); cmd.text = text; cmd._textIsWorldText = text instanceof WordText; cmd._words = words; cmd.x = x; cmd.y = y; cmd.font = font; cmd.color = color; cmd.textAlign = textAlign; cmd._lineWidth = lineWidth; cmd._borderColor = borderColor; return cmd; } recover() { Pool.recover("FillTextCmd", this); } run(context, gx, gy) { if (ILaya.stage.isGlobalRepaint()) { this._textIsWorldText && this._text.cleanCache(); } if (this._words) { Context._textRender.fillWords(context, this._words, this.x + gx, this.y + gy, this._fontObj, this._color, this._borderColor, this._lineWidth); } else { if (this._textIsWorldText) { context._fast_filltext(this._text, this.x + gx, this.y + gy, this._fontObj, this._color, this._borderColor, this._lineWidth, this._nTexAlign, 0); } else { Context._textRender.filltext(context, this._text, this.x + gx, this.y + gy, this.font, this.color, this._borderColor, this._lineWidth, this._textAlign); } } } get cmdID() { return FillTextCmd.ID; } get text() { return this._text; } set text(value) { this._text = value; this._textIsWorldText = value instanceof WordText; this._textIsWorldText && this._text.cleanCache(); } get font() { return this._font; } set font(value) { this._font = value; this._fontObj = FontInfo.Parse(value); this._textIsWorldText && this._text.cleanCache(); } get color() { return this._color; } set color(value) { this._color = value; this._fontColor = ColorUtils.create(value).numColor; this._textIsWorldText && this._text.cleanCache(); } get textAlign() { return this._textAlign; } set textAlign(value) { this._textAlign = value; switch (value) { case 'center': this._nTexAlign = ILaya.Context.ENUM_TEXTALIGN_CENTER; break; case 'right': this._nTexAlign = ILaya.Context.ENUM_TEXTALIGN_RIGHT; break; default: this._nTexAlign = ILaya.Context.ENUM_TEXTALIGN_DEFAULT; } this._textIsWorldText && this._text.cleanCache(); } } FillTextCmd.ID = "FillText"; FillTextCmd._defFontObj = new FontInfo(null);