UNPKG

laya-coreui-es

Version:

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

79 lines (78 loc) 2.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.WXOpenDataViewer = void 0; const UIComponent_1 = require("../../laya/ui/UIComponent"); const Laya_1 = require("./../../Laya"); const Matrix_1 = require("../../laya/maths/Matrix"); const Texture_1 = require("../../laya/resource/Texture"); const Texture2D_1 = require("../resource/Texture2D"); class WXOpenDataViewer extends UIComponent_1.UIComponent { constructor() { super(); this._width = this._height = 200; var tex = new Texture_1.Texture(); tex.bitmap = new Texture2D_1.Texture2D(); this.texture = tex; } onEnable() { this.postMsg({ type: "display", rate: Laya_1.Laya.stage.frameRate }); if (window.wx && window.sharedCanvas) Laya_1.Laya.timer.frameLoop(1, this, this._onLoop); } onDisable() { this.postMsg({ type: "undisplay" }); Laya_1.Laya.timer.clear(this, this._onLoop); } _onLoop() { let _canvas = window.sharedCanvas; this.texture.sourceWidth = _canvas.width; this.texture.sourceHeight = _canvas.height; this.texture.bitmap.loadImageSource(_canvas); } set width(value) { super.width = value; if (window.sharedCanvas) window.sharedCanvas.width = value; this.callLater(this._postMsg); } get width() { return super.width; } set height(value) { super.height = value; if (window.sharedCanvas) window.sharedCanvas.height = value; this.callLater(this._postMsg); } get height() { return super.height; } set x(value) { super.x = value; this.callLater(this._postMsg); } get x() { return super.x; } set y(value) { super.y = value; this.callLater(this._postMsg); } get y() { return super.y; } _postMsg() { var mat = new Matrix_1.Matrix(); mat.translate(this.x, this.y); var stage = Laya_1.Laya.stage; mat.scale(stage._canvasTransform.getScaleX() * this.globalScaleX * stage.transform.getScaleX(), stage._canvasTransform.getScaleY() * this.globalScaleY * stage.transform.getScaleY()); this.postMsg({ type: "changeMatrix", a: mat.a, b: mat.b, c: mat.c, d: mat.d, tx: mat.tx, ty: mat.ty, w: this.width, h: this.height }); } postMsg(msg) { if (window.wx && window.wx.getOpenDataContext) { var openDataContext = window.wx.getOpenDataContext(); openDataContext.postMessage(msg); } } } exports.WXOpenDataViewer = WXOpenDataViewer;