diff --git a/js/common/view/ToolboxPanel.js b/js/common/view/ToolboxPanel.js index f27c79cb..db3ec341 100644 --- a/js/common/view/ToolboxPanel.js +++ b/js/common/view/ToolboxPanel.js @@ -80,15 +80,9 @@ define( require => { } ); // When pressed, forwards dragging to the actual tracer Node - tracerIconNode.addInputListener( DragListener.createForwardingListener( function( event ) { - + tracerIconNode.addInputListener( DragListener.createForwardingListener( event => { tracer.isActiveProperty.set( true ); - - // coordinates empirically determined to shift tracer to mouse when pulled out of the toolbox - const initialViewPosition = tracerNode.globalToParentPoint( event.pointer.point ).plusXY( -180, 0 ); - tracer.positionProperty.set( transformProperty.get().viewToModelPosition( initialViewPosition ) ); - tracerNode.movableDragHandler.startDrag( event ); - + tracerNode.dragListener.press( event, tracerNode ); }, { allowTouchSnag: true } ) ); // tracer visibility has the opposite visibility of the tracerIcon diff --git a/js/common/view/TracerNode.js b/js/common/view/TracerNode.js index 0e39e475..cfe123bf 100644 --- a/js/common/view/TracerNode.js +++ b/js/common/view/TracerNode.js @@ -12,11 +12,11 @@ define( require => { const BooleanProperty = require( 'AXON/BooleanProperty' ); const Bounds2 = require( 'DOT/Bounds2' ); const Circle = require( 'SCENERY/nodes/Circle' ); + const DragListener = require( 'SCENERY/listeners/DragListener' ); const HBox = require( 'SCENERY/nodes/HBox' ); const inherit = require( 'PHET_CORE/inherit' ); const MathSymbols = require( 'SCENERY_PHET/MathSymbols' ); const merge = require( 'PHET_CORE/merge' ); - const MovableDragHandler = require( 'SCENERY_PHET/input/MovableDragHandler' ); const Node = require( 'SCENERY/nodes/Node' ); const Path = require( 'SCENERY/nodes/Path' ); const projectileMotion = require( 'PROJECTILE_MOTION/projectileMotion' ); @@ -77,6 +77,9 @@ define( require => { const RIGHT_SIDE_PADDING = 6; const READOUT_X_MARGIN = ProjectileMotionConstants.RIGHTSIDE_PANEL_OPTIONS.readoutXMargin; + // coordinates empirically determined to shift tracer to mouse when pulled out of the toolbox + const DRAG_OFFSET = new Vector2( -180, 0 ); + /** * @param {Score} tracer - model of the tracer tool * @param {Property.} transformProperty @@ -146,17 +149,18 @@ define( require => { { fill: 'gray' } ); + const dragBoundsProperty = new Property( screenView.visibleBoundsProperty.get().shiftedX( dragBoundsShift ) ); + // @public so events can be forwarded to it by ToolboxPanel - this.movableDragHandler = new MovableDragHandler( tracer.positionProperty, { + this.dragListener = new DragListener( { + locationProperty: tracer.positionProperty, modelViewTransform: transformProperty.get(), - dragBounds: screenView.visibleBoundsProperty.get().shiftedX( dragBoundsShift ), - startDrag: function( event ) { - self.isUserControlledProperty.set( true ); - }, - endDrag: function() { - self.isUserControlledProperty.set( false ); - }, - tandem: options.tandem.createTandem( 'dragHandler' ) + dragBoundsProperty: dragBoundsProperty, + offsetLocation: () => DRAG_OFFSET, + applyOffset: false, // ignore where the pointer pressed in relation to the TracerNode origin + start: () => self.isUserControlledProperty.set( true ), + end: () => self.isUserControlledProperty.set( false ), + tandem: options.tandem.createTandem( 'dragListener' ) } ); // label and values readouts @@ -244,14 +248,14 @@ define( require => { // Observe changes in the modelViewTransform and update/adjust positions accordingly transformProperty.link( function( transform ) { - self.movableDragHandler.setModelViewTransform( transform ); - self.movableDragHandler.setDragBounds( transform.viewToModelBounds( screenView.visibleBoundsProperty.get().shiftedX( dragBoundsShift ) ) ); + self.dragListener.transform = transform; + dragBoundsProperty.value = transform.viewToModelBounds( screenView.visibleBoundsProperty.get().shiftedX( dragBoundsShift ) ); updatePosition( tracer.positionProperty.get() ); } ); // Observe changes in the visible bounds and update drag bounds and adjust positions accordingly screenView.visibleBoundsProperty.link( function( bounds ) { - self.movableDragHandler.setDragBounds( transformProperty.get().viewToModelBounds( screenView.visibleBoundsProperty.get().shiftedX( dragBoundsShift ) ) ); + dragBoundsProperty.value = transformProperty.get().viewToModelBounds( screenView.visibleBoundsProperty.get().shiftedX( dragBoundsShift ) ); updatePosition( tracer.positionProperty.get() ); } ); @@ -275,7 +279,7 @@ define( require => { Node.call( this, options ); // When dragging, move the tracer tool - this.addInputListener( this.movableDragHandler ); + this.addInputListener( this.dragListener ); // visibility of the tracer tracer.isActiveProperty.link( function( active ) { diff --git a/js/phet-io/projectile-motion-phet-io-elements-baseline.js b/js/phet-io/projectile-motion-phet-io-elements-baseline.js index 173a627c..76a66ebf 100644 --- a/js/phet-io/projectile-motion-phet-io-elements-baseline.js +++ b/js/phet-io/projectile-motion-phet-io-elements-baseline.js @@ -5136,70 +5136,44 @@ window.phet.phetio.phetioElementsBaseline = assert && "phetioStudioControl": true, "phetioTypeName": "NodeIO" }, - "projectileMotion.dragScreen.view.tracerNode.dragHandler": { - "phetioDocumentation": "", + "projectileMotion.dragScreen.view.tracerNode.dragListener.dragAction": { + "phetioDocumentation": "Emits whenever a drag occurs with an EventIO argument. The arguments are:
  1. event: EventIO
