//
// MouseEvent.cpp
// script-engine/src
//
// Created by Stephen Birarda on 2014-10-27.
// Copyright 2014 High Fidelity, Inc.
// Copyright 2023 Overte e.V.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// SPDX-License-Identifier: Apache-2.0
//
#include "MouseEvent.h"
#include "ScriptEngine.h"
#include "ScriptValue.h"
MouseEvent::MouseEvent() :
x(0.0f),
y(0.0f),
isLeftButton(false),
isRightButton(false),
isMiddleButton(false),
isShifted(false),
isControl(false),
isMeta(false),
isAlt(false)
{
}
MouseEvent::MouseEvent(const QMouseEvent& event) :
x(event.x()),
y(event.y()),
isLeftButton(event.buttons().testFlag(Qt::LeftButton)),
isRightButton(event.buttons().testFlag(Qt::RightButton)),
isMiddleButton(event.buttons().testFlag(Qt::MiddleButton)),
isShifted(event.modifiers().testFlag(Qt::ShiftModifier)),
isControl(event.modifiers().testFlag(Qt::ControlModifier)),
isMeta(event.modifiers().testFlag(Qt::MetaModifier)),
isAlt(event.modifiers().testFlag(Qt::AltModifier))
{
// single button that caused the event
switch (event.button()) {
case Qt::LeftButton:
button = "LEFT";
isLeftButton = true;
break;
case Qt::RightButton:
button = "RIGHT";
isRightButton = true;
break;
case Qt::MiddleButton:
button = "MIDDLE";
isMiddleButton = true;
break;
default:
button = "NONE";
break;
}
}
/*@jsdoc
* A controller mouse movement or button event.
* @typedef {object} MouseEvent
* @property {number} x - Integer x-coordinate of the event on the Interface window or HMD HUD.
* @property {number} y - Integer y-coordinate of the event on the Interface window or HMD HUD.
* @property {string} button - "LEFT"
, "MIDDLE"
, or "RIGHT"
if a button press or release
* caused the event, otherwise "NONE"
.
* @property {boolean} isLeftButton - true
if the left button was pressed when the event was generated, otherwise
* false
.
* @property {boolean} isMiddleButton - true
if the middle button was pressed when the event was generated,
* otherwise false
.
* @property {boolean} isRightButton - true
if the right button was pressed when the event was generated,
* otherwise false
.
* @property {boolean} isShifted - true
if the Shift key was pressed when the event was generated, otherwise
* false
.
* @property {boolean} isMeta - true
if the "meta" key was pressed when the event was generated, otherwise
* false
. On Windows the "meta" key is the Windows key; on OSX it is the Control (Splat) key.
* @property {boolean} isControl - true
if the "control" key was pressed when the event was generated, otherwise
* false
. On Windows the "control" key is the Ctrl key; on OSX it is the Command key.
* @property {boolean} isAlt - true
if the Alt key was pressed when the event was generated, otherwise
* false
.
* @example