|
@@ -1,6 +1,7 @@
|
1
|
1
|
import { BaseMarker } from '../BaseMarker';
|
2
|
2
|
import { ResizeGrip } from '../BaseMarker/ResizeGrip';
|
3
|
3
|
import { SvgHelper } from '../../renderer/SvgHelper';
|
|
4
|
+import { PositionType } from 'fc-whiteboard/src/event/Event';
|
4
|
5
|
|
5
|
6
|
export class LinearMarker extends BaseMarker {
|
6
|
7
|
public static createMarker = (): LinearMarker => {
|
|
@@ -17,8 +18,7 @@ export class LinearMarker extends BaseMarker {
|
17
|
18
|
|
18
|
19
|
private controlBox: SVGGElement;
|
19
|
20
|
|
20
|
|
- private controlGrip1: ResizeGrip;
|
21
|
|
- private controlGrip2: ResizeGrip;
|
|
21
|
+ private controlGrips: { left: ResizeGrip; right: ResizeGrip };
|
22
|
22
|
private activeGrip: ResizeGrip | null;
|
23
|
23
|
|
24
|
24
|
private x1: number = 0;
|
|
@@ -56,10 +56,10 @@ export class LinearMarker extends BaseMarker {
|
56
|
56
|
this.addControlBox();
|
57
|
57
|
}
|
58
|
58
|
|
59
|
|
- protected resize(x: number, y: number) {
|
|
59
|
+ protected resize(x: number, y: number, onPosition?: (pos: PositionType) => void) {
|
60
|
60
|
if (this.activeGrip) {
|
61
|
61
|
if (
|
62
|
|
- this.activeGrip === this.controlGrip1 &&
|
|
62
|
+ this.activeGrip === this.controlGrips.left &&
|
63
|
63
|
this.getLineLength(this.x1 + x, this.y1 + 1, this.x2, this.y2) >= this.MIN_LENGTH
|
64
|
64
|
) {
|
65
|
65
|
this.x1 += x;
|
|
@@ -68,8 +68,11 @@ export class LinearMarker extends BaseMarker {
|
68
|
68
|
this.markerBgLine.setAttribute('y1', this.y1.toString());
|
69
|
69
|
this.markerLine.setAttribute('x1', this.x1.toString());
|
70
|
70
|
this.markerLine.setAttribute('y1', this.y1.toString());
|
|
71
|
+ if (onPosition) {
|
|
72
|
+ onPosition('left');
|
|
73
|
+ }
|
71
|
74
|
} else if (
|
72
|
|
- this.activeGrip === this.controlGrip2 &&
|
|
75
|
+ this.activeGrip === this.controlGrips.right &&
|
73
|
76
|
this.getLineLength(this.x1, this.y1, this.x2 + x, this.y2 + y) >= this.MIN_LENGTH
|
74
|
77
|
) {
|
75
|
78
|
this.x2 += x;
|
|
@@ -78,12 +81,25 @@ export class LinearMarker extends BaseMarker {
|
78
|
81
|
this.markerBgLine.setAttribute('y2', this.y2.toString());
|
79
|
82
|
this.markerLine.setAttribute('x2', this.x2.toString());
|
80
|
83
|
this.markerLine.setAttribute('y2', this.y2.toString());
|
|
84
|
+ if (onPosition) {
|
|
85
|
+ onPosition('right');
|
|
86
|
+ }
|
81
|
87
|
}
|
82
|
88
|
}
|
83
|
89
|
|
84
|
90
|
this.adjustControlBox();
|
85
|
91
|
}
|
86
|
92
|
|
|
93
|
+ protected resizeByEvent(x: number, y: number, pos?: PositionType) {
|
|
94
|
+ if (pos === 'left') {
|
|
95
|
+ this.activeGrip = this.controlGrips.left;
|
|
96
|
+ } else {
|
|
97
|
+ this.activeGrip = this.controlGrips.right;
|
|
98
|
+ }
|
|
99
|
+
|
|
100
|
+ this.resize(x, y);
|
|
101
|
+ }
|
|
102
|
+
|
87
|
103
|
private getLineLength = (x1: number, y1: number, x2: number, y2: number): number => {
|
88
|
104
|
const dx = Math.abs(x1 - x2);
|
89
|
105
|
const dy = Math.abs(y1 - y2);
|
|
@@ -103,8 +119,10 @@ export class LinearMarker extends BaseMarker {
|
103
|
119
|
};
|
104
|
120
|
|
105
|
121
|
private addControlGrips = () => {
|
106
|
|
- this.controlGrip1 = this.createGrip();
|
107
|
|
- this.controlGrip2 = this.createGrip();
|
|
122
|
+ this.controlGrips = {
|
|
123
|
+ left: this.createGrip(),
|
|
124
|
+ right: this.createGrip()
|
|
125
|
+ };
|
108
|
126
|
|
109
|
127
|
this.positionGrips();
|
110
|
128
|
};
|
|
@@ -126,15 +144,15 @@ export class LinearMarker extends BaseMarker {
|
126
|
144
|
};
|
127
|
145
|
|
128
|
146
|
private positionGrips = () => {
|
129
|
|
- const gripSize = this.controlGrip1.GRIP_SIZE;
|
|
147
|
+ const gripSize = this.controlGrips.left.GRIP_SIZE;
|
130
|
148
|
|
131
|
149
|
const x1 = this.x1 - gripSize / 2;
|
132
|
150
|
const y1 = this.y1 - gripSize / 2;
|
133
|
151
|
const x2 = this.x2 - gripSize / 2;
|
134
|
152
|
const y2 = this.y2 - gripSize / 2;
|
135
|
153
|
|
136
|
|
- this.positionGrip(this.controlGrip1.visual, x1, y1);
|
137
|
|
- this.positionGrip(this.controlGrip2.visual, x2, y2);
|
|
154
|
+ this.positionGrip(this.controlGrips.left.visual, x1, y1);
|
|
155
|
+ this.positionGrip(this.controlGrips.right.visual, x2, y2);
|
138
|
156
|
};
|
139
|
157
|
|
140
|
158
|
private positionGrip = (grip: SVGGraphicsElement, x: number, y: number) => {
|
|
@@ -146,9 +164,9 @@ export class LinearMarker extends BaseMarker {
|
146
|
164
|
private gripMouseDown = (ev: MouseEvent) => {
|
147
|
165
|
this.isResizing = true;
|
148
|
166
|
this.activeGrip =
|
149
|
|
- (ev.target as SVGGraphicsElement) === this.controlGrip1.visual
|
150
|
|
- ? this.controlGrip1
|
151
|
|
- : this.controlGrip2;
|
|
167
|
+ (ev.target as SVGGraphicsElement) === this.controlGrips.left.visual
|
|
168
|
+ ? this.controlGrips.left
|
|
169
|
+ : this.controlGrips.right;
|
152
|
170
|
this.previousMouseX = ev.screenX;
|
153
|
171
|
this.previousMouseY = ev.screenY;
|
154
|
172
|
ev.stopPropagation();
|