", "phetioDynamicElement": false, "phetioDynamicElementPrototype": false, "phetioEventType": "USER", "phetioFeatured": false, - "phetioHighFrequency": false, - "phetioPlayback": false, - "phetioReadOnly": true, - "phetioState": false, - "phetioStudioControl": true, - "phetioTypeName": "ObjectIO" - }, - "projectileMotion.dragScreen.view.tracerNode.dragHandler.dragAction": { - "phetioDocumentation": "A function that executes. The arguments are:
  1. point: Vector2IO. the position of the drag in view coordinates
", - "phetioDynamicElement": false, - "phetioDynamicElementPrototype": false, - "phetioEventType": "MODEL", - "phetioFeatured": false, "phetioHighFrequency": true, "phetioPlayback": false, - "phetioReadOnly": true, - "phetioState": false, - "phetioStudioControl": true, - "phetioTypeName": "ActionIO" - }, - "projectileMotion.dragScreen.view.tracerNode.dragHandler.dragEndAction": { - "phetioDocumentation": "A function that executes. The arguments are:
  1. point: Vector2IO. the position of the drag end in view coordinates
", - "phetioDynamicElement": false, - "phetioDynamicElementPrototype": false, - "phetioEventType": "MODEL", - "phetioFeatured": false, - "phetioHighFrequency": false, - "phetioPlayback": false, - "phetioReadOnly": true, + "phetioReadOnly": false, "phetioState": false, "phetioStudioControl": true, - "phetioTypeName": "ActionIO" + "phetioTypeName": "ActionIO" }, - "projectileMotion.dragScreen.view.tracerNode.dragHandler.dragStartAction": { - "phetioDocumentation": "A function that executes. The arguments are:
  1. point: Vector2IO. the position of the drag start in view coordinates
", + "projectileMotion.dragScreen.view.tracerNode.dragListener.pressAction": { + "phetioDocumentation": "Executes whenever a press occurs. The first argument when executing can be used to convey info about the Event. The arguments are:
  1. event: EventIO
", "phetioDynamicElement": false, "phetioDynamicElementPrototype": false, - "phetioEventType": "MODEL", + "phetioEventType": "USER", "phetioFeatured": false, "phetioHighFrequency": false, "phetioPlayback": false, - "phetioReadOnly": true, + "phetioReadOnly": false, "phetioState": false, "phetioStudioControl": true, - "phetioTypeName": "ActionIO" + "phetioTypeName": "ActionIO" }, - "projectileMotion.dragScreen.view.tracerNode.dragHandler.isDraggingProperty": { - "phetioDocumentation": "Indicates whether the object is dragging", + "projectileMotion.dragScreen.view.tracerNode.dragListener.releaseAction": { + "phetioDocumentation": "Executes whenever a release occurs. The arguments are:
  1. event: NullableIO
