Showing the changes to interface/src/scripting/ControllerScriptingInterface.h (1 of 44 files). Show all
Unified · Split
| @@ -0,0 +1,99 @@ | ||
| 1 | + | |
| 2 | +// | |
| 3 | +// ControllerScriptingInterface.h | |
| 4 | +// hifi | |
| 5 | +// | |
| 6 | +// Created by Brad Hefta-Gaub on 12/17/13 | |
| 7 | +// Copyright (c) 2013 HighFidelity, Inc. All rights reserved. | |
| 8 | +// | |
| 9 | + | |
| 10 | +#ifndef __hifi__ControllerScriptingInterface__ | |
| 11 | +#define __hifi__ControllerScriptingInterface__ | |
| 12 | + | |
| 13 | +#include <QtCore/QObject> | |
| 14 | + | |
| 15 | +#include <AbstractControllerScriptingInterface.h> | |
| 16 | +class PalmData; | |
| 17 | + | |
| 18 | +/// handles scripting of input controller commands from JS | |
| 19 | +class ControllerScriptingInterface : public AbstractControllerScriptingInterface { | |
| 20 | + Q_OBJECT | |
| 21 | + | |
| 22 | +public: | |
| 23 | + ControllerScriptingInterface(); | |
| 24 | + void emitKeyPressEvent(QKeyEvent* event) { emit keyPressEvent(KeyEvent(*event)); } | |
| 25 | + void emitKeyReleaseEvent(QKeyEvent* event) { emit keyReleaseEvent(KeyEvent(*event)); } | |
| 26 | + | |
| 27 | + void emitMouseMoveEvent(QMouseEvent* event) { emit mouseMoveEvent(MouseEvent(*event)); } | |
| 28 | + void emitMousePressEvent(QMouseEvent* event) { emit mousePressEvent(MouseEvent(*event)); } | |
| 29 | + void emitMouseReleaseEvent(QMouseEvent* event) { emit mouseReleaseEvent(MouseEvent(*event)); } | |
| 30 | + | |
| 31 | + void emitTouchBeginEvent(const TouchEvent& event) { emit touchBeginEvent(event); } | |
| 32 | + void emitTouchEndEvent(const TouchEvent& event) { emit touchEndEvent(event); } | |
| 33 | + void emitTouchUpdateEvent(const TouchEvent& event) { emit touchUpdateEvent(event); } | |
| 34 | + | |
| 35 | + void emitWheelEvent(QWheelEvent* event) { emit wheelEvent(*event); } | |
| 36 | + | |
| 37 | + bool isKeyCaptured(QKeyEvent* event) const; | |
| 38 | + bool isKeyCaptured(const KeyEvent& event) const; | |
| 39 | + bool isMouseCaptured() const { return _mouseCaptured; } | |
| 40 | + bool isTouchCaptured() const { return _touchCaptured; } | |
| 41 | + bool isWheelCaptured() const { return _wheelCaptured; } | |
| 42 | + bool isJoystickCaptured(int joystickIndex) const; | |
| 43 | + | |
| 44 | +public slots: | |
| 45 | + virtual bool isPrimaryButtonPressed() const; | |
| 46 | + virtual glm::vec2 getPrimaryJoystickPosition() const; | |
| 47 | + | |
| 48 | + virtual int getNumberOfButtons() const; | |
| 49 | + virtual bool isButtonPressed(int buttonIndex) const; | |
| 50 | + | |
| 51 | + virtual int getNumberOfTriggers() const; | |
| 52 | + virtual float getTriggerValue(int triggerIndex) const; | |
| 53 | + | |
| 54 | + virtual int getNumberOfJoysticks() const; | |
| 55 | + virtual glm::vec2 getJoystickPosition(int joystickIndex) const; | |
| 56 | + | |
| 57 | + virtual int getNumberOfSpatialControls() const; | |
| 58 | + virtual glm::vec3 getSpatialControlPosition(int controlIndex) const; | |
| 59 | + virtual glm::vec3 getSpatialControlVelocity(int controlIndex) const; | |
| 60 | + virtual glm::vec3 getSpatialControlNormal(int controlIndex) const; | |
| 61 | + virtual glm::quat getSpatialControlRawRotation(int controlIndex) const; | |
| 62 | + virtual void captureKeyEvents(const KeyEvent& event); | |
| 63 | + virtual void releaseKeyEvents(const KeyEvent& event); | |
| 64 | + | |
| 65 | + virtual void captureMouseEvents() { _mouseCaptured = true; } | |
| 66 | + virtual void releaseMouseEvents() { _mouseCaptured = false; } | |
| 67 | + | |
| 68 | + virtual void captureTouchEvents() { _touchCaptured = true; } | |
| 69 | + virtual void releaseTouchEvents() { _touchCaptured = false; } | |
| 70 | + | |
| 71 | + virtual void captureWheelEvents() { _wheelCaptured = true; } | |
| 72 | + virtual void releaseWheelEvents() { _wheelCaptured = false; } | |
| 73 | + | |
| 74 | + virtual void captureJoystick(int joystickIndex); | |
| 75 | + virtual void releaseJoystick(int joystickIndex); | |
| 76 | + | |
| 77 | + virtual glm::vec2 getViewportDimensions() const; | |
| 78 | + | |
| 79 | +private: | |
| 80 | + const PalmData* getPrimaryPalm() const; | |
| 81 | + const PalmData* getPalm(int palmIndex) const; | |
| 82 | + int getNumberOfActivePalms() const; | |
| 83 | + const PalmData* getActivePalm(int palmIndex) const; | |
| 84 | + | |
| 85 | + bool _mouseCaptured; | |
| 86 | + bool _touchCaptured; | |
| 87 | + bool _wheelCaptured; | |
| 88 | + QMultiMap<int,KeyEvent> _capturedKeys; | |
| 89 | + QSet<int> _capturedJoysticks; | |
| 90 | +}; | |
| 91 | + | |
| 92 | +const int NUMBER_OF_SPATIALCONTROLS_PER_PALM = 2; // the hand and the tip | |
| 93 | +const int NUMBER_OF_JOYSTICKS_PER_PALM = 1; | |
| 94 | +const int NUMBER_OF_TRIGGERS_PER_PALM = 1; | |
| 95 | +const int NUMBER_OF_BUTTONS_PER_PALM = 6; | |
| 96 | +const int PALM_SPATIALCONTROL = 0; | |
| 97 | +const int TIP_SPATIALCONTROL = 1; | |
| 98 | + | |
| 99 | +#endif /* defined(__hifi__ControllerScriptingInterface__) */ | |