Browse Source

解决点用CPU问题。

sybotan 5 years ago
parent
commit
9333a07bf5

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

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

+ 12 - 7
saga-web-draw/src/SCanvasView.ts

@@ -15,6 +15,7 @@ import { SPainter } from "./SPainter";
  * @author  庞利祥(sybotan@126.com)
  */
 export class SCanvasView extends SObject {
+    private _needDraw = true;
     /** canvas视图 */
     protected readonly canvasView: HTMLCanvasElement;
     get canvas(): CanvasRenderingContext2D | null {
@@ -42,7 +43,9 @@ export class SCanvasView extends SObject {
         }
         this._origin.x = v.x;
         this._origin.y = v.y;
+        this._needDraw = true;
     } // Set origin
+
     /** 可否进行平移操作 */
     moveable = true;
     /** 缩放比例 */
@@ -55,6 +58,7 @@ export class SCanvasView extends SObject {
             return;
         }
         this._scale = v;
+        this._needDraw = true;
     } // Set scale
 
     /** 可否执行绽放操作 */
@@ -100,12 +104,7 @@ export class SCanvasView extends SObject {
      * 更新视图
      */
     update(): void {
-        /** painter对象 */
-        let ctx = this.canvas;
-        if (null != ctx) {
-            let painter = new SPainter(this);
-            this.onDraw(painter);
-        }
+        this._needDraw = true;
     } // Function update()
 
     /**
@@ -188,7 +187,13 @@ export class SCanvasView extends SObject {
      * 循环
      */
     protected loop(): void {
-        this.update();
+        /** painter对象 */
+        let ctx = this.canvas;
+        if (null != ctx && this._needDraw) {
+            let painter = new SPainter(this);
+            this.onDraw(painter);
+            this._needDraw = false;
+        }
         this.requestAnimationFrame(this.loop.bind(this));
     } // Function loop()
 

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

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

+ 20 - 4
saga-web-graphy/src/SGraphyItem.ts

@@ -21,6 +21,7 @@ export class SGraphyItem extends SObject {
     } // Get scene
     set scene(v: SGraphyScene | null) {
         this._scene = v;
+        this.update();
     } // Set scene
     /** parent属性存值函数 */
     private _parent: SGraphyItem | null = null;
@@ -39,7 +40,7 @@ export class SGraphyItem extends SObject {
             this._parent.children.splice(i, 1);
         }
         this._parent = v;
-
+        this.update();
         // 如果新parent不为空
         if (this._parent != null) {
             // 将节点加入到新parent节点中
@@ -61,6 +62,7 @@ export class SGraphyItem extends SObject {
         if (this._parent != null) {
             this._parent.children.sort(SGraphyItem.sortItemZOrder);
         }
+        this.update();
     } // Set zOrder
 
     /** 位置 */
@@ -71,6 +73,7 @@ export class SGraphyItem extends SObject {
     } // Get x
     set x(v: number) {
         this.pos.x = v;
+        this.update();
     } // Set x
     /** Y轴坐标 */
     get y(): number {
@@ -78,12 +81,20 @@ export class SGraphyItem extends SObject {
     } // Get y
     set y(v: number) {
         this.pos.y = v;
+        this.update();
     } // Set y
     /** 缩放比例 */
     scale: number = 1;
 
     /** 是否可见 */
-    visible: boolean = true;
+    _visible: boolean = true;
+    get visible(): boolean {
+        return this._visible;
+    } // Get visible
+    set visible(v: boolean) {
+        this._visible = v;
+        this.update();
+    } // Set visible
 
     /** 是否可以移动 */
     moveable: boolean = false;
@@ -106,6 +117,7 @@ export class SGraphyItem extends SObject {
             return;
         }
         this._selected = value;
+        this.update();
     } // Set selected
 
     /** 是否进行变形 */
@@ -186,8 +198,12 @@ export class SGraphyItem extends SObject {
      * 更新Item
      */
     update(): void {
-        // TODO: PLX
-        // scene?.update()
+        if(null != this.scene) {
+            const view = this.scene.view;
+            if(null != view) {
+                view.update();
+            }
+        }
     } // Function update()
 
     /**