", "phetioDynamicElement": false, "phetioDynamicElementPrototype": false, - "phetioEventType": "MODEL", + "phetioEventType": "USER", "phetioFeatured": false, "phetioHighFrequency": false, "phetioPlayback": false, - "phetioReadOnly": true, + "phetioReadOnly": false, "phetioState": false, "phetioStudioControl": true, - "phetioTypeName": "PropertyIO" + "phetioTypeName": "ActionIO>" }, "projectileMotion.dragScreen.view.tracerNode.opacityProperty": { "phetioDocumentation": "Opacity of the parent NodeIO, between 0 (invisible) and 1 (fully visible)", @@ -13287,70 +13261,44 @@ window.phet.phetio.phetioElementsBaseline = assert && "phetioStudioControl": true, "phetioTypeName": "NodeIO" }, - "projectileMotion.introScreen.view.tracerNode.dragHandler": { - "phetioDocumentation": "", + "projectileMotion.introScreen.view.tracerNode.dragListener.dragAction": { + "phetioDocumentation": "Emits whenever a drag occurs with an EventIO argument. The arguments are:
  1. event: EventIO
", "phetioDynamicElement": false, "phetioDynamicElementPrototype": false, "phetioEventType": "USER", "phetioFeatured": false, - "phetioHighFrequency": false, - "phetioPlayback": false, - "phetioReadOnly": true, - "phetioState": false, - "phetioStudioControl": true, - "phetioTypeName": "ObjectIO" - }, - "projectileMotion.introScreen.view.tracerNode.dragHandler.dragAction": { - "phetioDocumentation": "A function that executes. The arguments are:
  1. point: Vector2IO. the position of the drag in view coordinates
", - "phetioDynamicElement": false, - "phetioDynamicElementPrototype": false, - "phetioEventType": "MODEL", - "phetioFeatured": false, "phetioHighFrequency": true, "phetioPlayback": false, - "phetioReadOnly": true, - "phetioState": false, - "phetioStudioControl": true, - "phetioTypeName": "ActionIO" - }, - "projectileMotion.introScreen.view.tracerNode.dragHandler.dragEndAction": { - "phetioDocumentation": "A function that executes. The arguments are:
  1. point: Vector2IO. the position of the drag end in view coordinates
", - "phetioDynamicElement": false, - "phetioDynamicElementPrototype": false, - "phetioEventType": "MODEL", - "phetioFeatured": false, - "phetioHighFrequency": false, - "phetioPlayback": false, - "phetioReadOnly": true, + "phetioReadOnly": false, "phetioState": false, "phetioStudioControl": true, - "phetioTypeName": "ActionIO" + "phetioTypeName": "ActionIO" }, - "projectileMotion.introScreen.view.tracerNode.dragHandler.dragStartAction": { - "phetioDocumentation": "A function that executes. The arguments are:
  1. point: Vector2IO. the position of the drag start in view coordinates
", + "projectileMotion.introScreen.view.tracerNode.dragListener.pressAction": { + "phetioDocumentation": "Executes whenever a press occurs. The first argument when executing can be used to convey info about the Event. The arguments are:
  1. event: EventIO
", "phetioDynamicElement": false, "phetioDynamicElementPrototype": false, - "phetioEventType": "MODEL", + "phetioEventType": "USER", "phetioFeatured": false, "phetioHighFrequency": false, "phetioPlayback": false, - "phetioReadOnly": true, + "phetioReadOnly": false, "phetioState": false, "phetioStudioControl": true, - "phetioTypeName": "ActionIO" + "phetioTypeName": "ActionIO" }, - "projectileMotion.introScreen.view.tracerNode.dragHandler.isDraggingProperty": { - "phetioDocumentation": "Indicates whether the object is dragging", + "projectileMotion.introScreen.view.tracerNode.dragListener.releaseAction": { + "phetioDocumentation": "Executes whenever a release occurs. The arguments are:
  1. event: NullableIO
