-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a listener that speaks name and hint response upon activation, see …
- Loading branch information
1 parent
1ca73e3
commit ef612ce
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
js/accessibility/voicing/VoicingActivationResponseListener.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters