laya-coreui-es
Version:
laya核心库、ui库es版本,剔除了媒体、TTF等功能。基于 LayaAir-release_2.12.0 修改
75 lines (74 loc) • 2.49 kB
JavaScript
import { UIComponent } from "../../laya/ui/UIComponent";
import { Laya } from "./../../Laya";
import { Matrix } from "../../laya/maths/Matrix";
import { Texture } from "../../laya/resource/Texture";
import { Texture2D } from "../resource/Texture2D";
export class WXOpenDataViewer extends UIComponent {
constructor() {
super();
this._width = this._height = 200;
var tex = new Texture();
tex.bitmap = new Texture2D();
this.texture = tex;
}
onEnable() {
this.postMsg({ type: "display", rate: Laya.stage.frameRate });
if (window.wx && window.sharedCanvas)
Laya.timer.frameLoop(1, this, this._onLoop);
}
onDisable() {
this.postMsg({ type: "undisplay" });
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();
mat.translate(this.x, this.y);
var stage = 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);
}
}
}