123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- /*
- * ********************************************************************************************************************
- *
- * :*$@@%$*: ;: ;; ;;
- * :@@%! :!@@%: %! ;%%@@%$ =@@@@@@@%; @%@@@%%%%@@@@@
- * :@%; :$= %%$$$%$$ ;$$ ;$@= !@$
- * =@! %! @ $=;% !@@@%: !$$$$$$$$$$$$$$=
- * =@* %! @ $= % %@= =%@! %=
- * *$%%! @@= ;=$%%%$*: %! @ $= % =%%%%%%@$ *%: =%
- * %@@!: !@@@%=$@@@@%! :*@@$: %! @ $= % $* ;@ @* :%*
- * ;@@! ;!!!;: ;@%: =======@%========* @ $$ % $%*****$@ :@$=*********=@$
- * $@* ;@@@%=!: *@*
- * =@$ ;;;!=%@@@@=! =@!
- * %@$: =@%: :*@@@* %@= Copyright (c) 2016-2019. 北京上格云技术有限公司
- * ;%@@$=$@@%* *@@@$=%@@%;
- * ::;:: ::;:: All rights reserved.
- *
- * ********************************************************************************************************************
- */
- import { SGraphyView } from "@saga-web/graphy/lib";
- import {
- SMouseButton,
- SMouseEvent,
- SNetUtil,
- STouchState
- } from "@saga-web/base/lib";
- import { SPoint } from "@saga-web/draw/lib";
- /**
- * 楼层场景
- *
- * @author 郝建龙
- */
- export class FloorView extends SGraphyView {
- /** 鼠标左键键按下时位置 */
- private _leftKeyPos = new SPoint();
- /** 空格是否被按下 */
- private spaceKey: boolean = false;
- /**
- * 保存底图json
- *
- * @param name 文件名
- */
- saveFloorJson(name: string): void {
- // @ts-ignore
- if (!this.scene || !this.scene.json) return;
- // @ts-ignore
- let url = URL.createObjectURL(new Blob([this.scene.json]));
- SNetUtil.downLoad(name, url);
- } // Function saveSceneSvg()
- /**
- * 按键按下事件
- *
- * @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()
- /**
- * 鼠标按下事件
- *
- * @param event 事件参数
- */
- protected onMouseDown(event: MouseEvent): void {
- let se = new SMouseEvent(event);
- if (se.buttons & SMouseButton.LeftButton) {
- this._leftKeyPos.x = se.x;
- this._leftKeyPos.y = se.y;
- }
- super.onMouseDown(event);
- } // Function onMouseDown()
- /**
- * 鼠标移动事件
- *
- * @param event 事件参数
- */
- protected onMouseMove(event: MouseEvent): void {
- // 按左键移动
- let se = new SMouseEvent(event);
- if (se.buttons & SMouseButton.LeftButton) {
- if (this.spaceKey) {
- this.origin.x += se.x - this._leftKeyPos.x;
- this.origin.y += se.y - this._leftKeyPos.y;
- }
- this._leftKeyPos.x = se.x;
- this._leftKeyPos.y = se.y;
- }
- super.onMouseMove(event);
- } // Function onMouseMove()
- } // Class FloorScene
|