UNPKG

laya-coreui-es

Version:

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

64 lines (63 loc) 2.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HTMLImageElement = void 0; const HTMLElement_1 = require("./HTMLElement"); const Event_1 = require("../../events/Event"); const Loader_1 = require("../../net/Loader"); const Texture_1 = require("../../resource/Texture"); const IHtml_1 = require("../utils/IHtml"); class HTMLImageElement extends HTMLElement_1.HTMLElement { constructor() { super(); this.eletype = HTMLElement_1.HTMLElementType.IMAGE; } reset() { super.reset(); if (this._tex) { this._tex.off(Event_1.Event.LOADED, this, this.onloaded); } this._tex = null; this._url = null; return this; } set src(url) { url = this.formatURL(url); if (this._url === url) return; this._url = url; var tex = this._tex = Loader_1.Loader.getRes(url); if (!tex) { this._tex = tex = new Texture_1.Texture(); tex.load(url); Loader_1.Loader.cacheTexture(url, tex); } tex.getIsReady() ? this.onloaded() : tex.once(Event_1.Event.READY, this, this.onloaded); } onloaded() { if (!this._style) return; var style = this._style; var w = style.widthed(this) ? -1 : this._tex.width; var h = style.heighted(this) ? -1 : this._tex.height; if (!style.widthed(this) && this._width != this._tex.width) { this.width = this._tex.width; this.parent && this.parent._layoutLater(); } if (!style.heighted(this) && this._height != this._tex.height) { this.height = this._tex.height; this.parent && this.parent._layoutLater(); } this.repaint(); } _addToLayout(out) { var style = this._style; !style.absolute && out.push(this); } renderSelfToGraphic(graphic, gX, gY, recList) { if (!this._tex) return; graphic.drawImage(this._tex, gX, gY, this.width || this._tex.width, this.height || this._tex.height); } } exports.HTMLImageElement = HTMLImageElement; IHtml_1.IHtml.HTMLImageElement = HTMLImageElement;