From 31d586461eee064976d062107741d6f2006feef1 Mon Sep 17 00:00:00 2001 From: Jonathan Olson Date: Wed, 17 Jan 2018 12:17:55 -0700 Subject: [PATCH] Removing pointer type shortcuts, see https://github.com/phetsims/scenery/issues/724 --- doc/a-tour-of-scenery.html | 8 ++++---- js/input/DownUpListener.js | 9 +++++---- js/input/Event.js | 5 +++-- js/input/Input.js | 8 ++++---- js/input/Mouse.js | 2 -- js/input/Pen.js | 2 -- js/input/SimpleDragHandler.js | 7 ++++--- js/input/Touch.js | 2 -- js/listeners/MultiListener.js | 3 ++- js/listeners/PressListener.js | 3 ++- js/nodes/Node.js | 5 ++++- js/overlays/PointerOverlay.js | 7 +++---- 12 files changed, 31 insertions(+), 30 deletions(-) diff --git a/doc/a-tour-of-scenery.html b/doc/a-tour-of-scenery.html index cf0118759..a29bd112a 100644 --- a/doc/a-tour-of-scenery.html +++ b/doc/a-tour-of-scenery.html @@ -614,7 +614,7 @@

Colored by quantity of pointers inside shape

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(); } @@ -622,7 +622,7 @@

Colored by quantity of pointers inside shape

// mouseup or touchend (pointer lifted from over the node) up: function( event ) { - if ( !event.pointer.isMouse ) { + if ( !( event.pointer instanceof scenery.Mouse ) ) { count--; updatePointers(); } @@ -699,7 +699,7 @@

Colored by quantity of pointers inside shape

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(); } @@ -707,7 +707,7 @@

Colored by quantity of pointers inside shape

// mouseup or touchend (pointer lifted from over the node) up: function( event ) { - if ( !event.pointer.isMouse ) { + if ( !( event.pointer instanceof scenery.Mouse ) ) { count--; updatePointers(); } diff --git a/js/input/DownUpListener.js b/js/input/DownUpListener.js index 54d6fffc9..13e6385cc 100644 --- a/js/input/DownUpListener.js +++ b/js/input/DownUpListener.js @@ -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. @@ -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 ); } }, @@ -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 ); diff --git a/js/input/Event.js b/js/input/Event.js index a9a466037..48bc2f846 100644 --- a/js/input/Event.js +++ b/js/input/Event.js @@ -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' ); @@ -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 ); @@ -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 ); } } ); diff --git a/js/input/Input.js b/js/input/Input.js index 52c994c55..840532cde 100644 --- a/js/input/Input.js +++ b/js/input/Input.js @@ -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. @@ -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 ); } @@ -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 ); } @@ -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 ); } diff --git a/js/input/Mouse.js b/js/input/Mouse.js index 4c4b1f9ba..d5cfa7b6d 100644 --- a/js/input/Mouse.js +++ b/js/input/Mouse.js @@ -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() ); diff --git a/js/input/Pen.js b/js/input/Pen.js index b6ce8eac1..e77c4d551 100644 --- a/js/input/Pen.js +++ b/js/input/Pen.js @@ -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(); } diff --git a/js/input/SimpleDragHandler.js b/js/input/SimpleDragHandler.js index c541da7fc..ae613ffcd 100644 --- a/js/input/SimpleDragHandler.js +++ b/js/input/SimpleDragHandler.js @@ -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' ); @@ -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 ); @@ -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, @@ -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; } diff --git a/js/input/Touch.js b/js/input/Touch.js index 5b1e401f3..91ba72547 100644 --- a/js/input/Touch.js +++ b/js/input/Touch.js @@ -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(); } diff --git a/js/listeners/MultiListener.js b/js/listeners/MultiListener.js index 6d4434d1a..319f94aca 100644 --- a/js/listeners/MultiListener.js +++ b/js/listeners/MultiListener.js @@ -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' ); @@ -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; diff --git a/js/listeners/PressListener.js b/js/listeners/PressListener.js index ea6c352f2..ff1ac72cf 100644 --- a/js/listeners/PressListener.js +++ b/js/listeners/PressListener.js @@ -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' ); @@ -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; } diff --git a/js/nodes/Node.js b/js/nodes/Node.js index 9772fbddd..819697106 100644 --- a/js/nodes/Node.js +++ b/js/nodes/Node.js @@ -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' ); @@ -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 ); }, /** diff --git a/js/overlays/PointerOverlay.js b/js/overlays/PointerOverlay.js index 9b864cc5a..a3c13079a 100644 --- a/js/overlays/PointerOverlay.js +++ b/js/overlays/PointerOverlay.js @@ -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; @@ -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 ); }