import {Container, Rectangle, Texture, Sprite} from './../com/pixi.min'; export default class Rect extends Container { /** * @param {String} name - имя текстуры * @param {Object} _options */ isRect: boolean; alpha: number; scale: any; wc: number; hc: number; w: number; h: number; s: number; SW: number; SH: number; EW: number; EH: number; imgs: any[]; sectorsW: number[]; sectorsH: number[]; constructor(name, _options: any = {a: 1}) { super(); this.isRect = true; let options = Object.assign({left: 0.3, top: 0.3, s: 1}, _options); let tex = Texture.fromFrame(name); tex.sector = tex.frame; let picture = {W: tex.frame.width, H: tex.frame.height}; let W = picture.W; let H = picture.H; this.alpha = .5;// options.a || .5; this.wc = options.left; this.hc = options.top; this.scale.x = this.scale.y = this.s = options.s; this.SW = this.h = picture.W; this.SH = this.w = picture.H; let w = this.EW = (W * this.wc); let h = this.EH = (H * this.hc); let sector = tex.sector; let sectorsW = this.sectorsW = [w, W - w * 2, w]; let sectorsH = this.sectorsH = [h, H - h * 2, h]; let sectorsWX = [0, w, w + sectorsW[1]]; let sectorsHY = [0, h, h + sectorsH[1]]; this.imgs = []; let x, y, img; for (let i = 0; i < 9; i++) { y = Math.floor(i / 3); x = i - y * 3; this.addChild(img = new Sprite(new Texture(tex, new Rectangle(sector.x + sectorsWX[x], sector.y + sectorsHY[y], sectorsW[x], sectorsH[y])))); img.x = sectorsWX[x]; img.y = sectorsHY[y]; this.imgs.push(img); } this.W = W; this.H = H; } addChild(child: any): any { super.addChild(child); } set Tint(v) { this.imgs.forEach(img => { img.tint = v; }) } get H() { return this.h * this.s; } set H(value) { this.h = Math.max(this.SH * this.s, value) / this.s; this.imgs[8].y = this.imgs[7].y = this.imgs[6].y = Math.max(this.EH, (this.h - this.EH)); this.imgs[5].scale.y = this.imgs[3].scale.y = this.imgs[4].scale.y = Math.max(0, (this.h - this.EH * 2) / this.sectorsH[1]); } get W() { return this.w * this.s; } set W(value) { this.w = Math.max(this.SW * this.s, value) / this.s; this.imgs[5].x = this.imgs[8].x = this.imgs[2].x = Math.max(this.EW, (this.w - this.EW)); this.imgs[4].scale.x = this.imgs[7].scale.x = this.imgs[1].scale.x = Math.max(0, (this.w - this.EW * 2) / this.sectorsW[1]); } }