Parcourir la source

空格+左键移动 wasd 移动 版本;将高亮item颜色移至opt

haojianlong il y a 5 ans
Parent
commit
01efc64def
5 fichiers modifiés avec 68 ajouts et 34 suppressions
  1. 1 1
      package.json
  2. 14 13
      src/DivideFloorScene.ts
  3. 42 2
      src/FloorView.ts
  4. 7 18
      src/items/HighlightItem.ts
  5. 4 0
      src/types/Opt.ts

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/cad-engine",
-    "version": "2.0.335",
+    "version": "2.0.341",
     "description": "上格云 CAD图形引擎。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",

+ 14 - 13
src/DivideFloorScene.ts

@@ -70,7 +70,7 @@ export class DivideFloorScene extends FloorScene {
     } // Set isZoneSelectable
 
     /** 高亮item  */
-    hightLight: HighlightItem = new HighlightItem(null, new SPoint(), 0);
+    hightLight: HighlightItem = new HighlightItem(null);
     /** 是否开启吸附  */
     private _isAbsorbing: boolean = false;
     get isAbsorbing(): boolean {
@@ -232,6 +232,7 @@ export class DivideFloorScene extends FloorScene {
     /**
      *  切换业务空间
      *
+     *  @param  zoneitem    需要隐藏的业务空间
      */
     changeSelectZone(zoneitem: ZoneItem): void {
         this.zoneList.map(zone => {
@@ -245,7 +246,7 @@ export class DivideFloorScene extends FloorScene {
     /**
      *  吸附空间
      *
-     *  @param  鼠标事件对象
+     *  @param  event   鼠标事件对象
      */
     onMouseMove(event: SMouseEvent): boolean {
         super.onMouseMove(event);
@@ -259,7 +260,7 @@ export class DivideFloorScene extends FloorScene {
     /**
      *  吸附空间
      *
-     *  @param  鼠标事件对象
+     *  @param  event   鼠标事件对象
      */
     absorbSpace(event: SMouseEvent): void {
         let absorbLen = 1000;
@@ -291,7 +292,7 @@ export class DivideFloorScene extends FloorScene {
      *  @param  maxX    空间区域
      *  @param  maxY    空间区域
      */
-    isPointInAbsorbArea(
+    static isPointInAbsorbArea(
         p: SPoint,
         minX: number,
         maxX: number,
@@ -301,7 +302,7 @@ export class DivideFloorScene extends FloorScene {
         let rect = new SRect(
             minX - 1000,
             minY - 1000,
-            maxX - minX + 200,
+            maxX - minX + 2000,
             maxY - minY + 2000
         );
         return rect.contains(p.x, p.y);
@@ -310,16 +311,16 @@ export class DivideFloorScene extends FloorScene {
     /**
      *  吸附点
      *
-     *  @param  鼠标事件对象
-     *  @param  吸附距离
-     *  @return 吸附的点
+     *  @param  event       鼠标事件对象
+     *  @param  absorbLen   吸附距离
+     *  @return MinDis      吸附的点
      */
     absorbPoint(event: SMouseEvent, absorbLen: number): MinDis {
         let minPointDis = Number.MAX_SAFE_INTEGER;
         let Point;
         this.spaceList.map(space => {
             if (
-                this.isPointInAbsorbArea(
+                DivideFloorScene.isPointInAbsorbArea(
                     new SPoint(event.x, event.y),
                     space.minX,
                     space.maxX,
@@ -353,16 +354,16 @@ export class DivideFloorScene extends FloorScene {
     /**
      *  吸附线
      *
-     *  @param  鼠标事件对象
-     *  @param  吸附距离
-     *  @return 吸附的线
+     *  @param  event       鼠标事件对象
+     *  @param  absorbLen   吸附距离
+     *  @return PointToLine 吸附的线
      */
     absorbLine(event: SMouseEvent, absorbLen: number): PointToLine {
         let minPointDis = Number.MAX_SAFE_INTEGER;
         let Point, Line;
         this.spaceList.map(space => {
             if (
-                this.isPointInAbsorbArea(
+                DivideFloorScene.isPointInAbsorbArea(
                     new SPoint(event.x, event.y),
                     space.minX,
                     space.maxX,

+ 42 - 2
src/FloorView.ts

@@ -30,6 +30,46 @@ import { SPoint } from "@saga-web/draw/lib";
 export class FloorView extends SGraphyView {
     /** 鼠标左键键按下时位置 */
     private _leftKeyPos = new SPoint();
+    /** 空格是否被按下 */
+    private spaceKey: boolean = false;
+
+    /**
+     * 按键按下事件
+     *
+     * @param   event       事件参数
+     */
+    protected onKeyDown(event: KeyboardEvent): void {
+        let keyCode = event.keyCode;
+        this.spaceKey = false;
+        if (keyCode == 32) {
+            // 空格按键
+            this.spaceKey = true;
+        } else if (keyCode == 87) {
+            // w按键
+            this.origin.y -= 10;
+        } else if (keyCode == 83) {
+            // s按键
+            this.origin.y += 10;
+        } else if (keyCode == 68) {
+            // d按键
+            this.origin.x += 10;
+        } else if (keyCode == 65) {
+            // a按键
+            this.origin.x -= 10;
+        } else {
+            super.onKeyDown(event);
+        }
+    } // Function onKeyDown()
+
+    /**
+     * 按键松开事件
+     *
+     * @param   event       事件参数
+     */
+    protected onKeyUp(event: KeyboardEvent): void {
+        this.spaceKey = false;
+        super.onKeyUp(event);
+    } // Function onKeyUp()
 
     /**
      * 鼠标按下事件
@@ -38,7 +78,7 @@ export class FloorView extends SGraphyView {
      */
     protected onMouseDown(event: MouseEvent): void {
         let se = new SMouseEvent(event);
-        if (se.ctrlKey) {
+        if (this.spaceKey) {
             if (se.buttons & SMouseButton.LeftButton) {
                 this._leftKeyPos.x = se.x;
                 this._leftKeyPos.y = se.y;
@@ -58,7 +98,7 @@ export class FloorView extends SGraphyView {
         if (this.moveable) {
             // 按左键移动
             let se = new SMouseEvent(event);
-            if (se.ctrlKey) {
+            if (this.spaceKey) {
                 if (se.buttons & SMouseButton.LeftButton) {
                     this.origin.x += se.x - this._leftKeyPos.x;
                     this.origin.y += se.y - this._leftKeyPos.y;

+ 7 - 18
src/items/HighlightItem.ts

@@ -20,6 +20,7 @@
 
 import { SGraphyItem } from "@saga-web/graphy/lib";
 import { SColor, SLine, SPainter, SPoint } from "@saga-web/draw/lib";
+import { Opt } from "../types/Opt";
 
 /**
  * 吸附时高亮对象
@@ -55,39 +56,27 @@ export class HighlightItem extends SGraphyItem {
     /**
      * 构造函数
      *
-     * @param parent    指向父对象
-     * @param data      对象
-     * @param distance  对象与鼠标位置的距离
+     * @param   parent  指向父对象
      */
-    constructor(
-        parent: SGraphyItem | null,
-        data: SPoint | SLine,
-        distance: number
-    ) {
+    constructor(parent: SGraphyItem | null) {
         super(parent);
-        if (data instanceof SPoint) {
-            this.point = data;
-        } else {
-            this.line = data;
-        }
-        this.distance = distance;
         this.visible = false;
-        this.zOrder = 19;
+        this.zOrder = 99;
     } // Constructor
 
     /**
      * Item绘制操作
      *
-     * @param   painter       painter对象
+     * @param   painter painter对象
      */
     onDraw(painter: SPainter): void {
         if (this.type == 2) {
-            painter.pen.color = new SColor("#409EFF");
+            painter.pen.color = Opt.hightLightLineColor;
             painter.pen.lineWidth = painter.toPx(6);
             painter.drawLine(this.line);
         }
         painter.pen.color = SColor.Transparent;
-        painter.brush.color = new SColor("#efff00");
+        painter.brush.color = Opt.hightLightPointColor;
         painter.drawCircle(this.point.x, this.point.y, painter.toPx(5));
     } // Function onDraw()
 } // Class HighlightItem

+ 4 - 0
src/types/Opt.ts

@@ -40,4 +40,8 @@ export class Opt {
     static windowColor = new SColor("#fcd6ff");
     /** 蒙版颜色    */
     static sceneMarkColor = new SColor("#00000080");
+    /** 高亮item吸附点颜色    */
+    static hightLightPointColor = new SColor("#efff00");
+    /** 高亮item吸附线颜色    */
+    static hightLightLineColor = new SColor("#409EFF");
 } // Interface Opt