Overte C++ Documentation
TouchscreenDevice.h
1 //
2 // TouchscreenDevice.h
3 // input-plugins/src/input-plugins
4 //
5 // Created by Triplelexx on 1/31/16.
6 // Copyright 2016 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef hifi_TouchscreenDevice_h
13 #define hifi_TouchscreenDevice_h
14 
15 #include <controllers/InputDevice.h>
16 #include "InputPlugin.h"
17 #include <QtGui/qtouchdevice.h>
18 
19 class QTouchEvent;
20 class QGestureEvent;
21 
22 class TouchscreenDevice : public InputPlugin {
23  Q_OBJECT
24 public:
25 
26  enum TouchAxisChannel {
27  TOUCH_AXIS_X_POS = 0,
28  TOUCH_AXIS_X_NEG,
29  TOUCH_AXIS_Y_POS,
30  TOUCH_AXIS_Y_NEG,
31  };
32 
33  enum TouchGestureAxisChannel {
34  TOUCH_GESTURE_PINCH_POS = TOUCH_AXIS_Y_NEG + 1,
35  TOUCH_GESTURE_PINCH_NEG,
36  };
37 
38  // Plugin functions
39  virtual bool isSupported() const override;
40  virtual const QString getName() const override { return NAME; }
41 
42  virtual void pluginFocusOutEvent() override { _inputDevice->focusOutEvent(); }
43  virtual void pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) override;
44 
45  void touchBeginEvent(const QTouchEvent* event);
46  void touchEndEvent(const QTouchEvent* event);
47  void touchUpdateEvent(const QTouchEvent* event);
48  void touchGestureEvent(const QGestureEvent* event);
49 
50  static const char* NAME;
51 
52 protected:
53 
54  class InputDevice : public controller::InputDevice {
55  public:
56  InputDevice() : controller::InputDevice("Touchscreen") {}
57  private:
58  // Device functions
59  virtual controller::Input::NamedVector getAvailableInputs() const override;
60  virtual QString getDefaultMappingConfig() const override;
61  virtual void update(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) override;
62  virtual void focusOutEvent() override;
63 
64  controller::Input makeInput(TouchAxisChannel axis) const;
65  controller::Input makeInput(TouchGestureAxisChannel gesture) const;
66 
67  friend class TouchscreenDevice;
68  };
69 
70 public:
71  const std::shared_ptr<InputDevice>& getInputDevice() const { return _inputDevice; }
72 
73 protected:
74  qreal _lastPinchScale;
75  qreal _pinchScale;
76  qreal _screenDPI;
77  glm::vec2 _screenDPIScale;
78  glm::vec2 _firstTouchVec;
79  glm::vec2 _currentTouchVec;
80  int _touchPointCount;
81  std::shared_ptr<InputDevice> _inputDevice { std::make_shared<InputDevice>() };
82 };
83 
84 #endif // hifi_TouchscreenDevice_h