| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- /*
- * ********************************************************************************************************************
- *
- * :*$@@%$*: ;: ;; ;;
- * :@@%! :!@@%: %! ;%%@@%$ =@@@@@@@%; @%@@@%%%%@@@@@
- * :@%; :$= %%$$$%$$ ;$$ ;$@= !@$
- * =@! %! @ $=;% !@@@%: !$$$$$$$$$$$$$$=
- * =@* %! @ $= % %@= =%@! %=
- * *$%%! @@= ;=$%%%$*: %! @ $= % =%%%%%%@$ *%: =%
- * %@@!: !@@@%=$@@@@%! :*@@$: %! @ $= % $* ;@ @* :%*
- * ;@@! ;!!!;: ;@%: =======@%========* @ $$ % $%*****$@ :@$=*********=@$
- * $@* ;@@@%=!: *@*
- * =@$ ;;;!=%@@@@=! =@!
- * %@$: =@%: :*@@@* %@= 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
|