Skip to content

Commit

Permalink
Removing pointer type shortcuts, see #724
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanolson committed Jan 17, 2018
1 parent 88abb6a commit 31d5864
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 30 deletions.
8 changes: 4 additions & 4 deletions doc/a-tour-of-scenery.html
Original file line number Diff line number Diff line change
Expand Up @@ -614,15 +614,15 @@ <h4>Colored by quantity of pointers inside shape</h4>
node.addInputListener( {
// mousedown or touchstart (pointer pressed down over the node)
down: function( event ) {
if ( !event.pointer.isMouse ) {
if ( !( event.pointer instanceof scenery.Mouse ) ) {
count++;
updatePointers();
}
},

// mouseup or touchend (pointer lifted from over the node)
up: function( event ) {
if ( !event.pointer.isMouse ) {
if ( !( event.pointer instanceof scenery.Mouse ) ) {
count--;
updatePointers();
}
Expand Down Expand Up @@ -699,15 +699,15 @@ <h4>Colored by quantity of pointers inside shape</h4>
node.addInputListener( {
// mousedown or touchstart (pointer pressed down over the node)
down: function( event ) {
if ( !event.pointer.isMouse ) {
if ( !( event.pointer instanceof scenery.Mouse ) ) {
count++;
updatePointers();
}
},

// mouseup or touchend (pointer lifted from over the node)
up: function( event ) {
if ( !event.pointer.isMouse ) {
if ( !( event.pointer instanceof scenery.Mouse ) ) {
count--;
updatePointers();
}
Expand Down
9 changes: 5 additions & 4 deletions js/input/DownUpListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ define( function( require ) {
'use strict';

var inherit = require( 'PHET_CORE/inherit' );
var KeyboardUtil = require( 'SCENERY/accessibility/KeyboardUtil' );
var Mouse = require( 'SCENERY/input/Mouse' );
var PhetioObject = require( 'TANDEM/PhetioObject' );
var Trail = require( 'SCENERY/util/Trail' );
var scenery = require( 'SCENERY/scenery' );
require( 'SCENERY/util/Trail' );
var KeyboardUtil = require( 'SCENERY/accessibility/KeyboardUtil' );
var Trail = require( 'SCENERY/util/Trail' );

/*
* The 'trail' parameter passed to down/upInside/upOutside will end with the node to which this DownUpListener has been added.
Expand Down Expand Up @@ -57,7 +58,7 @@ define( function( require ) {
up: function( event ) {
sceneryLog && sceneryLog.InputEvent && sceneryLog.InputEvent( 'DownUpListener (pointer) up for ' + self.downTrail.toString() );
assert && assert( event.pointer === self.pointer );
if ( !event.pointer.isMouse || event.domEvent.button === self.options.mouseButton ) {
if ( !( event.pointer instanceof Mouse ) || event.domEvent.button === self.options.mouseButton ) {
self.buttonUp( event );
}
},
Expand Down Expand Up @@ -88,7 +89,7 @@ define( function( require ) {
if ( this.isDown ) { return; }

// ignore other mouse buttons
if ( event.pointer.isMouse && event.domEvent.button !== this.options.mouseButton ) { return; }
if ( event.pointer instanceof Mouse && event.domEvent.button !== this.options.mouseButton ) { return; }

// add our listener so we catch the up wherever we are
event.pointer.addInputListener( this.downListener );
Expand Down
5 changes: 3 additions & 2 deletions js/input/Event.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ define( function( require ) {
'use strict';

var inherit = require( 'PHET_CORE/inherit' );
var Mouse = require( 'SCENERY/input/Mouse' );
var Pointer = require( 'SCENERY/input/Pointer' );
var scenery = require( 'SCENERY/scenery' );
var Trail = require( 'SCENERY/util/Trail' );
Expand Down Expand Up @@ -61,7 +62,7 @@ define( function( require ) {
// @public {boolean} - Whether this is the 'primary' mode for the pointer. Always true for touches, and will be true
// for the mouse if it is the primary (left) mouse button.
// TODO: don't require check on domEvent (seems sometimes this is passed as null as a hack?)
this.isPrimary = !pointer.isMouse || !domEvent || domEvent.button === 0;
this.isPrimary = !( pointer instanceof Mouse ) || !domEvent || domEvent.button === 0;
}

scenery.register( 'Event', Event );
Expand Down Expand Up @@ -99,7 +100,7 @@ define( function( require ) {
canStartPress: function() {
// If the pointer is already attached (some other press probably), it can't start a press.
// Additionally, we generally want to ignore non-left mouse buttons.
return !this.pointer.isAttached() && ( !this.pointer.isMouse || this.domEvent.button === 0 );
return !this.pointer.isAttached() && ( !( this.pointer instanceof Mouse ) || this.domEvent.button === 0 );
}
} );

Expand Down
8 changes: 4 additions & 4 deletions js/input/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ define( function( require ) {

for ( var i = this.pointers.length - 1; i >= 0; i-- ) {
var pointer = this.pointers[ i ];
if ( !pointer.isMouse ) {
if ( !( pointer instanceof Mouse ) ) {
this.pointers.splice( i, 1 );

// Send exit events. As we can't get a DOM event, we'll send a fake object instead.
Expand Down Expand Up @@ -716,7 +716,7 @@ define( function( require ) {
this.dispatchEvent( trail, 'up', pointer, event, true );

// touch pointers are transient, so fire exit/out to the trail afterwards
if ( pointer.isTouch ) {
if ( pointer instanceof Touch ) {
this.exitEvents( pointer, event, trail, 0, true );
}

Expand All @@ -727,7 +727,7 @@ define( function( require ) {
var trail = this.rootNode.trailUnderPointer( pointer ) || new Trail( this.rootNode );

// touch pointers are transient, so fire enter/over to the trail first
if ( pointer.isTouch ) {
if ( pointer instanceof Touch ) {
this.enterEvents( pointer, event, trail, 0, true );
}

Expand Down Expand Up @@ -769,7 +769,7 @@ define( function( require ) {
this.dispatchEvent( trail, 'cancel', pointer, event, true );

// touch pointers are transient, so fire exit/out to the trail afterwards
if ( pointer.isTouch ) {
if ( pointer instanceof Touch ) {
this.exitEvents( pointer, event, trail, 0, true );
}

Expand Down
2 changes: 0 additions & 2 deletions js/input/Mouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ define( function( require ) {
inherit( Pointer, Mouse, {
type: 'mouse',

isMouse: true,

down: function( point, event ) {
var pointChanged = this.hasPointChanged( point );
point && sceneryLog && sceneryLog.InputEvent && sceneryLog.InputEvent( 'mouse down at ' + point.toString() );
Expand Down
2 changes: 0 additions & 2 deletions js/input/Pen.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ define( function( require ) {
inherit( Pointer, Pen, {
type: 'pen',

isPen: true,

move: function( point, event ) {
var pointChanged = this.hasPointChanged( point );
// if ( this.point ) { this.point.freeToPool(); }
Expand Down
7 changes: 4 additions & 3 deletions js/input/SimpleDragHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ define( function( require ) {
'use strict';

var inherit = require( 'PHET_CORE/inherit' );
var Mouse = require( 'SCENERY/input/Mouse' );
var PhetioObject = require( 'TANDEM/PhetioObject' );
var scenery = require( 'SCENERY/scenery' );
var Tandem = require( 'TANDEM/Tandem' );
Expand Down Expand Up @@ -78,7 +79,7 @@ define( function( require ) {
if ( !self.dragging ) { return; }

assert && assert( event.pointer === self.pointer, 'Wrong pointer in up' );
if ( !event.pointer.isMouse || event.domEvent.button === self.mouseButton ) {
if ( !( event.pointer instanceof Mouse ) || event.domEvent.button === self.mouseButton ) {
var saveCurrentTarget = event.currentTarget;
event.currentTarget = self.node; // #66: currentTarget on a pointer is null, so set it to the node we're dragging
self.endDrag( event );
Expand Down Expand Up @@ -170,7 +171,7 @@ define( function( require ) {
this.lastDragPoint = event.pointer.point;
this.startTransformMatrix = event.currentTarget.getMatrix().copy();
// event.domEvent may not exist if this is touch-to-snag
this.mouseButton = event.pointer.isMouse ? event.domEvent.button : undefined;
this.mouseButton = event.pointer instanceof Mouse ? event.domEvent.button : undefined;

this.startEvent( 'user', 'dragStarted', {
x: event.pointer.point.x,
Expand Down Expand Up @@ -221,7 +222,7 @@ define( function( require ) {

tryToSnag: function( event ) {
// don't allow drag attempts that use the wrong mouse button (-1 indicates any mouse button works)
if ( event.pointer.isMouse && event.domEvent && this.options.mouseButton !== event.domEvent.button && this.options.mouseButton !== -1 ) {
if ( event.pointer instanceof Mouse && event.domEvent && this.options.mouseButton !== event.domEvent.button && this.options.mouseButton !== -1 ) {
return;
}

Expand Down
2 changes: 0 additions & 2 deletions js/input/Touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ define( function( require ) {
inherit( Pointer, Touch, {
type: 'touch',

isTouch: true,

move: function( point, event ) {
var pointChanged = this.hasPointChanged( point );
// if ( this.point ) { this.point.freeToPool(); }
Expand Down
3 changes: 2 additions & 1 deletion js/listeners/MultiListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ define( function( require ) {
var inherit = require( 'PHET_CORE/inherit' );
var Matrix = require( 'DOT/Matrix' );
var Matrix3 = require( 'DOT/Matrix3' );
var Mouse = require( 'SCENERY/input/Mouse' );
var scenery = require( 'SCENERY/scenery' );
var SingularValueDecomposition = require( 'DOT/SingularValueDecomposition' );
var Vector2 = require( 'DOT/Vector2' );
Expand Down Expand Up @@ -158,7 +159,7 @@ define( function( require ) {
down: function( event ) {
sceneryLog && sceneryLog.InputListener && sceneryLog.InputListener( 'MultiListener down' );

if ( event.pointer.isMouse && event.domEvent.button !== this._mouseButton ) {
if ( event.pointer instanceof Mouse && event.domEvent.button !== this._mouseButton ) {
sceneryLog && sceneryLog.InputListener && sceneryLog.InputListener( 'MultiListener abort: wrong mouse button' );

return;
Expand Down
3 changes: 2 additions & 1 deletion js/listeners/PressListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ define( function( require ) {

var BooleanProperty = require( 'AXON/BooleanProperty' );
var inherit = require( 'PHET_CORE/inherit' );
var Mouse = require( 'SCENERY/input/Mouse' );
var Node = require( 'SCENERY/nodes/Node' );
var ObservableArray = require( 'AXON/ObservableArray' );
var PhetioObject = require( 'TANDEM/PhetioObject' );
Expand Down Expand Up @@ -355,7 +356,7 @@ define( function( require ) {
}

// Only let presses be started with the correct mouse button.
if ( event.pointer.isMouse && event.domEvent.button !== this._mouseButton ) {
if ( event.pointer instanceof Mouse && event.domEvent.button !== this._mouseButton ) {
return false;
}

Expand Down
5 changes: 4 additions & 1 deletion js/nodes/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,15 @@ define( function( require ) {
var extend = require( 'PHET_CORE/extend' );
var inherit = require( 'PHET_CORE/inherit' );
var Matrix3 = require( 'DOT/Matrix3' );
var Mouse = require( 'SCENERY/input/Mouse' );
var Pen = require( 'SCENERY/input/Pen' );
var Picker = require( 'SCENERY/util/Picker' );
var PhetioObject = require( 'TANDEM/PhetioObject' );
var Renderer = require( 'SCENERY/display/Renderer' );
var RendererSummary = require( 'SCENERY/util/RendererSummary' );
var scenery = require( 'SCENERY/scenery' );
var Shape = require( 'KITE/Shape' );
var Touch = require( 'SCENERY/input/Touch' );
var Transform3 = require( 'DOT/Transform3' );
var Util = require( 'DOT/Util' );
var Vector2 = require( 'DOT/Vector2' );
Expand Down Expand Up @@ -1553,7 +1556,7 @@ define( function( require ) {
* @returns {Trail|null}
*/
trailUnderPointer: function( pointer ) {
return this.hitTest( pointer.point, pointer.isMouse, pointer.isTouch || pointer.isPen );
return this.hitTest( pointer.point, pointer instanceof Mouse, pointer instanceof Touch || pointer instanceof Pen );
},

/**
Expand Down
7 changes: 3 additions & 4 deletions js/overlays/PointerOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ define( function( require ) {

var inherit = require( 'PHET_CORE/inherit' );
var Matrix3 = require( 'DOT/Matrix3' );

var scenery = require( 'SCENERY/scenery' );
require( 'SCENERY/util/Trail' );

var Touch = require( 'SCENERY/input/Touch' );
var Util = require( 'SCENERY/util/Util' );
require( 'SCENERY/util/Trail' );

function PointerOverlay( display, rootNode ) {
var self = this;
Expand Down Expand Up @@ -76,7 +75,7 @@ define( function( require ) {
var pointerRemoved = function() {

//For touches that get a touch up event, remove them. But when the mouse button is released, don't stop showing the mouse location
if ( pointer.isTouch ) {
if ( pointer instanceof Touch ) {
self.pointerSVGContainer.removeChild( svg );
pointer.removeInputListener( moveListener );
}
Expand Down

0 comments on commit 31d5864

Please sign in to comment.