|
@@ -9,6 +9,7 @@ import { Project, VectorLenth } from "./objects/mathUtils";
|
|
|
import { Point } from "./objects/point";
|
|
|
import { indexOf } from "lodash";
|
|
|
import { AssistCtrl } from "./assistCtrl";
|
|
|
+import { AssistRulerCtrl } from "./assistRulerCtrl";
|
|
|
|
|
|
/**
|
|
|
* 页面画布空间进行选择
|
|
@@ -18,6 +19,8 @@ const MODE_MOVING = 2;
|
|
|
const MODE_ROTATE = 3;
|
|
|
const MODE_SCALE_WIDTH = 4;
|
|
|
const MODE_SCALE_SCALE = 5;
|
|
|
+const MODE_RULER_LINE = 6;
|
|
|
+
|
|
|
const MODE_NONE = 0;
|
|
|
|
|
|
export class SelectCtrl extends ModuleControl<EditorModule> {
|
|
@@ -63,10 +66,18 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
|
|
|
bus = new Event();
|
|
|
viewport?: HTMLElement;
|
|
|
|
|
|
- assistCtrl?:AssistCtrl;
|
|
|
+ assistCtrl?: AssistCtrl;
|
|
|
+ assistRuler?: AssistRulerCtrl;
|
|
|
|
|
|
getCurrCardBox() {
|
|
|
return this.store.currStreamCard.$el.getBoundingClientRect();
|
|
|
+ }
|
|
|
+
|
|
|
+ getCurrCard() {
|
|
|
+ return this.store.currStreamCard;
|
|
|
+ }
|
|
|
+ getProjectId() {
|
|
|
+ return this.store.designData._id;
|
|
|
}
|
|
|
|
|
|
initEvents(
|
|
@@ -86,44 +97,48 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
|
|
|
this._selCanvaseSize.w = selCanvas.width * 2;
|
|
|
this._selCanvaseSize.h = selCanvas.height * 2;
|
|
|
|
|
|
- viewport.addEventListener("mousedown", this.onDocMouseDown.bind(this), {
|
|
|
- capture: true,
|
|
|
- });
|
|
|
+ this.assistCtrl = new AssistCtrl(this);
|
|
|
+ this.assistRuler = new AssistRulerCtrl(this);
|
|
|
+
|
|
|
+ viewport.addEventListener("mousedown", this.onDocMouseDown.bind(this));
|
|
|
window.addEventListener("resize", this.onResize.bind(this));
|
|
|
|
|
|
this.initEffects();
|
|
|
-
|
|
|
- this.assistCtrl = new AssistCtrl(this);
|
|
|
}
|
|
|
|
|
|
initEffects() {
|
|
|
- //相应相应的事件
|
|
|
- Effect.array(()=>this.store.selected).list({
|
|
|
- remove:()=>{
|
|
|
- console.log("xxx")
|
|
|
+ //相应相应的事件
|
|
|
+ Effect.array(() => this.store.selected)
|
|
|
+ .list({
|
|
|
+ remove: () => {
|
|
|
+ console.log("xxx");
|
|
|
},
|
|
|
- change:(added:string[], removed:string[])=>{
|
|
|
- console.log("changeMap=>", added, removed)
|
|
|
- this._updateSelects();
|
|
|
- },
|
|
|
- }).run();
|
|
|
+ change: (added: string[], removed: string[]) => {
|
|
|
+ console.log("changeMap=>", added, removed);
|
|
|
+ this._updateSelects();
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .run();
|
|
|
}
|
|
|
|
|
|
_mouseDownFlag = "";
|
|
|
_mouseDownTimestamp = 0;
|
|
|
|
|
|
- _containers:Map<string, ObjsContainer> = new Map();
|
|
|
+ _containers: Map<string, ObjsContainer> = new Map();
|
|
|
|
|
|
_updateSelects() {
|
|
|
const selecteds = this.store.selected;
|
|
|
- const ObjC = this._containers.get(this.store.selectId)
|
|
|
+ const ObjC = this._containers.get(this.store.selectId);
|
|
|
let objs = [];
|
|
|
for (let item of selecteds) {
|
|
|
- objs.push( new CompObject(this.compMap[item]) )
|
|
|
+ objs.push(new CompObject(this.compMap[item]));
|
|
|
}
|
|
|
this.selecteObjs(objs, ObjC);
|
|
|
if (this.store.selectId) {
|
|
|
- this._containers.set(this.store.selectId, this.objContainer as ObjsContainer);
|
|
|
+ this._containers.set(
|
|
|
+ this.store.selectId,
|
|
|
+ this.objContainer as ObjsContainer
|
|
|
+ );
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -175,9 +190,11 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
|
|
|
this._state = MODE_MOVING;
|
|
|
}
|
|
|
}
|
|
|
- if (!isClickSelRect) { //点击在选框之外
|
|
|
-
|
|
|
- if (!this._downClickedCompId) {//没有点击到组件
|
|
|
+ if (!isClickSelRect) {
|
|
|
+ //点击在选框之外
|
|
|
+
|
|
|
+ if (!this._downClickedCompId) {
|
|
|
+ //没有点击到组件
|
|
|
const view = this.viewport?.getBoundingClientRect() as any;
|
|
|
const isOut =
|
|
|
e.clientX < view.left ||
|
|
@@ -200,32 +217,41 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
|
|
|
this._state = MODE_MOVING;
|
|
|
} else if (this._mouseDownFlag.indexOf("scale") > -1) {
|
|
|
this._state = MODE_SCALE_WIDTH;
|
|
|
- if (this.store.selected.length == 1 && this.store.currComp.compKey == "Text") {//拖拽的是文本
|
|
|
- const scaleFlags = ["scaleBottomright", "scaleBottomleft", "scaleTopleft", "scaleTopright"]
|
|
|
- if (scaleFlags.indexOf(this._mouseDownFlag) > -1 ) {
|
|
|
- this._state = MODE_SCALE_SCALE;
|
|
|
- }
|
|
|
+ if (
|
|
|
+ this.store.selected.length == 1 &&
|
|
|
+ this.store.currComp.compKey == "Text"
|
|
|
+ ) {
|
|
|
+ //拖拽的是文本
|
|
|
+ const scaleFlags = [
|
|
|
+ "scaleBottomright",
|
|
|
+ "scaleBottomleft",
|
|
|
+ "scaleTopleft",
|
|
|
+ "scaleTopright",
|
|
|
+ ];
|
|
|
+ if (scaleFlags.indexOf(this._mouseDownFlag) > -1) {
|
|
|
+ this._state = MODE_SCALE_SCALE;
|
|
|
+ }
|
|
|
}
|
|
|
+ } else if (this._mouseDownFlag.indexOf("ruler") > -1) {
|
|
|
+ this._state = MODE_RULER_LINE;
|
|
|
}
|
|
|
-
|
|
|
this._movePreClientX = this._downClientX;
|
|
|
this._movePreClientY = this._downClientY;
|
|
|
this._initMovePos.x = -1;
|
|
|
this._initMovePos.y = -1;
|
|
|
-
|
|
|
}
|
|
|
_initMovePos = { x: -1, y: -1 };
|
|
|
|
|
|
- getDivFlag(div: HTMLElement, flag="editable") {
|
|
|
+ getDivFlag(div: HTMLElement, flag = "editable") {
|
|
|
let c: any = div;
|
|
|
- if (!c) return ""
|
|
|
+ if (!c) return "";
|
|
|
let i = 0;
|
|
|
do {
|
|
|
if (c[flag]) return c[flag];
|
|
|
c = c.parentElement;
|
|
|
i += 1;
|
|
|
if (i > 16) {
|
|
|
- return ""
|
|
|
+ return "";
|
|
|
}
|
|
|
} while (c);
|
|
|
return "";
|
|
@@ -244,12 +270,20 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
|
|
|
}
|
|
|
} while (c);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
getDivTransformFlag(div: HTMLElement) {
|
|
|
- const id = this.getDivId(div);
|
|
|
- if (!id) return "";
|
|
|
- if ( id.indexOf("rotate")>-1 || id.indexOf("move") > -1 || id.indexOf("scale") > -1 || id.indexOf("toolbar") > -1) return id;
|
|
|
- return "";
|
|
|
+ const id = this.getDivId(div);
|
|
|
+ if (!id) return "";
|
|
|
+ if (
|
|
|
+ id.indexOf("rotate") > -1 ||
|
|
|
+ id.indexOf("move") > -1 ||
|
|
|
+ id.indexOf("scale") > -1 ||
|
|
|
+ id.indexOf("toolbar") > -1 ||
|
|
|
+ id.indexOf("ruler") > -1
|
|
|
+ )
|
|
|
+ return id;
|
|
|
+
|
|
|
+ return "";
|
|
|
}
|
|
|
|
|
|
compClickTest2(e: MouseEvent) {
|
|
@@ -336,8 +370,8 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
|
|
|
const objContainer = this.objContainer as ObjsContainer;
|
|
|
|
|
|
if (this._initMovePos.x == -1 && this._initMovePos.y == -1) {
|
|
|
- const obj = this.objContainer as ObjsContainer;
|
|
|
- this._initMovePos = { x: obj.parent.x, y: obj.parent.y };
|
|
|
+ const obj = this.objContainer as ObjsContainer;
|
|
|
+ this._initMovePos = { x: obj.parent.x, y: obj.parent.y };
|
|
|
}
|
|
|
objContainer.setPivot(0);
|
|
|
objContainer.translate(
|
|
@@ -353,10 +387,7 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
|
|
|
|
|
|
onDocMouseMove = (e: MouseEvent) => {
|
|
|
if (!this.pageEl) return;
|
|
|
- // if (!this._downed) {
|
|
|
- // this.checkHover();
|
|
|
- // return;
|
|
|
- // }
|
|
|
+
|
|
|
if (this._state) {
|
|
|
e.preventDefault();
|
|
|
e.stopPropagation();
|
|
@@ -375,6 +406,9 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
|
|
|
case MODE_SCALE_WIDTH:
|
|
|
case MODE_SCALE_SCALE:
|
|
|
this.scaleMousemove(e);
|
|
|
+ break
|
|
|
+ case MODE_RULER_LINE:
|
|
|
+ this.assistRuler?.rulerLineMouseMove(e);
|
|
|
}
|
|
|
|
|
|
this._movePreClientY = e.clientY;
|
|
@@ -400,7 +434,7 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
|
|
|
if (this._mouseDownFlag == "toolbar") {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (isClick) {
|
|
|
this._state = MODE_NONE;
|
|
|
this.actions.pickComp(this._downClickedCompId);
|
|
@@ -420,25 +454,27 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
|
|
|
|
|
|
if (this._state == MODE_ROTATE) {
|
|
|
this.rotateMouseUp(e);
|
|
|
- } else if (this._state == MODE_SCALE_WIDTH || this._state == MODE_SCALE_SCALE) {
|
|
|
+ } else if (
|
|
|
+ this._state == MODE_SCALE_WIDTH ||
|
|
|
+ this._state == MODE_SCALE_SCALE
|
|
|
+ ) {
|
|
|
this.scaleMouseUp(e);
|
|
|
} else if (this._state == MODE_MOVING) {
|
|
|
this.moveMouseUp(e, isClick);
|
|
|
+ } else if (this._state == MODE_RULER_LINE) {
|
|
|
+ this.assistRuler?.rulerLineMouseUp(e, isClick)
|
|
|
}
|
|
|
|
|
|
this._state = MODE_NONE;
|
|
|
this._downed = false;
|
|
|
this._moveSelectUpdated = false;
|
|
|
- this._selCtx?.clearRect(
|
|
|
- 0,
|
|
|
- 0,
|
|
|
- this._selCanvaseSize.w,
|
|
|
- this._selCanvaseSize.h
|
|
|
- );
|
|
|
+
|
|
|
this.upgateGizmoStyle();
|
|
|
this.helper.extendStreamCard(this.store.currStreamCardId);
|
|
|
+ this.assistRuler?.draw();
|
|
|
}
|
|
|
- moveMouseUp(e: MouseEvent, clicked:boolean) {
|
|
|
+
|
|
|
+ moveMouseUp(e: MouseEvent, clicked: boolean) {
|
|
|
const history = this.controls.historyCtrl.history;
|
|
|
|
|
|
const obj = this.objContainer as ObjsContainer;
|
|
@@ -448,13 +484,12 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
|
|
|
const initX = this._initMovePos.x,
|
|
|
initY = this._initMovePos.y;
|
|
|
|
|
|
- this._initMovePos.x = -1;
|
|
|
- this._initMovePos.y = -1;
|
|
|
-
|
|
|
- if (initX == -1 && initY == -1) return;
|
|
|
+ this._initMovePos.x = -1;
|
|
|
+ this._initMovePos.y = -1;
|
|
|
|
|
|
+ if (initX == -1 && initY == -1) return;
|
|
|
|
|
|
- obj.setPivot(0);
|
|
|
+ obj.setPivot(0);
|
|
|
|
|
|
history.record({
|
|
|
undo: () => {
|
|
@@ -465,12 +500,11 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
|
|
|
currObj.parent.y = initY;
|
|
|
currObj.parent.updateTransform();
|
|
|
currObj.updateCompState();
|
|
|
-
|
|
|
+
|
|
|
this.upgateGizmoStyle();
|
|
|
this.helper.extendStreamCard(this.store.currStreamCardId);
|
|
|
},
|
|
|
redo: () => {
|
|
|
-
|
|
|
const currObj = this.objContainer as ObjsContainer;
|
|
|
currObj.setPivot(0);
|
|
|
currObj.parent.x = lastX;
|
|
@@ -501,7 +535,7 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
|
|
|
this.actions.pickComp(this.store.currStreamCardId);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
upgateGizmoStyle() {
|
|
|
this.transferStyle.mode = this._state;
|
|
|
this.assistCtrl?.flashDrawCardDists();
|
|
@@ -553,6 +587,8 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
|
|
|
_lastSelRect = [0, 0, 0, 0];
|
|
|
|
|
|
drawSelRect(e: MouseEvent) {
|
|
|
+ this.assistRuler?.draw();
|
|
|
+
|
|
|
const ctx = this._selCtx;
|
|
|
|
|
|
const dx = this._selDownX;
|
|
@@ -561,7 +597,6 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
|
|
|
const currY = e.clientY - this._selBox.top;
|
|
|
const x = Math.min(currX, dx),
|
|
|
y = Math.min(dy, currY);
|
|
|
- ctx.clearRect(0, 0, this._selCanvaseSize.w, this._selCanvaseSize.h);
|
|
|
|
|
|
ctx.fillStyle = "rgba(232, 139, 0, 0.16)";
|
|
|
const w = Math.abs(currX - dx);
|
|
@@ -578,6 +613,8 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
|
|
|
this._lastSelRect[3] = h;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
checkHover() {
|
|
|
this.selCanvas;
|
|
|
}
|
|
@@ -733,12 +770,11 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
|
|
|
|
|
|
const history = this.controls.historyCtrl.history;
|
|
|
this.objContainer?.setPivot(0);
|
|
|
-
|
|
|
+
|
|
|
history.record({
|
|
|
undo: () => {
|
|
|
-
|
|
|
const objContainer = this.objContainer as ObjsContainer;
|
|
|
-
|
|
|
+
|
|
|
this.objContainer?.setPivot(4);
|
|
|
this.objContainer?.rotate(initrad);
|
|
|
this.objContainer?.setPivot(0);
|
|
@@ -881,7 +917,7 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
|
|
|
history.record({
|
|
|
undo: () => {
|
|
|
console.log("undo ");
|
|
|
-
|
|
|
+
|
|
|
this.objContainer?.setPivot(scaleIndex);
|
|
|
if (scaleMode == MODE_SCALE_WIDTH) {
|
|
|
this.objContainer?.scaleSize(preScale.x, preScale.y);
|