setMouseAction method

dynamic setMouseAction(
  1. dynamic operation,
  2. dynamic mouse, [
  3. dynamic key = null
])
  • 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(operation, mouse, [key = null]) {
  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 < this.mouseActions.length; i++) {
    if (this.mouseActions[i]['mouse'] == action['mouse'] &&
        this.mouseActions[i]['key'] == action['key']) {
      this.mouseActions.splice(i, 1, action);
      return true;
    }
  }

  this.mouseActions.add(action);
  return true;
}