setMouseAction method
Set a new mouse action by specifying the operation to be performed and a mouse/key combination. In case of conflict, replaces the existing one @param {String} operation The operation to be performed ('PAN', 'ROTATE', 'ZOOM', 'FOV) @param {} mouse A mouse button (0, 1, 2) or 'WHEEL' for wheel notches @param {} key The keyboard modifier ('CTRL', 'SHIFT') or null if key is not needed @returns {Boolean} True if the mouse action has been successfully added, false otherwise
Implementation
setMouseAction(String operation, mouse, [String? key]) {
var operationInput = ['PAN', 'ROTATE', 'ZOOM', 'FOV'];
var mouseInput = ['0', '1', '2', 'WHEEL'];
var keyInput = ['CTRL', 'SHIFT', null];
var state;
if (!operationInput.contains(operation) || !mouseInput.contains(mouse.toString()) || !keyInput.contains(key)) {
//invalid parameters
return false;
}
if (mouse == 'WHEEL') {
if (operation != 'ZOOM' && operation != 'FOV') {
//cannot associate 2D operation to 1D input
return false;
}
}
switch (operation) {
case 'PAN':
state = State2.pan;
break;
case 'ROTATE':
state = State2.rotate;
break;
case 'ZOOM':
state = State2.scale;
break;
case 'FOV':
state = State2.fov;
break;
}
var action = {'operation': operation, 'mouse': mouse, 'key': key, 'state': state};
for (var i = 0; i < mouseActions.length; i++) {
if (mouseActions[i]['mouse'] == action['mouse'] && mouseActions[i]['key'] == action['key']) {
mouseActions.splice(i, 1, action);
return true;
}
}
mouseActions.add(action);
return true;
}