NGL@0.10.4 Home Manual Reference Source GalleryRepository
import MouseControls from 'ngl/src/controls/mouse-controls.js'
public class | source

MouseControls

Mouse controls

Constructor Summary

Public Constructor
public

constructor(stage: Stage, params: Object)

Method Summary

Public Methods
public

add(triggerStr: TriggerString, callback: function(stage: Stage, ...args: Any)): undefined

Add a new mouse action triggered by an event, key and button combination.

public

Remove all mouse actions

public

Set mouse action preset

public

remove(triggerStr: TriggerString, callback: Function): undefined

Remove a mouse action.

Public Constructors

public constructor(stage: Stage, params: Object) source

Params:

NameTypeAttributeDescription
stage Stage

the stage object

params Object
  • optional

the parameters

params.preset String

one of "default", "pymol", "coot"

Public Methods

public add(triggerStr: TriggerString, callback: function(stage: Stage, ...args: Any)): undefined source

Add a new mouse action triggered by an event, key and button combination. The MouseActions class provides a number of static methods for use as callback functions.

Params:

NameTypeAttributeDescription
triggerStr TriggerString

the trigger for the action

callback function(stage: Stage, ...args: Any)

the callback function for the action

Return:

undefined

Example:

// change ambient light intensity on mouse scroll
// while the ctrl and shift keys are pressed
stage.mouseControls.add( "scroll-ctrl+shift", function( stage, delta ){
    var ai = stage.getParameters().ambientIntensity;
    stage.setParameters( { ambientIntensity: Math.max( 0, ai + delta / 50 ) } );
} );
// Call the MouseActions.zoomDrag method on mouse drag events
// with left and right mouse buttons simultaneous
stage.mouseControls.add( "drag-left+right", MouseActions.zoomDrag );

public clear(): undefined source

Remove all mouse actions

Return:

undefined

public preset(name: String): undefined source

Set mouse action preset

Params:

NameTypeAttributeDescription
name String

one of "default", "pymol", "coot"

Return:

undefined

public remove(triggerStr: TriggerString, callback: Function): undefined source

Remove a mouse action. The trigger string can contain an asterix (*) as a wildcard for any key or mouse button. When the callback function is given, only actions that call that function are removed.

Params:

NameTypeAttributeDescription
triggerStr TriggerString

the trigger for the action

callback Function
  • optional

the callback function for the action

Return:

undefined

Example:

// remove actions triggered solely by a scroll event
stage.mouseControls.remove( "scroll" );
// remove actions triggered by a scroll event, including
// those requiring a key pressed or mouse button used
stage.mouseControls.remove( "scroll-*" );
// remove actions triggered by a scroll event
// while the shift key is pressed
stage.mouseControls.remove( "scroll-shift" );