", "phetioDynamicElement": false, "phetioDynamicElementPrototype": false, - "phetioEventType": "MODEL", + "phetioEventType": "USER", "phetioFeatured": false, "phetioHighFrequency": false, "phetioPlayback": false, - "phetioReadOnly": true, + "phetioReadOnly": false, "phetioState": false, "phetioStudioControl": true, - "phetioTypeName": "PropertyIO" + "phetioTypeName": "ActionIO>" }, "projectileMotion.introScreen.view.tracerNode.opacityProperty": { "phetioDocumentation": "Opacity of the parent NodeIO, between 0 (invisible) and 1 (fully visible)", @@ -35114,70 +35062,44 @@ window.phet.phetio.phetioElementsBaseline = assert && "phetioStudioControl": true, "phetioTypeName": "NodeIO" }, - "projectileMotion.labScreen.view.tracerNode.dragHandler": { - "phetioDocumentation": "", + "projectileMotion.labScreen.view.tracerNode.dragListener.dragAction": { + "phetioDocumentation": "Emits whenever a drag occurs with an EventIO argument. The arguments are:
  1. event: EventIO
", "phetioDynamicElement": false, "phetioDynamicElementPrototype": false, "phetioEventType": "USER", "phetioFeatured": false, - "phetioHighFrequency": false, - "phetioPlayback": false, - "phetioReadOnly": true, - "phetioState": false, - "phetioStudioControl": true, - "phetioTypeName": "ObjectIO" - }, - "projectileMotion.labScreen.view.tracerNode.dragHandler.dragAction": { - "phetioDocumentation": "A function that executes. The arguments are:
  1. point: Vector2IO. the position of the drag in view coordinates
", - "phetioDynamicElement": false, - "phetioDynamicElementPrototype": false, - "phetioEventType": "MODEL", - "phetioFeatured": false, "phetioHighFrequency": true, "phetioPlayback": false, - "phetioReadOnly": true, - "phetioState": false, - "phetioStudioControl": true, - "phetioTypeName": "ActionIO" - }, - "projectileMotion.labScreen.view.tracerNode.dragHandler.dragEndAction": { - "phetioDocumentation": "A function that executes. The arguments are:
  1. point: Vector2IO. the position of the drag end in view coordinates
", - "phetioDynamicElement": false, - "phetioDynamicElementPrototype": false, - "phetioEventType": "MODEL", - "phetioFeatured": false, - "phetioHighFrequency": false, - "phetioPlayback": false, - "phetioReadOnly": true, + "phetioReadOnly": false, "phetioState": false, "phetioStudioControl": true, - "phetioTypeName": "ActionIO" + "phetioTypeName": "ActionIO" }, - "projectileMotion.labScreen.view.tracerNode.dragHandler.dragStartAction": { - "phetioDocumentation": "A function that executes. The arguments are:
  1. point: Vector2IO. the position of the drag start in view coordinates
", + "projectileMotion.labScreen.view.tracerNode.dragListener.pressAction": { + "phetioDocumentation": "Executes whenever a press occurs. The first argument when executing can be used to convey info about the Event. The arguments are:
  1. event: EventIO
", "phetioDynamicElement": false, "phetioDynamicElementPrototype": false, - "phetioEventType": "MODEL", + "phetioEventType": "USER", "phetioFeatured": false, "phetioHighFrequency": false, "phetioPlayback": false, - "phetioReadOnly": true, + "phetioReadOnly": false, "phetioState": false, "phetioStudioControl": true, - "phetioTypeName": "ActionIO" + "phetioTypeName": "ActionIO" }, - "projectileMotion.labScreen.view.tracerNode.dragHandler.isDraggingProperty": { - "phetioDocumentation": "Indicates whether the object is dragging", + "projectileMotion.labScreen.view.tracerNode.dragListener.releaseAction": { + "phetioDocumentation": "Executes whenever a release occurs. The arguments are:
  1. event: NullableIO
