@@ -17,8 +17,15 @@ export default {
1717 name: " Select" ,
1818 cursor: " pointer" ,
1919 movePath: false ,
20+ point: null ,
2021 segment: null ,
2122 scaleFactor: 15 ,
23+ edit: {
24+ indicatorWidth: 0 ,
25+ indicatorSize: 0 ,
26+ center: null ,
27+ canMove: false
28+ },
2229 hover: {
2330 showText: true ,
2431 text: null ,
@@ -36,7 +43,18 @@ export default {
3643 hitOptions: {
3744 segments: true ,
3845 stroke: true ,
39- tolerance: 2
46+ fill: false ,
47+ tolerance: 5 ,
48+ match : hit => {
49+ if (this .point == null ) return true ;
50+ if (
51+ hit .item instanceof paper .Path ||
52+ hit .item instanceof paper .CompoundPath
53+ ) {
54+ return ! hit .item .hasOwnProperty (" indicator" );
55+ }
56+ return true ;
57+ }
4058 }
4159 };
4260 },
@@ -94,14 +112,15 @@ export default {
94112 this .hover .text .justification = " left" ;
95113 this .hover .text .fillColor = " black" ;
96114 this .hover .text .content = content;
115+ this .hover .text .indicator = true ;
97116
98117 this .hover .text .fontSize = this .hover .fontSize ;
99118
100119 this .hover .box = new paper.Path.Rectangle (
101120 this .hover .text .bounds ,
102121 this .hover .rounded
103122 );
104-
123+ this . hover . box . indicator = true ;
105124 this .hover .box .fillColor = " white" ;
106125 this .hover .box .strokeColor = " white" ;
107126 this .hover .box .opacity = 0.5 ;
@@ -120,7 +139,7 @@ export default {
120139 onMouseDown (event ) {
121140 let hitResult = this .$parent .paper .project .hitTest (
122141 event .point ,
123- this .hitResult
142+ this .hitOptions
124143 );
125144
126145 if (! hitResult) return ;
@@ -132,21 +151,57 @@ export default {
132151 return ;
133152 }
134153
135- this . path = hitResult .item ;
154+ let path = hitResult .item ;
136155
137156 if (hitResult .type === " segment" ) {
138157 this .segment = hitResult .segment ;
139158 } else if (hitResult .type === " stroke" ) {
140159 let location = hitResult .location ;
141- this .segment = this .path .insert (location .index + 1 , event .point );
160+ this .segment = path .insert (location .index + 1 , event .point );
161+ }
162+
163+ if (this .point != null ) {
164+ this .edit .canMove = this .point .contains (event .point );
165+ }
166+ },
167+ createPoint (point ) {
168+ if (this .point != null ) {
169+ this .point .remove ();
142170 }
171+
172+ this .point = new paper.Path.Circle (point, this .edit .indicatorSize );
173+ this .point .strokeColor = " white" ;
174+ this .point .strokeWidth = this .edit .indicatorWidth ;
175+ this .point .indicator = true ;
143176 },
144177 onMouseDrag (event ) {
145178 if (this .segment ) {
179+ if (! this .edit .canMove ) return ;
180+ this .createPoint (event .point );
146181 this .segment .point = event .point ;
147182 }
148183 },
149184 onMouseMove (event ) {
185+ let hitResult = this .$parent .paper .project .hitTest (
186+ event .point ,
187+ this .hitOptions
188+ );
189+
190+ if (hitResult) {
191+ let point = null ;
192+
193+ if (hitResult .type === " segment" ) {
194+ point = hitResult .segment .location .point ;
195+ } else if (hitResult .type === " stroke" ) {
196+ point = hitResult .location .point ;
197+ }
198+
199+ if (point != null ) {
200+ this .edit .center = point;
201+ this .createPoint (point);
202+ }
203+ }
204+
150205 this .$parent .hover .annotation = - 1 ;
151206 this .$parent .hover .category = - 1 ;
152207
@@ -185,7 +240,7 @@ export default {
185240 }
186241 } else {
187242 this .hover .category = null ;
188- this .hover .annotation = - 1 ;
243+ this .hover .annotation = null ;
189244
190245 if (this .hover .text != null ) {
191246 this .hover .text .remove ();
@@ -197,20 +252,51 @@ export default {
197252 }
198253 },
199254 watch: {
200- scale (newScale ) {
201- this .hover .rounded = newScale * 5 ;
202- this .hover .textShift = newScale * 40 ;
203- this .hover .fontSize = newScale * this .scaleFactor ;
255+ scale: {
256+ handler (newScale ) {
257+ this .hover .rounded = newScale * 5 ;
258+ this .hover .textShift = newScale * 40 ;
259+ this .hover .fontSize = newScale * this .scaleFactor ;
260+ this .edit .distance = newScale * 40 ;
261+ this .edit .indicatorSize = newScale * 10 ;
262+ this .edit .indicatorWidth = newScale * 2 ;
204263
205- if (this .hover .text != null ) {
206- this .hover .text .fontSize = this .hover .fontSize ;
207- this .hover .shift =
208- (this .hover .text .bounds .bottomRight .x -
209- this .hover .text .bounds .bottomLeft .x ) /
210- 2 ;
211- let totalShift = this .hover .shift + this .hover .textShift ;
212- this .hover .text .position = this .hover .position .add (totalShift, 0 );
213- this .hover .box .bounds = this .hover .text .bounds ;
264+ if (this .edit .center ) {
265+ this .createPoint (this .edit .center );
266+ }
267+
268+ if (this .hover .text != null ) {
269+ this .hover .text .fontSize = this .hover .fontSize ;
270+ this .hover .shift =
271+ (this .hover .text .bounds .bottomRight .x -
272+ this .hover .text .bounds .bottomLeft .x ) /
273+ 2 ;
274+ let totalShift = this .hover .shift + this .hover .textShift ;
275+ this .hover .text .position = this .hover .position .add (totalShift, 0 );
276+ this .hover .box .bounds = this .hover .text .bounds ;
277+ }
278+ },
279+ immediate: true
280+ },
281+ isActive (active ) {
282+ if (active) {
283+ this .tool .activate ();
284+ } else {
285+ if (this .hover .text ) {
286+ this .hover .text .remove ();
287+ this .hover .box .remove ();
288+
289+ this .hover .box = null ;
290+ this .hover .text = null ;
291+ }
292+ if (this .point ) {
293+ this .point .remove ();
294+ this .point = null ;
295+ this .segment = null ;
296+ }
297+ if (this .hover .annotation ) {
298+ this .hover .annotation .compoundPath .selected = false ;
299+ }
214300 }
215301 }
216302 }
0 commit comments