//
// PointerEvent.cpp
// script-engine/src
//
// Created by Anthony Thibault on 2016-8-11.
// Copyright 2016 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "PointerEvent.h"
#include "RegisteredMetaTypes.h"
#include "ScriptEngine.h"
#include "ScriptValue.h"
#include "ScriptValueUtils.h"
static bool areFlagsSet(uint32_t flags, uint32_t mask) {
return (flags & mask) != 0;
}
PointerEvent::PointerEvent(EventType type, uint32_t id) :
_type(type),
_id(id)
{
}
PointerEvent::PointerEvent(EventType type, uint32_t id, const glm::vec2& pos2D, Button button, uint32_t buttons, Qt::KeyboardModifiers keyboardModifiers) :
_type(type),
_id(id),
_pos2D(pos2D),
_button(button),
_buttons(buttons),
_keyboardModifiers(keyboardModifiers)
{
}
PointerEvent::PointerEvent(const glm::vec2& pos2D, const glm::vec3& pos3D, const glm::vec3& normal, const glm::vec3& direction) :
_pos2D(pos2D),
_pos3D(pos3D),
_normal(normal),
_direction(direction)
{
}
PointerEvent::PointerEvent(EventType type, uint32_t id,
const glm::vec2& pos2D, const glm::vec3& pos3D,
const glm::vec3& normal, const glm::vec3& direction,
Button button, uint32_t buttons, Qt::KeyboardModifiers keyboardModifiers) :
_type(type),
_id(id),
_pos2D(pos2D),
_pos3D(pos3D),
_normal(normal),
_direction(direction),
_button(button),
_buttons(buttons),
_keyboardModifiers(keyboardModifiers)
{
}
void PointerEvent::setButton(Button button) {
_button = button;
_buttons |= button;
}
/*@jsdoc
* A 2D or 3D mouse or similar pointer event.
* @typedef {object} PointerEvent
* @property {string} type - The type of event: "Press"
, "DoublePress"
, "Release"
, or
* "Move"
.
* @property {number} id - Integer number used to identify the pointer: 0
= hardware mouse, 1
= left
* controller, 2
= right controller.
* @property {Vec2} pos2D - The 2D position of the event on the intersected object XY plane, where applicable.
* @property {Vec3} pos3D - The 3D position of the event on the intersected object, where applicable.
* @property {Vec3} normal - The surface normal at the intersection point.
* @property {Vec3} direction - The direction of the intersection ray.
* @property {string} button - The name of the button pressed: None
, Primary
, Secondary
,
* or Tertiary
.
* @property {boolean} isPrimaryButton - true
if the button pressed was the primary button, otherwise
* undefined
;
* @property {boolean} isLeftButton - true
if the button pressed was the primary button, otherwise
* undefined
;
* @property {boolean} isSecondaryButton - true
if the button pressed was the secondary button, otherwise
* undefined
;
* @property {boolean} isRightButton - true
if the button pressed was the secondary button, otherwise
* undefined
;
* @property {boolean} isTertiaryButton - true
if the button pressed was the tertiary button, otherwise
* undefined
;
* @property {boolean} isMiddleButton - true
if the button pressed was the tertiary button, otherwise
* undefined
;
* @property {boolean} isPrimaryHeld - true
if the primary button is currently being pressed, otherwise
* false
* @property {boolean} isSecondaryHeld - true
if the secondary button is currently being pressed, otherwise
* false
* @property {boolean} isTertiaryHeld - true
if the tertiary button is currently being pressed, otherwise
* false
* @property {KeyboardModifiers} keyboardModifiers - Integer value with bits set according to which keyboard modifier keys were
* pressed when the event was generated.
*/
/*@jsdoc
*
A KeyboardModifiers value is used to specify which modifier keys on the keyboard are pressed. The value is the sum * (bitwise OR) of the relevant combination of values from the following table:
*Key | Hexadecimal value | Decimal value | Description |
---|---|---|---|
Shift | 0x02000000 | 33554432 |
* A Shift key on the keyboard is pressed. |
Control | 0x04000000 | 67108864 |
* A control key on the keyboard is pressed. On Windows the "control" key is the Ctrl key; on OSX it is the Command * key. |
Alt | 0x08000000 | 134217728 |
* An Alt key on the keyboard is pressed. |
Meta | 0x10000000 | 268435456 |
* A meta key on the keyboard is pressed. On Windows the "meta" key is the Windows key; on OSX it is the Control * (Splat) key. |
Keypad | 0x20000000 | 536870912 |
* A keypad button is pressed. |
Group | 0x40000000 | 1073741824 |
* X11 operating system only: An AltGr / Mode_switch key on the keyboard is pressed. |