/* * ******************************************************************************************************************** * * :*$@@%$*: ;: ;; ;; * :@@%! :!@@%: %! ;%%@@%$ =@@@@@@@%; @%@@@%%%%@@@@@ * :@%; :$= %%$$$%$$ ;$$ ;$@= !@$ * =@! %! @ $=;% !@@@%: !$$$$$$$$$$$$$$= * =@* %! @ $= % %@= =%@! %= * *$%%! @@= ;=$%%%$*: %! @ $= % =%%%%%%@$ *%: =% * %@@!: !@@@%=$@@@@%! :*@@$: %! @ $= % $* ;@ @* :%* * ;@@! ;!!!;: ;@%: =======@%========* @ $$ % $%*****$@ :@$=*********=@$ * $@* ;@@@%=!: *@* * =@$ ;;;!=%@@@@=! =@! * %@$: =@%: :*@@@* %@= Copyright (c) 2016-2020. 北京上格云技术有限公司 * ;%@@$=$@@%* *@@@$=%@@%; * ::;:: ::;:: All rights reserved. * * ******************************************************************************************************************** */ import { SGraphyItem } from "@saga-web/graphy/lib"; import { SColor, SPainter, SPoint, SRect } from "@saga-web/draw/lib"; import { SMouseEvent } from "@saga-web/base/lib"; import { Equip } from "../types/Equip"; import { Point } from "../types/Point"; import { ItemOrder } from "../types/ItemOrder"; /** * 设备item * * @author 郝建龙 */ export class EquipItem extends SGraphyItem { /** 宽度 */ _width: number = 400; /** X轴坐标 */ get width(): number { return this._width; } // Get width set width(v: number) { this._width = v; if (this.data) { this.data.Size.Width = v; } // this.minX = this.pos.x - v / 2; // this.maxX = this.pos.x + v / 2; this.update(); } // Set width /** 高度 */ _height: number = 300; /** X轴坐标 */ get height(): number { return this._height; } // Get width set height(v: number) { this._height = v; if (this.data) { this.data.Size.Height = v; } this.update(); } // Set width /** 设备数据 */ data: Equip | null = null; /** 位置 */ pos: SPoint = new SPoint(0, 0); /** X轴坐标 */ get x(): number { return this.pos.x; } // Get x set x(v: number) { this.pos.x = v; this.$emit("changePos"); this.update(); } // Set x /** Y轴坐标 */ get y(): number { return this.pos.y; } // Get y set y(v: number) { this.pos.y = v; this.$emit("changePos"); this.update(); } // Set y /** 展示的图片路径 */ Img: CanvasImageSource | undefined; constructor(parent: SGraphyItem | null, data: Equip) { super(parent); if (data.Size.Width) { this.width = data.Size.Width; } if (data.Size.Height) { this.height = data.Size.Height; } if (data.ImgSource) { this.Img = new Image(); this.Img.src = data.ImgSource; } this.data = data; this.name = data.Name || ""; this.moveable = true; this.zOrder = ItemOrder.EquipOrder; this.update(); } // Constructor /** * Item对象边界区域 * * @return SRect */ boundingRect(): SRect { return new SRect( -this.width / 2, -this.height / 2, this.width, this.height ); } // Function boundingRect() /** * 鼠标按下事件 * */ onMouseDown(event: SMouseEvent): boolean { if (this.selectable) { this.selected = !this.selected; } this.$emit("click", event); super.onMouseDown(event); return true; } // Function onMouseDown /** * 鼠标右键事件 * * @param event 事件参数 * @return boolean */ onContextMenu(event: SMouseEvent): boolean { this.$emit("ContextMenu", event); return true; } // Function onContextMenu() /** * Item绘制操作 * * @param painter painter对象 */ onDraw(painter: SPainter): void { painter.brush.color = SColor.White; if (this.Img) { painter.drawImage( this.Img, -this.width / 2, -this.height / 2, this.width, this.height ); } else { painter.drawRect( -this.width / 2, -this.height / 2, this.width, this.height ); } if (this.name) { painter.brush.color = SColor.Black; painter.font.size = 12; painter.drawText(this.name, -20, this.height / 2 + 15); } } // Function onDraw() } // Class EquipItem