Skip to content

Commit

Permalink
add a listener that speaks name and hint response upon activation, see
Browse files Browse the repository at this point in the history
  • Loading branch information
jessegreenberg committed Jan 8, 2025
1 parent 1ca73e3 commit ef612ce
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
49 changes: 49 additions & 0 deletions js/accessibility/voicing/VoicingActivationResponseListener.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2024, University of Colorado Boulder

/**
* A PressListener that speaks the name and hint responses of a VoicingNode when it is clicked. If there
* is movement of the pressed mouse, the voicing response is interrupted.
*
* @author Jesse Greenberg (PhET Interactive Simulations)
*/

import Vector2 from '../../../../dot/js/Vector2.js';
import { PressListener, scenery, VoicingNode } from '../../../js/imports.js';

// If the mouse moves this much in the global coordinate frame, we consider it a drag event and the voicing response
// behavior is interrupted.
const GLOBAL_DELTA = 1;

export default class VoicingActivationResponseListener extends PressListener {
public constructor( voicingNode: VoicingNode ) {

let startPosition: Vector2 | null = null;

super( {

// This listener should not attach to the Pointer and should not interfere with other listeners.
attach: false,
press: event => {
startPosition = event.pointer.point;
},
drag: event => {

if ( event && startPosition && startPosition.distance( event.pointer.point ) > GLOBAL_DELTA ) {
this.interrupt();
}
},
release: event => {

// If there is a change in position, speak the name and hint of the voicing node.
if ( event && !this.interrupted ) {
voicingNode.voicingSpeakResponse( {
nameResponse: voicingNode.voicingNameResponse,
hintResponse: voicingNode.voicingHintResponse
} );
}
}
} );
}
}

scenery.register( 'VoicingActivationResponseListener', VoicingActivationResponseListener );
1 change: 1 addition & 0 deletions js/imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ export { default as VoicingText } from './accessibility/voicing/nodes/VoicingTex
export type { VoicingTextOptions } from './accessibility/voicing/nodes/VoicingText.js';
export { default as VoicingRichText } from './accessibility/voicing/nodes/VoicingRichText.js';
export type { VoicingRichTextOptions } from './accessibility/voicing/nodes/VoicingRichText.js';
export { default as VoicingActivationResponseListener } from './accessibility/voicing/VoicingActivationResponseListener.js';

export { default as scenerySerialize, serializeConnectedNodes } from './util/scenerySerialize.js';
export { default as sceneryDeserialize } from './util/sceneryDeserialize.js';
Expand Down

0 comments on commit ef612ce

Please sign in to comment.