Browse Source

文本类名修改

haojianlong 5 years ago
parent
commit
f4ba59f4a4

+ 11 - 0
saga-web-big/src/enums/SImageShowType.ts

@@ -0,0 +1,11 @@
+/**
+ * 图片item展示方式
+ *
+ * @author  haojianlong
+ */
+export enum SImageShowType {
+    /** 铺满  */
+    Full,
+    /** 自适应 */
+    AutoFit
+} // Enum SImageShowType

+ 26 - 12
saga-web-big/src/items/SImageItem.ts

@@ -1,6 +1,7 @@
 import { SObjectItem } from "./SObjectItem";
-import { SPainter, SRect } from "@saga-web/draw/lib";
+import { SPainter, SRect, SSize } from "@saga-web/draw/lib";
 import { SGraphItem } from "@saga-web/graph/lib";
+import { SImageShowType } from "../enums/SImageShowType";
 
 /**
  *  图片绘制
@@ -15,18 +16,22 @@ export class SImageItem extends SObjectItem {
     }
     set url(v: string) {
         this._url = v;
-        this.Img = new Image();
-        this.Img.src = v;
-        this.Img.onload = (): void => {
-            // @ts-ignore
-            this.width = this.Img.width;
-            // @ts-ignore
-            this.height = this.Img.height;
+        this.img = new Image();
+        this.img.src = v;
+        this.img.onload = (): void => {
+            if (this.showType == SImageShowType.AutoFit) {
+                // @ts-ignore
+                this.width = this.Img.width;
+                // @ts-ignore
+                this.height = this.Img.height;
+            }
             this.update();
         };
     }
     /** 图片dom */
-    Img: CanvasImageSource | undefined;
+    img: CanvasImageSource | undefined;
+    /** 展示模式    */
+    showType: SImageShowType = SImageShowType.Full;
 
     /**
      * 构造函数
@@ -35,7 +40,6 @@ export class SImageItem extends SObjectItem {
      * */
     constructor(parent: SGraphItem | null) {
         super(parent);
-        this.isTransform = false;
     }
 
     /**
@@ -53,14 +57,24 @@ export class SImageItem extends SObjectItem {
     }
 
     /**
+     * 宽高发发生变化
+     *
+     * @param   oldSize 改之前的大小
+     * @param   newSize 改之后大小
+     * */
+    protected onResize(oldSize: SSize, newSize: SSize) {
+        this.update();
+    } // Function onResize()
+
+    /**
      * Item绘制操作
      *
      * @param   painter       painter对象
      */
     onDraw(painter: SPainter): void {
-        if (this.Img) {
+        if (this.img) {
             painter.drawImage(
-                this.Img,
+                this.img,
                 -this.width / 2,
                 -this.height / 2,
                 this.width,

+ 1 - 1
saga-web-big/src/items/STextItem.ts

@@ -7,7 +7,7 @@ import { SGraphItem } from "@saga-web/graph/lib";
  *
  * @author  张宇(taohuzy@163.com)
  */
-class TextItem extends SObjectItem {
+export class STextItem extends SObjectItem {
     /** 文本内容 */
     private _text: string = "";
     get text(): string {

+ 20 - 1
saga-web-big/src/items/topology/SAnchorItem.ts

@@ -1,8 +1,27 @@
 import { SGraphItem } from "@saga-web/graph/lib";
+import { SPainter } from "@saga-web/draw/lib";
 
 /**
  * 锚点item
  *
  * @author  郝建龙(1061851420@qq.com)
  */
-export class SAnchorItem extends SGraphItem {} // Class SAnchorItem
+export class SAnchorItem extends SGraphItem {
+    // private width: number;
+    // private height: number;
+    //
+    // /**
+    //  * Item绘制操作
+    //  *
+    //  * @param   painter       painter对象
+    //  */
+    // onDraw(painter: SPainter): void {
+    //     painter.pen.lineWidth = painter.toPx(1);
+    //     painter.drawRect(
+    //         -this.width / 2,
+    //         -this.height / 2,
+    //         this.width,
+    //         this.height
+    //     );
+    // } // Function onDraw()
+} // Class SAnchorItem

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

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/feng-map",
-    "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.9.3"
     },
     "dependencies": {
-        "@saga-web/big": "1.0.9"
+        "@saga-web/big": "^1.0.17"
     }
 }

+ 61 - 0
saga-web-graph/src/commands/SGraphPropertyCommand.ts

@@ -0,0 +1,61 @@
+import { SGraphCommand } from "./SGraphCommand";
+import { SGraphItem } from "../SGraphItem";
+import { SGraphScene } from "../SGraphScene";
+
+/**
+ * 属性修改命令类
+ *
+ * @author  张宇(taohuzy@163.com)
+ */
+
+class SGraphPropertyCommand<T> extends SGraphCommand {
+    /**	指向item对象	*/
+    item: SGraphItem;
+    /** 属性名称 */
+    propName: string;
+    /** 属性旧值 */
+    oldProp: T;
+    /** 属性新值 */
+    newProp: T;
+
+    /**
+     * 构造函数
+     *
+     * @param   scene       命令所属的场景类
+     * @param   item        命令所属的item类
+     * @param   propName    修改的属性名称
+     * @param   oldProp     修改前的属性值
+     * @param   newProp     修改后的属性值
+     */
+    constructor(
+        scene: SGraphScene,
+        item: SGraphItem,
+        propName: string,
+        oldProp: T,
+        newProp: T
+    ) {
+        super(scene);
+        this.item = item;
+        this.propName = propName;
+        this.oldProp = oldProp;
+        this.newProp = newProp;
+    } // Constructor
+
+    /**
+     * redo操作
+     */
+    redo(): void {
+        // @ts-ignore
+        this.item[this.propName] = this.newProp;
+        this.item.update();
+    } // Function redo()
+
+    /**
+     * undo操作
+     */
+    undo(): void {
+        // @ts-ignore
+        this.item[this.propName] = this.oldProp;
+        this.item.update();
+    } // Function undo()
+} // Class SGraphPropertyCommand