|
@@ -77,18 +77,44 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
|
|
return (this.pageEl as (HTMLElement)).getBoundingClientRect();
|
|
return (this.pageEl as (HTMLElement)).getBoundingClientRect();
|
|
}
|
|
}
|
|
|
|
|
|
- getCurrCardBox() {
|
|
|
|
- return this.store.currStreamCard.$el.getBoundingClientRect();
|
|
|
|
|
|
+ _cardBox = {x:0,y:0,width: 0, height: 0, bottom: 0, top: 0, left: 0};
|
|
|
|
+
|
|
|
|
+ getCurrCardViewPortBox() {//屏幕空间坐标clientX 转中间viewport空间
|
|
|
|
+ const box = this.store.currStreamCard.$el.getBoundingClientRect();
|
|
|
|
+ const viewportbox = this.getViewPortBox();
|
|
|
|
+ const _cardBox = this._cardBox;
|
|
|
|
+ _cardBox.x = box.x - viewportbox.x;
|
|
|
|
+ _cardBox.y = box.y - viewportbox.y;
|
|
|
|
+ _cardBox.width = box.width;
|
|
|
|
+ _cardBox.height = box.height;
|
|
|
|
+ _cardBox.left = box.left - viewportbox.left;
|
|
|
|
+ _cardBox.top = box.top - viewportbox.top;
|
|
|
|
+
|
|
|
|
+ return _cardBox;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ _tempPos = {x: 0, y:0}
|
|
|
|
+ viewportPos2DesignPos(clientX: number, clientY:number) {
|
|
|
|
+ const box = this.store.currStreamCard.$el.getBoundingClientRect();
|
|
|
|
+ let scale = this.controls.editorCtrl.state.scale;
|
|
|
|
+ this._tempPos.x = (clientX - box.left) / scale;
|
|
|
|
+ this._tempPos.y = (clientY - box.top) / scale;
|
|
|
|
+ return this._tempPos;
|
|
|
|
+ }
|
|
|
|
+
|
|
getViewPortBox() {
|
|
getViewPortBox() {
|
|
//@ts-ignore
|
|
//@ts-ignore
|
|
- return this.viewport.getBoundingClientRect();
|
|
|
|
|
|
+ const box = this.viewport.getBoundingClientRect();
|
|
|
|
+ return box;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
|
|
getCurrCard() {
|
|
getCurrCard() {
|
|
return this.store.currStreamCard;
|
|
return this.store.currStreamCard;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ getCurrCardBox() {
|
|
|
|
+ return this.store.currStreamCard.$el.getBoundingClientRect();
|
|
|
|
+ }
|
|
getProjectId() {
|
|
getProjectId() {
|
|
return this.store.designData._id;
|
|
return this.store.designData._id;
|
|
}
|
|
}
|
|
@@ -119,8 +145,8 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
|
|
|
|
|
|
this._selCtx = selCanvas.getContext("2d") as CanvasRenderingContext2D;
|
|
this._selCtx = selCanvas.getContext("2d") as CanvasRenderingContext2D;
|
|
|
|
|
|
- this._selCanvaseSize.w = selCanvas.width * 2;
|
|
|
|
- this._selCanvaseSize.h = selCanvas.height * 2;
|
|
|
|
|
|
+ this._selCanvaseSize.w = selCanvas.width;
|
|
|
|
+ this._selCanvaseSize.h = selCanvas.height;
|
|
|
|
|
|
this.assistCtrl = new AssistCtrl(this);
|
|
this.assistCtrl = new AssistCtrl(this);
|
|
this.assistRuler = new AssistRulerCtrl(this);
|
|
this.assistRuler = new AssistRulerCtrl(this);
|
|
@@ -171,9 +197,7 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
|
|
_downClickedCompId = "";
|
|
_downClickedCompId = "";
|
|
onDocMouseDown(e: MouseEvent) {
|
|
onDocMouseDown(e: MouseEvent) {
|
|
this._mouseDownTimestamp = Date.now();
|
|
this._mouseDownTimestamp = Date.now();
|
|
- if (!this.pageEl || !this.selCanvas) return;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ if (e.button != 0 || !this.pageEl || !this.selCanvas || this.controls.editorCtrl.isMoving() ) return;
|
|
|
|
|
|
document.addEventListener("mousemove", this.onDocMouseMove, {
|
|
document.addEventListener("mousemove", this.onDocMouseMove, {
|
|
capture: true,
|
|
capture: true,
|
|
@@ -194,12 +218,13 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
|
|
this._state = draging ? MODE_RULER_DRAG : MODE_NONE;
|
|
this._state = draging ? MODE_RULER_DRAG : MODE_NONE;
|
|
|
|
|
|
const sel = this.selCanvas.getBoundingClientRect();
|
|
const sel = this.selCanvas.getBoundingClientRect();
|
|
- const selX = e.clientX - sel.left;
|
|
|
|
- const sely = e.clientY - sel.top;
|
|
|
|
- this._selDownX = selX;
|
|
|
|
- this._selDownY = sely;
|
|
|
|
this._selBox = sel;
|
|
this._selBox = sel;
|
|
|
|
|
|
|
|
+ const pos = this.getViewportPos(e);
|
|
|
|
+
|
|
|
|
+ this._selDownX = pos.x;
|
|
|
|
+ this._selDownY = pos.y;
|
|
|
|
+
|
|
this._downClientX = e.clientX;
|
|
this._downClientX = e.clientX;
|
|
this._downClientY = e.clientY;
|
|
this._downClientY = e.clientY;
|
|
|
|
|
|
@@ -213,30 +238,28 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
|
|
//选框点击判断
|
|
//选框点击判断
|
|
let isClickSelRect = false;
|
|
let isClickSelRect = false;
|
|
if (this.selected.length > 0) {
|
|
if (this.selected.length > 0) {
|
|
- const card = this.store.currStreamCard.$el;
|
|
|
|
- box = card.getBoundingClientRect();
|
|
|
|
- const cardX = pageX;
|
|
|
|
- const cardY = e.clientY - box.top;
|
|
|
|
- isClickSelRect = this.objContainer?.testClick(cardX, cardY) as boolean;
|
|
|
|
|
|
+ const pos = this.viewportPos2DesignPos(e.clientX, e.clientY);
|
|
|
|
+ isClickSelRect = this.objContainer?.testClick(pos.x, pos.y) as boolean;
|
|
if (isClickSelRect) {
|
|
if (isClickSelRect) {
|
|
this._state = MODE_MOVING;
|
|
this._state = MODE_MOVING;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (!isClickSelRect) {
|
|
if (!isClickSelRect) {
|
|
//点击在选框之外
|
|
//点击在选框之外
|
|
-
|
|
|
|
- if (!this._downClickedCompId) {
|
|
|
|
- //没有点击到组件
|
|
|
|
- const view = this.viewport?.getBoundingClientRect() as any;
|
|
|
|
- const isOut =
|
|
|
|
- e.clientX < view.left ||
|
|
|
|
- e.clientX > view.right ||
|
|
|
|
- e.clientY < view.top ||
|
|
|
|
- e.clientY > view.bottom;
|
|
|
|
- if (!isOut) {
|
|
|
|
- this._state = MODE_SEL_RECT;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ this._state = MODE_SEL_RECT;
|
|
|
|
+
|
|
|
|
+ // if (!this._downClickedCompId) {
|
|
|
|
+ // //没有点击到组件
|
|
|
|
+ // const view = this.viewport?.getBoundingClientRect() as any;
|
|
|
|
+ // const isOut =
|
|
|
|
+ // e.clientX < view.left ||
|
|
|
|
+ // e.clientX > view.right ||
|
|
|
|
+ // e.clientY < view.top ||
|
|
|
|
+ // e.clientY > view.bottom;
|
|
|
|
+ // if (!isOut) {
|
|
|
|
+ // this._state = MODE_SEL_RECT;
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
//else {//点击到选框之外的组件, 把时间放到mouseup 时相应.
|
|
//else {//点击到选框之外的组件, 把时间放到mouseup 时相应.
|
|
// this._state = MODE_MOVING;
|
|
// this._state = MODE_MOVING;
|
|
// const obj = this.compMap[comps[0].id];
|
|
// const obj = this.compMap[comps[0].id];
|
|
@@ -399,6 +422,7 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
|
|
this.helper.extendStreamCard(this.store.currStreamCardId);
|
|
this.helper.extendStreamCard(this.store.currStreamCardId);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
movingMousemove(e: MouseEvent) {
|
|
movingMousemove(e: MouseEvent) {
|
|
const objContainer = this.objContainer as ObjsContainer;
|
|
const objContainer = this.objContainer as ObjsContainer;
|
|
const magnet = this.assistMagnet as AssistMagnetCtrl;
|
|
const magnet = this.assistMagnet as AssistMagnetCtrl;
|
|
@@ -408,11 +432,12 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
|
|
this._initMovePos = { x: obj.parent.x, y: obj.parent.y };
|
|
this._initMovePos = { x: obj.parent.x, y: obj.parent.y };
|
|
}
|
|
}
|
|
magnet.test(e);
|
|
magnet.test(e);
|
|
|
|
+ const s = this.controls.editorCtrl.state.scale;
|
|
|
|
|
|
objContainer.setPivot(0);
|
|
objContainer.setPivot(0);
|
|
objContainer.translate(
|
|
objContainer.translate(
|
|
- magnet.clientX - this._movePreClientX,
|
|
|
|
- magnet.clientY - this._movePreClientY
|
|
|
|
|
|
+ (magnet.clientX - this._movePreClientX) / s,
|
|
|
|
+ (magnet.clientY - this._movePreClientY ) / s
|
|
);
|
|
);
|
|
|
|
|
|
this.upgateGizmoStyle();
|
|
this.upgateGizmoStyle();
|
|
@@ -491,11 +516,13 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
|
|
//选择空间转 streamCard空间
|
|
//选择空间转 streamCard空间
|
|
const card = this.store.currStreamCard;
|
|
const card = this.store.currStreamCard;
|
|
const box = card.$el.getBoundingClientRect();
|
|
const box = card.$el.getBoundingClientRect();
|
|
|
|
+ const s = this.controls.editorCtrl.state.scale;
|
|
|
|
+
|
|
this.rectSelect(
|
|
this.rectSelect(
|
|
- this._lastSelRect[0] - box.left,
|
|
|
|
- this._lastSelRect[1] - box.top,
|
|
|
|
- this._lastSelRect[2],
|
|
|
|
- this._lastSelRect[3],
|
|
|
|
|
|
+ (this._lastSelRect[0] - box.left)/s,
|
|
|
|
+ (this._lastSelRect[1] - box.top) / s,
|
|
|
|
+ this._lastSelRect[2] / s,
|
|
|
|
+ this._lastSelRect[3] / s,
|
|
e
|
|
e
|
|
);
|
|
);
|
|
}
|
|
}
|
|
@@ -688,6 +715,12 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
|
|
|
|
|
|
_lastSelRect = [0, 0, 0, 0];
|
|
_lastSelRect = [0, 0, 0, 0];
|
|
|
|
|
|
|
|
+ getViewportPos(e:MouseEvent) {
|
|
|
|
+ this._tempPos.x = (e.clientX - this._selBox.left); /// this.controls.editorCtrl.state.scale;
|
|
|
|
+ this._tempPos.y = (e.clientY - this._selBox.top ); /// this.controls.editorCtrl.state.scale;
|
|
|
|
+ return this._tempPos;
|
|
|
|
+ }
|
|
|
|
+
|
|
drawSelRect(e: MouseEvent) {
|
|
drawSelRect(e: MouseEvent) {
|
|
this.assistRuler?.draw();
|
|
this.assistRuler?.draw();
|
|
|
|
|
|
@@ -695,8 +728,14 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
|
|
|
|
|
|
const dx = this._selDownX;
|
|
const dx = this._selDownX;
|
|
const dy = this._selDownY;
|
|
const dy = this._selDownY;
|
|
- const currX = e.clientX - this._selBox.left;
|
|
|
|
- const currY = e.clientY - this._selBox.top;
|
|
|
|
|
|
+
|
|
|
|
+ const pos = this.getViewportPos(e);
|
|
|
|
+
|
|
|
|
+ const currX = pos.x;
|
|
|
|
+ const currY = pos.y;
|
|
|
|
+
|
|
|
|
+ console.log("xxxxxxxx=>", currX, currY);
|
|
|
|
+
|
|
const x = Math.min(currX, dx),
|
|
const x = Math.min(currX, dx),
|
|
y = Math.min(dy, currY);
|
|
y = Math.min(dy, currY);
|
|
|
|
|
|
@@ -745,6 +784,16 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
|
|
//const m = Matrix.createFromComp(comp.layout.transform)
|
|
//const m = Matrix.createFromComp(comp.layout.transform)
|
|
}
|
|
}
|
|
objContainer?: ObjsContainer;
|
|
objContainer?: ObjsContainer;
|
|
|
|
+ getSelectBound() {
|
|
|
|
+ const Objc = this.objContainer as ObjsContainer;
|
|
|
|
+ const w = Objc.getBound();
|
|
|
|
+ const s = this.controls.editorCtrl.state.scale;
|
|
|
|
+ w.x = w.x * s;
|
|
|
|
+ w.y = w.y * s;
|
|
|
|
+ w.width = w.width *s;
|
|
|
|
+ w.height = w.height *s;
|
|
|
|
+ return w;
|
|
|
|
+ }
|
|
|
|
|
|
selecteObjs(objs: any[], ContainerBox?: ObjsContainer) {
|
|
selecteObjs(objs: any[], ContainerBox?: ObjsContainer) {
|
|
if (this.selected.length == 0 && objs.length == 0) return;
|
|
if (this.selected.length == 0 && objs.length == 0) return;
|
|
@@ -800,11 +849,10 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
|
|
lastRad = 0;
|
|
lastRad = 0;
|
|
|
|
|
|
rotateMousemove(e: MouseEvent) {
|
|
rotateMousemove(e: MouseEvent) {
|
|
- const card = this.store.currStreamCard;
|
|
|
|
-
|
|
|
|
- const rect = card.$el.getBoundingClientRect();
|
|
|
|
- let StartX = e.clientX - rect.left;
|
|
|
|
- let StartY = e.clientY - rect.top;
|
|
|
|
|
|
+
|
|
|
|
+ const pos = this.viewportPos2DesignPos(e.clientX, e.clientY)
|
|
|
|
+ let StartX = pos.x;
|
|
|
|
+ let StartY = pos.y;
|
|
|
|
|
|
const objContainer = this.objContainer as ObjsContainer;
|
|
const objContainer = this.objContainer as ObjsContainer;
|
|
|
|
|
|
@@ -924,13 +972,15 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
|
|
];
|
|
];
|
|
let dirOrth = ["scaleright", "scaleleft", "scalebottom", "scaletop"];
|
|
let dirOrth = ["scaleright", "scaleleft", "scalebottom", "scaletop"];
|
|
|
|
|
|
- const rect = this.store.currStreamCard.$el.getBoundingClientRect();
|
|
|
|
-
|
|
|
|
|
|
+
|
|
const maget = this.assistMagnet as AssistMagnetCtrl;
|
|
const maget = this.assistMagnet as AssistMagnetCtrl;
|
|
maget.test(event);
|
|
maget.test(event);
|
|
|
|
|
|
- let StartX = maget.clientX - rect.left;
|
|
|
|
- let StartY = maget.clientY - rect.top;
|
|
|
|
|
|
+ const pos = this.viewportPos2DesignPos(maget.clientX, maget.clientY)
|
|
|
|
+
|
|
|
|
+ let StartX = pos.x;
|
|
|
|
+ let StartY = pos.y;
|
|
|
|
+
|
|
const objContainer = this.objContainer as ObjsContainer;
|
|
const objContainer = this.objContainer as ObjsContainer;
|
|
|
|
|
|
//获取当前屏幕坐标和选框中心点坐标,计算旋转值
|
|
//获取当前屏幕坐标和选框中心点坐标,计算旋转值
|