", "phetioDynamicElement": false, "phetioDynamicElementPrototype": false, - "phetioEventType": "MODEL", + "phetioEventType": "USER", "phetioFeatured": false, "phetioHighFrequency": false, "phetioPlayback": false, - "phetioReadOnly": true, + "phetioReadOnly": false, "phetioState": false, "phetioStudioControl": true, - "phetioTypeName": "PropertyIO" + "phetioTypeName": "ActionIO>" }, "projectileMotion.labScreen.view.tracerNode.opacityProperty": { "phetioDocumentation": "Opacity of the parent NodeIO, between 0 (invisible) and 1 (fully visible)", @@ -39560,70 +39482,44 @@ window.phet.phetio.phetioElementsBaseline = assert && "phetioStudioControl": true, "phetioTypeName": "NodeIO" }, - "projectileMotion.vectorsScreen.view.tracerNode.dragHandler": { - "phetioDocumentation": "", + "projectileMotion.vectorsScreen.view.tracerNode.dragListener.dragAction": { + "phetioDocumentation": "Emits whenever a drag occurs with an EventIO argument. The arguments are:
  1. event: EventIO
", "phetioDynamicElement": false, "phetioDynamicElementPrototype": false, "phetioEventType": "USER", "phetioFeatured": false, - "phetioHighFrequency": false, - "phetioPlayback": false, - "phetioReadOnly": true, - "phetioState": false, - "phetioStudioControl": true, - "phetioTypeName": "ObjectIO" - }, - "projectileMotion.vectorsScreen.view.tracerNode.dragHandler.dragAction": { - "phetioDocumentation": "A function that executes. The arguments are:
  1. point: Vector2IO. the position of the drag in view coordinates
", - "phetioDynamicElement": false, - "phetioDynamicElementPrototype": false, - "phetioEventType": "MODEL", - "phetioFeatured": false, "phetioHighFrequency": true, "phetioPlayback": false, - "phetioReadOnly": true, - "phetioState": false, - "phetioStudioControl": true, - "phetioTypeName": "ActionIO" - }, - "projectileMotion.vectorsScreen.view.tracerNode.dragHandler.dragEndAction": { - "phetioDocumentation": "A function that executes. The arguments are:
  1. point: Vector2IO. the position of the drag end in view coordinates
", - "phetioDynamicElement": false, - "phetioDynamicElementPrototype": false, - "phetioEventType": "MODEL", - "phetioFeatured": false, - "phetioHighFrequency": false, - "phetioPlayback": false, - "phetioReadOnly": true, + "phetioReadOnly": false, "phetioState": false, "phetioStudioControl": true, - "phetioTypeName": "ActionIO" + "phetioTypeName": "ActionIO" }, - "projectileMotion.vectorsScreen.view.tracerNode.dragHandler.dragStartAction": { - "phetioDocumentation": "A function that executes. The arguments are:
  1. point: Vector2IO. the position of the drag start in view coordinates
", + "projectileMotion.vectorsScreen.view.tracerNode.dragListener.pressAction": { + "phetioDocumentation": "Executes whenever a press occurs. The first argument when executing can be used to convey info about the Event. The arguments are:
  1. event: EventIO
", "phetioDynamicElement": false, "phetioDynamicElementPrototype": false, - "phetioEventType": "MODEL", + "phetioEventType": "USER", "phetioFeatured": false, "phetioHighFrequency": false, "phetioPlayback": false, - "phetioReadOnly": true, + "phetioReadOnly": false, "phetioState": false, "phetioStudioControl": true, - "phetioTypeName": "ActionIO" + "phetioTypeName": "ActionIO" }, - "projectileMotion.vectorsScreen.view.tracerNode.dragHandler.isDraggingProperty": { - "phetioDocumentation": "Indicates whether the object is dragging", + "projectileMotion.vectorsScreen.view.tracerNode.dragListener.releaseAction": { + "phetioDocumentation": "Executes whenever a release occurs. The arguments are:
  1. event: NullableIO
", "phetioDynamicElement": false, "phetioDynamicElementPrototype": false, - "phetioEventType": "MODEL", + "phetioEventType": "USER", "phetioFeatured": false, "phetioHighFrequency": false, "phetioPlayback": false, - "phetioReadOnly": true, + "phetioReadOnly": false, "phetioState": false, "phetioStudioControl": true, - "phetioTypeName": "PropertyIO" + "phetioTypeName": "ActionIO>" }, "projectileMotion.vectorsScreen.view.tracerNode.opacityProperty": { "phetioDocumentation": "Opacity of the parent NodeIO, between 0 (invisible) and 1 (fully visible)",