haojianlong 5 лет назад
Родитель
Сommit
86c64eca63

+ 2 - 2
saga-web-big/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/big",
-    "version": "1.0.6",
+    "version": "1.0.7",
     "description": "上格云Web平面图。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
@@ -32,6 +32,6 @@
         "typescript": "^3.5.3"
     },
     "dependencies": {
-        "@saga-web/graphy": "2.1.52"
+        "@saga-web/graphy": "2.1.53"
     }
 }

+ 3 - 1
saga-web-big/src/index.ts

@@ -21,6 +21,7 @@ import { SZoneParser } from "./parser/SZoneParser";
 import { STopologyParser } from "./parser/STopologyParser";
 import { SFloorParser } from "./parser/SFloorParser";
 import { SParser } from "./parser/SParser";
+import { SIconTextItem } from "./items/SIconTextItem";
 
 export {
     SAnchorItem,
@@ -45,5 +46,6 @@ export {
     STopologyParser,
     SZoneParser,
     SEquipParser,
-    SBigParser
+    SBigParser,
+    SIconTextItem
 };

+ 1 - 70
saga-web-big/src/items/SIconTextItem.ts

@@ -1,6 +1,4 @@
 import { SGraphyItem } from "@saga-web/graphy/lib";
-import { ImageData } from "../types/ImageData";
-import { SPainter, SRect } from "@saga-web/draw/lib";
 import { SMouseEvent } from "@saga-web/base/lib";
 
 /**
@@ -9,48 +7,13 @@ import { SMouseEvent } from "@saga-web/base/lib";
  * * @author  郝建龙(1061851420@qq.com)
  */
 export class SIconTextItem extends SGraphyItem {
-    /** 标志宽度 */
-    private width: number = 20;
-    /** 标志高度 */
-    private height: number = 20;
-    /** 图片地址    */
-    url: string = "";
-    /** 图片dom */
-    Img: CanvasImageSource | undefined;
-    /** 图片item所有数据  */
-    private data: ImageData;
-    /** 绘制的文本   */
-    _text: string = "";
-    get text(): string {
-        return this._text;
-    }
-    set text(val) {
-        this._text = val;
-        this.update();
-    }
-
     /**
      * 构造函数
      *
      *  @param parent    指向父对象
-     *  @param data      图片数据
      * */
-    constructor(parent: SGraphyItem | null, data: ImageData) {
+    constructor(parent: SGraphyItem | null) {
         super(parent);
-        this.data = data;
-        if (data.Url) {
-            this.Img = new Image();
-            this.url = data.Url;
-            this.Img.src = this.url;
-            this.Img.onload = (): void => {
-                // @ts-ignore
-                this.width = data.Width ? data.Width : this.Img.width;
-                // @ts-ignore
-                this.height = data.Height ? data.Height : this.Img.height;
-                this.update();
-            };
-        }
-        this.isTransform = false;
     }
 
     /**
@@ -65,36 +28,4 @@ export class SIconTextItem extends SGraphyItem {
         this.update();
         return true;
     } // Function onMouseDown()
-
-    /**
-     * Item对象边界区域
-     *
-     * @return	SRect
-     */
-    boundingRect(): SRect {
-        return new SRect(
-            -this.width / 2,
-            this.height / 2,
-            this.width,
-            this.height
-        );
-    }
-
-    /**
-     * Item绘制操作
-     *
-     * @param   painter       painter对象
-     */
-    onDraw(painter: SPainter): void {
-        if (this.Img) {
-            painter.drawImage(
-                this.Img,
-                -this.width / 2,
-                this.height / 2,
-                this.width,
-                this.height
-            );
-            painter.drawText(this.text, this.width, this.height / 2);
-        }
-    } // Function onDraw()
 } // Class SImageItem

+ 78 - 40
saga-web-big/src/items/STextItem.ts

@@ -1,13 +1,11 @@
 import { SObjectItem } from "./SObjectItem";
-import { TextData } from "../types/TextData";
-import { SGraphyItem } from "@saga-web/graphy/lib";
 import {
     SPainter,
     SRect,
-    STextAlign,
-    STextBaseLine,
-    STextDirection
+    SColor,
+    SFont
 } from "@saga-web/draw/lib";
+import { SMouseEvent } from "@saga-web/base/lib";
 
 /**
  * 文本item
@@ -15,40 +13,42 @@ import {
  * @author  郝建龙(1061851420@qq.com)
  */
 export class STextItem extends SObjectItem {
-    /** 文本item所有数据  */
-    data: TextData | null = null;
     /** 文本内容    */
-    text: string = "";
-    /** 文本对齐    */
-    private textAlign: STextAlign;
-    /** 文本基准线   */
-    private baseLine: STextBaseLine;
-    /** 文本绘制方向  */
-    private textDirection: STextDirection;
+    _text: string = "";
+    get text(): string {
+        return this._text;
+    }
+    set text(v: string) {
+        this._text = v;
+        this.update();
+    }
+
+    /** 文本所占高度  */
+    private height: number = 0;
+    /** 文本所占宽度  */
+    private width: number = 0;
+
+    /** 字体  */
+    _font: SFont = new SFont();
+    get font(): SFont {
+        return this._font;
+    }
+    set font(v: SFont) {
+        this._font = v;
+        this.update();
+    }
+
     /** 文本绘制最大宽 */
     maxWidth: number | undefined = undefined;
-    /** 文本大小    */
-    private size: number;
 
-    /**
-     * 构造体
-     *
-     * @param   parent  指向父对象
-     * @param   data    文本数据
-     * */
-    constructor(parent: SGraphyItem | null, data: TextData) {
-        super(parent);
-        this.data = data;
-        this.text = data.Text;
-        this.textAlign = data.TextAlign ? data.TextAlign : STextAlign.Start;
-        this.baseLine = data.BaseLine
-            ? data.BaseLine
-            : STextBaseLine.Alphabetic;
-        this.textDirection = data.TextDirection
-            ? data.TextDirection
-            : STextDirection.Inherit;
-        this.maxWidth = data.Width;
-        this.size = data.Size ? data.Size : 12;
+    /** 文本颜色    */
+    private _color: string = "#000000";
+    get color(): string {
+        return this._color;
+    }
+    set color(v: string) {
+        this._color = v;
+        this.update();
     }
 
     /**
@@ -57,19 +57,57 @@ export class STextItem extends SObjectItem {
      * @return	SRect
      */
     boundingRect(): SRect {
-        return new SRect();
+        return new SRect(
+            -this.width / 2,
+            -this.height / 2,
+            this.width,
+            this.height
+        );
     }
 
     /**
+     * 判断点是否在区域内
+     *
+     * @param x
+     * @param y
+     */
+    contains(x: number, y: number): boolean {
+        return this.boundingRect().contains(x, y);
+    } // Function contains()
+
+    /**
+     * 鼠标单击事件
+     *
+     * @param	event         事件参数
+     * @return	boolean
+     */
+    onMouseDown(event: SMouseEvent): boolean {
+        console.log("textDown");
+        this.$emit("click", event);
+        return true;
+    } // Function onMouseDown()
+
+    /**
+     * 鼠标抬起事件
+     *
+     * @param	event         事件参数
+     * @return	boolean
+     */
+    onMouseUp(event: SMouseEvent): boolean {
+        console.log("textup");
+        return super.onMouseUp(event);
+    } // Function onClick()
+
+    /**
      * Item绘制操作
      *
      * @param   painter painter对象
      */
     onDraw(painter: SPainter): void {
-        painter.font.textAlign = this.textAlign;
-        painter.font.textBaseLine = this.baseLine;
-        painter.font.textDirection = this.textDirection;
-        painter.font.size = painter.toPx(this.size);
+        this.width = painter.toPx(painter.textWidth(this.text));
+        this.height = painter.toPx(this.font.size);
+        painter.font = this.font;
+        painter.brush.color = new SColor(this.color);
         painter.drawText(this.text, 0, 0, this.maxWidth);
     } // Function onDraw()
 } // Class STextItem

+ 1 - 1
saga-web-draw/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/draw",
-    "version": "2.1.80",
+    "version": "2.1.81",
     "description": "上格云绘制引擎。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",

+ 2 - 2
saga-web-graphy/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/graphy",
-    "version": "2.1.52",
+    "version": "2.1.53",
     "description": "上格云二维图形引擎。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
@@ -31,6 +31,6 @@
         "typescript": "^3.5.3"
     },
     "dependencies": {
-        "@saga-web/draw": "2.1.80"
+        "@saga-web/draw": "2.1.81"
     }
 }