Skip to content

Commit

Permalink
Add Properties to enabled/disable rotation/drag independently, see #397
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Feb 9, 2021
1 parent 7110444 commit f20d694
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
50 changes: 43 additions & 7 deletions js/common/view/LaserNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* @author Chandrashekar Bemagoni (Actual Concepts)
*/

import BooleanProperty from '../../../../axon/js/BooleanProperty.js';
import Property from '../../../../axon/js/Property.js';
import Dimension2 from '../../../../dot/js/Dimension2.js';
import Vector2 from '../../../../dot/js/Vector2.js';
Expand Down Expand Up @@ -99,7 +100,7 @@ class LaserNode extends Node {
// add the drag region for translating the laser
let start;

translationTarget && translationTarget.addInputListener( new SimpleDragHandler( {
const translationListener = new SimpleDragHandler( {
start: event => {
start = this.globalToParentPoint( event.pointer.point );
showTranslationDragHandlesProperty.value = true;
Expand Down Expand Up @@ -138,19 +139,21 @@ class LaserNode extends Node {
showTranslationDragHandlesProperty.value = false;
occlusionHandler( this );
}
} ) );
} );
translationTarget && translationTarget.addInputListener( translationListener );

// Listeners to enable/disable the translation dragHandles
translationTarget && translationTarget.addInputListener( {
const translationOverListener = {
enter: () => {
showTranslationDragHandlesProperty.value = !showRotationDragHandlesProperty.value;
},
exit: () => {
showTranslationDragHandlesProperty.value = false;
}
} );
};
translationTarget && translationTarget.addInputListener( translationOverListener );

rotationTarget.addInputListener( new SimpleDragHandler( {
const rotationListener = new SimpleDragHandler( {
start: () => {
showTranslationDragHandlesProperty.value = false;
overCountProperty.value++;
Expand Down Expand Up @@ -181,16 +184,49 @@ class LaserNode extends Node {
end: () => {
overCountProperty.value--;
}
} ) );
} );
rotationTarget.addInputListener( rotationListener );

// Listeners to enable/disable the rotation dragHandles
rotationTarget.addInputListener( {
const rotationOverListener = {
enter: () => {
overCountProperty.value++;
},
exit: () => {
overCountProperty.value--;
}
};
rotationTarget.addInputListener( rotationOverListener );

const isRotationEnabledProperty = new BooleanProperty( true, {
tandem: options.tandem.createTandem( 'isRotationEnabledProperty' )
} );
isRotationEnabledProperty.lazyLink( isEnabled => {
if ( isEnabled ) {
rotationTarget.addInputListener( rotationListener );
rotationTarget.addInputListener( rotationOverListener );
}
else {
rotationTarget.removeInputListener( rotationListener );
rotationTarget.removeInputListener( rotationOverListener );
}
if ( knobImage ) {
knobImage.visible = isEnabled;
}
} );

const isTranslationEnabledProperty = new BooleanProperty( true, {
tandem: options.tandem.createTandem( 'isTranslationEnabledProperty' )
} );
isTranslationEnabledProperty.lazyLink( isEnabled => {
if ( isEnabled ) {
translationTarget.addInputListener( translationListener );
translationTarget.addInputListener( translationOverListener );
}
else {
translationTarget.removeInputListener( translationListener );
translationTarget.removeInputListener( translationOverListener );
}
} );

// update the laser position
Expand Down
6 changes: 4 additions & 2 deletions js/prisms/PrismsScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ class PrismsScreen extends Screen {
};

super(
() => new PrismsModel(),
model => new PrismsScreenView( model ),
() => new PrismsModel( { tandem: options.tandem.createTandem( 'model' ) } ),
model => new PrismsScreenView( model, {
tandem: options.tandem.createTandem( 'view' )
} ),
options );
}
}
Expand Down

0 comments on commit f20d694

Please sign in to comment.