@@ -12,13 +12,8 @@ export default function widgetBehavior(publicAPI, model) {
12
12
// --------------------------------------------------------------------------
13
13
14
14
const updateHandlesSize = ( ) => {
15
- if ( model . handleSizeInPixels != null ) {
16
- const scale =
17
- model . handleSizeInPixels *
18
- vec3 . distance (
19
- model . apiSpecificRenderWindow . displayToWorld ( 0 , 0 , 0 , model . renderer ) ,
20
- model . apiSpecificRenderWindow . displayToWorld ( 1 , 0 , 0 , model . renderer )
21
- ) ;
15
+ if ( publicAPI . getHandleSizeInPixels ( ) != null ) {
16
+ const scale = publicAPI . getHandleSizeInPixels ( ) ;
22
17
23
18
model . moveHandle . setScale1 ( scale ) ;
24
19
model . widgetState . getHandleList ( ) . forEach ( ( handle ) => {
@@ -39,7 +34,7 @@ export default function widgetBehavior(publicAPI, model) {
39
34
model . moveHandle . getOrigin ( ) ,
40
35
model . lastHandle . getOrigin ( )
41
36
) >
42
- model . freehandMinDistance * model . freehandMinDistance
37
+ publicAPI . getFreehandMinDistance ( ) * publicAPI . getFreehandMinDistance ( )
43
38
) {
44
39
model . lastHandle = model . widgetState . addHandle ( ) ;
45
40
model . lastHandle . setVisible ( false ) ;
@@ -60,6 +55,13 @@ export default function widgetBehavior(publicAPI, model) {
60
55
const getHoveredHandle = ( ) => {
61
56
const handles = model . widgetState . getHandleList ( ) ;
62
57
58
+ const scale =
59
+ model . moveHandle . getScale1 ( ) *
60
+ vec3 . distance (
61
+ model . apiSpecificRenderWindow . displayToWorld ( 0 , 0 , 0 , model . renderer ) ,
62
+ model . apiSpecificRenderWindow . displayToWorld ( 1 , 0 , 0 , model . renderer )
63
+ ) ;
64
+
63
65
return handles . reduce (
64
66
( { closestHandle, closestDistance } , handle ) => {
65
67
const distance = vec3 . squaredDistance (
@@ -81,8 +83,7 @@ export default function widgetBehavior(publicAPI, model) {
81
83
} ,
82
84
{
83
85
closestHandle : null ,
84
- closestDistance :
85
- model . moveHandle . getScale1 ( ) * model . moveHandle . getScale1 ( ) ,
86
+ closestDistance : scale * scale ,
86
87
}
87
88
) . closestHandle ;
88
89
} ;
@@ -98,20 +99,33 @@ export default function widgetBehavior(publicAPI, model) {
98
99
// Public methods
99
100
// --------------------------------------------------------------------------
100
101
101
- macro . setGet ( publicAPI , model , [
102
- 'freehandMinDistance' ,
103
- 'allowFreehand' ,
104
- 'resolution' ,
105
- 'defaultCursor' ,
106
- 'handleSizeInPixels' ,
107
- ] ) ;
102
+ publicAPI . setResetAfterPointPlacement =
103
+ model . factory . setResetAfterPointPlacement ;
104
+ publicAPI . getResetAfterPointPlacement =
105
+ model . factory . getResetAfterPointPlacement ;
106
+ publicAPI . setResetAfterPointPlacement (
107
+ publicAPI . getResetAfterPointPlacement ( )
108
+ ) ;
109
+
110
+ publicAPI . setFreehandMinDistance = model . factory . setFreehandMinDistance ;
111
+ publicAPI . getFreehandMinDistance = model . factory . getFreehandMinDistance ;
112
+ publicAPI . setFreehandMinDistance ( publicAPI . getFreehandMinDistance ( ) ) ;
113
+
114
+ publicAPI . setAllowFreehand = model . factory . setAllowFreehand ;
115
+ publicAPI . getAllowFreehand = model . factory . getAllowFreehand ;
116
+ publicAPI . setAllowFreehand ( publicAPI . getAllowFreehand ( ) ) ;
117
+
118
+ publicAPI . setDefaultCursor = model . factory . setDefaultCursor ;
119
+ publicAPI . getDefaultCursor = model . factory . getDefaultCursor ;
120
+ publicAPI . setDefaultCursor ( publicAPI . getDefaultCursor ( ) ) ;
108
121
109
122
// --------------------------------------------------------------------------
110
123
111
124
publicAPI . setHandleSizeInPixels = ( size ) => {
112
125
model . factory . setHandleSizeInPixels ( size ) ;
113
126
updateHandlesSize ( ) ;
114
127
} ;
128
+ publicAPI . getHandleSizeInPixels = model . factory . getHandleSizeInPixels ;
115
129
publicAPI . setHandleSizeInPixels ( model . factory . getHandleSizeInPixels ( ) ) ; // set initial value
116
130
117
131
// --------------------------------------------------------------------------
@@ -202,7 +216,7 @@ export default function widgetBehavior(publicAPI, model) {
202
216
}
203
217
}
204
218
205
- model . freeHand = model . allowFreehand && ! model . isDragging ;
219
+ model . freeHand = publicAPI . getAllowFreehand ( ) && ! model . isDragging ;
206
220
} else {
207
221
model . isDragging = true ;
208
222
model . apiSpecificRenderWindow . setCursor ( 'grabbing' ) ;
@@ -244,7 +258,13 @@ export default function widgetBehavior(publicAPI, model) {
244
258
model . moveHandle . getScale1 ( ) * model . moveHandle . getScale1 ( )
245
259
) {
246
260
model . lastHandle . setVisible ( true ) ;
247
- publicAPI . loseFocus ( ) ;
261
+ publicAPI . invokeEndInteractionEvent ( ) ;
262
+
263
+ if ( publicAPI . getResetAfterPointPlacement ( ) ) {
264
+ publicAPI . reset ( ) ;
265
+ } else {
266
+ publicAPI . loseFocus ( ) ;
267
+ }
248
268
}
249
269
}
250
270
@@ -325,11 +345,18 @@ export default function widgetBehavior(publicAPI, model) {
325
345
326
346
if ( key === 'Enter' ) {
327
347
if ( model . widgetState . getHandleList ( ) . length > 0 ) {
328
- publicAPI . loseFocus ( ) ;
348
+ publicAPI . invokeEndInteractionEvent ( ) ;
349
+
350
+ if ( publicAPI . getResetAfterPointPlacement ( ) ) {
351
+ publicAPI . reset ( ) ;
352
+ } else {
353
+ publicAPI . loseFocus ( ) ;
354
+ }
329
355
}
330
356
} else if ( key === 'Escape' ) {
331
357
publicAPI . reset ( ) ;
332
358
publicAPI . loseFocus ( ) ;
359
+ publicAPI . invokeEndInteractionEvent ( ) ;
333
360
} else if ( key === 'Delete' || key === 'Backspace' ) {
334
361
if ( model . lastHandle ) {
335
362
model . widgetState . removeHandle ( model . lastHandle ) ;
@@ -367,7 +394,6 @@ export default function widgetBehavior(publicAPI, model) {
367
394
publicAPI . loseFocus = ( ) => {
368
395
if ( model . hasFocus ) {
369
396
model . interactor . cancelAnimation ( publicAPI ) ;
370
- publicAPI . invokeEndInteractionEvent ( ) ;
371
397
}
372
398
373
399
model . widgetState . deactivate ( ) ;
0 commit comments