Skip to content

Commit

Permalink
Added SimpleDragHandler.createForwardingListener, see phetsims/scener…
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Jul 1, 2017
1 parent 86da66a commit 8cb6469
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 39 deletions.
29 changes: 6 additions & 23 deletions js/view/CircuitElementToolNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ define( function( require ) {
var VBox = require( 'SCENERY/nodes/VBox' );
var Text = require( 'SCENERY/nodes/Text' );
var CircuitConstructionKitConstants = require( 'CIRCUIT_CONSTRUCTION_KIT_COMMON/CircuitConstructionKitConstants' );
var SimpleDragHandler = require( 'SCENERY/input/SimpleDragHandler' );

// constants
var TOOLBOX_ICON_SIZE = CircuitConstructionKitConstants.TOOLBOX_ICON_SIZE;
Expand All @@ -28,9 +29,7 @@ define( function( require ) {
* @param {function} createElement
* @constructor
*/
function CircuitElementToolNode(
labelText, showLabelsProperty, circuitLayerNode, iconNode, maxNumber, count, createElement
) {
function CircuitElementToolNode( labelText, showLabelsProperty, circuitLayerNode, iconNode, maxNumber, count, createElement ) {
var circuit = circuitLayerNode.circuit;
var self = this;
var labelNode = new Text( labelText, { fontSize: 12, maxWidth: TOOLBOX_ICON_SIZE } );
Expand All @@ -44,25 +43,8 @@ define( function( require ) {
children: labelText.length > 0 ? [ iconNode, labelNode ] : [ iconNode ]
} );

this.addInputListener( {

// ad-hoc touchSnag to support multiple dragging out at once
touchenter: function( event ) {
this.down( event );
},

// ad-hoc touchSnag to support multiple dragging out at once
touchmove: function( event ) {
this.down( event );
},

this.addInputListener( SimpleDragHandler.createForwardingListener( {
down: function( event ) {
if ( event.pointer.dragging ) {
return;
}

// Don't try to start drags with a right mouse button or an attached pointer.
if ( !event.canStartPress() ) { return; }

// initial position of the pointer in the coordinate frame of the CircuitLayerNode
var viewPosition = circuitLayerNode.globalToLocalPoint( event.pointer.point );
Expand All @@ -79,9 +61,10 @@ define( function( require ) {
// listener (which adds a listener to the pointer, in the usual SimpleDragHandler way), and it seems like a good
// pattern.
circuitElement.startDragEmitter.emit1( event );

}
} );
}, {
allowTouchSnag: true
} ) );

circuit.circuitElements.lengthProperty.link( function() {
self.visible = count() < maxNumber;
Expand Down
21 changes: 5 additions & 16 deletions js/view/SensorToolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ define( function( require ) {
var Text = require( 'SCENERY/nodes/Text' );
var Property = require( 'AXON/Property' );
var CircuitConstructionKitConstants = require( 'CIRCUIT_CONSTRUCTION_KIT_COMMON/CircuitConstructionKitConstants' );
var SimpleDragHandler = require( 'SCENERY/input/SimpleDragHandler' );

// strings
var ammeterString = require( 'string!CIRCUIT_CONSTRUCTION_KIT_COMMON/ammeter' );
Expand Down Expand Up @@ -62,29 +63,17 @@ define( function( require ) {
*/
var createListener = function( meterModel, meterNode ) {

return {

// ad-hoc touchSnag
touchenter: function( event ) {
this.down( event );
},

// ad-hoc touchSnag
touchmove: function( event ) {
this.down( event );
},

return SimpleDragHandler.createForwardingListener( {
down: function( event ) {
if ( event.pointer.dragging ) {
return;
}
var viewPosition = circuitLayerNode.globalToLocalPoint( event.pointer.point );
meterModel.draggingProbesWithBodyProperty.set( true );
meterModel.visibleProperty.set( true );
meterModel.bodyPositionProperty.set( viewPosition );
meterNode.dragHandler.startDrag( event );
}
};
}, {
allowTouchSnag: true,
} );
};

// Draggable icon for the voltmeter
Expand Down

0 comments on commit 8cb6469

Please sign in to comment.