kodi
GenericTouchInputHandler.h
1 /*
2  * Copyright (C) 2012-2024 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "input/touch/ITouchInputHandler.h"
12 #include "input/touch/TouchTypes.h"
13 #include "threads/CriticalSection.h"
14 #include "threads/Timer.h"
15 
16 #include <array>
17 #include <memory>
18 #include <set>
19 
21 
35 {
36 public:
41  static constexpr int MAX_POINTERS = 2;
42 
43  // implementation of ITouchInputHandler
44  bool HandleTouchInput(TouchInput event,
45  float x,
46  float y,
47  int64_t time,
48  int32_t pointer = 0,
49  float size = 0.0f) override;
50  bool UpdateTouchPointer(
51  int32_t pointer, float x, float y, int64_t time, float size = 0.0f) override;
52 
53 private:
54  // private construction, and no assignments; use the provided singleton methods
56  ~CGenericTouchInputHandler() override;
58  CGenericTouchInputHandler const& operator=(CGenericTouchInputHandler const&) = delete;
59 
60  typedef enum
61  {
62  TouchGestureUnknown = 0,
63  // only primary pointer active but stationary so far
64  TouchGestureSingleTouch,
65  // primary pointer active but stationary for a certain time
66  TouchGestureSingleTouchHold,
67  // primary pointer moving
68  TouchGesturePan,
69  // at least two pointers active but stationary so far
70  TouchGestureMultiTouchStart,
71  // at least two pointers active but stationary for a certain time
72  TouchGestureMultiTouchHold,
73  // at least two pointers active and moving
74  TouchGestureMultiTouch,
75  // all but primary pointer have been lifted
76  TouchGestureMultiTouchDone
77  } TouchGestureState;
78 
79  // implementation of ITimerCallback
80  void OnTimeout() override;
81 
82  void saveLastTouch();
83  void setGestureState(TouchGestureState gestureState)
84  {
85  m_gestureStateOld = m_gestureState;
86  m_gestureState = gestureState;
87  }
88  void triggerDetectors(TouchInput event, int32_t pointer);
89  float AdjustPointerSize(float size);
90 
91  CCriticalSection m_critical;
92  std::unique_ptr<CTimer> m_holdTimer;
93  std::array<Pointer, MAX_POINTERS> m_pointers;
94  std::set<std::unique_ptr<IGenericTouchGestureDetector>> m_detectors;
95 
96  TouchGestureState m_gestureState = TouchGestureUnknown;
97  TouchGestureState m_gestureStateOld = TouchGestureUnknown;
98 };
Interface (implements ITouchInputHandling) defining methods to handle raw touch input events (down...
Definition: ITouchInputHandler.h:38
bool UpdateTouchPointer(int32_t pointer, float x, float y, int64_t time, float size=0.0f) override
Update the coordinates of a pointer.
Definition: GenericTouchInputHandler.cpp:288
Interface defining methods to perform gesture recognition.
Definition: IGenericTouchGestureDetector.h:20
bool HandleTouchInput(TouchInput event, float x, float y, int64_t time, int32_t pointer=0, float size=0.0f) override
Handle a touch event.
Definition: GenericTouchInputHandler.cpp:49
Generic implementation of ITouchInputHandler to handle low level (raw) touch events and translate the...
Definition: GenericTouchInputHandler.h:34
static CGenericTouchInputHandler & GetInstance()
Get an instance of the touch input manager.
Definition: GenericTouchInputHandler.cpp:33
Definition: Timer.h:17
TouchInput
Touch input event.
Definition: ITouchInputHandler.h:20