| 1 |
/* |
| 2 |
* Copyright (C) 2013-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/ITouchInputHandling.h" |
| 12 |
|
| 13 |
#include <atomic> |
| 14 |
#include <stdint.h> |
| 15 |
|
| 16 |
/*! |
| 17 |
* \ingroup touch |
| 18 |
* \brief Touch input event |
| 19 |
*/ |
| 20 |
typedef enum |
| 21 |
{ |
| 22 |
TouchInputUnchanged = 0, |
| 23 |
TouchInputAbort, |
| 24 |
TouchInputDown, |
| 25 |
TouchInputUp, |
| 26 |
TouchInputMove |
| 27 |
} TouchInput; |
| 28 |
|
| 29 |
/*! |
| 30 |
* \ingroup touch |
| 31 |
* \brief Interface (implements ITouchInputHandling) defining methods to handle |
| 32 |
* raw touch input events (down, up, move). |
| 33 |
* |
| 34 |
* This interface should be implemented on platforms only supporting low level |
| 35 |
* (raw) touch input events like touch down/up/move and with no gesture |
| 36 |
* recognition logic. |
| 37 |
*/ |
| 38 |
class ITouchInputHandler : public ITouchInputHandling |
| 39 |
{ |
| 40 |
public: |
| 41 |
ITouchInputHandler() : m_dpi(160.0f) {} |
| 42 |
~ITouchInputHandler() override = default; |
| 43 |
|
| 44 |
/*! |
| 45 |
* \brief Handle a touch event |
| 46 |
* |
| 47 |
* Handles the given touch event at the given location. |
| 48 |
* This takes into account all the currently active pointers |
| 49 |
* which need to be updated before calling this method to |
| 50 |
* actually interpret and handle the changes in touch. |
| 51 |
* |
| 52 |
* \param event The actual touch event (abort, down, up, move) |
| 53 |
* \param x The x coordinate (with sub-pixel) of the touch |
| 54 |
* \param y The y coordinate (with sub-pixel) of the touch |
| 55 |
* \param time The time (in nanoseconds) when this touch occurred |
| 56 |
* \param pointer The number of the touch pointer which caused this event (default 0) |
| 57 |
* \param size The size of the touch pointer (with sub-pixel) (default 0.0) |
| 58 |
* |
| 59 |
* \return True if the event was handled otherwise false. |
| 60 |
* |
| 61 |
* \sa Update |
| 62 |
*/ |
| 63 |
virtual bool HandleTouchInput( |
| 64 |
TouchInput event, float x, float y, int64_t time, int32_t pointer = 0, float size = 0.0f) = 0; |
| 65 |
|
| 66 |
/*! |
| 67 |
* \brief Update the coordinates of a pointer |
| 68 |
* |
| 69 |
* Depending on how a platform handles touch input and provides the necessary events |
| 70 |
* this method needs to be called at different times. If there's an event for every |
| 71 |
* touch action this method does not need to be called at all. If there's only a |
| 72 |
* touch event for the primary pointer (and no special events for any secondary |
| 73 |
* pointers in a multi touch gesture) this method should be called for every active |
| 74 |
* secondary pointer before calling Handle. |
| 75 |
* |
| 76 |
* \param pointer The number of the touch pointer which caused this event (default 0) |
| 77 |
* \param x The x coordinate (with sub-pixel) of the touch |
| 78 |
* \param y The y coordinate (with sub-pixel) of the touch |
| 79 |
* \param time The time (in nanoseconds) when this touch occurred |
| 80 |
* \param size The size of the touch pointer (with sub-pixel) (default 0.0) |
| 81 |
* |
| 82 |
* \return True if the pointer was updated otherwise false. |
| 83 |
* |
| 84 |
* \sa Handle |
| 85 |
*/ |
| 86 |
virtual bool UpdateTouchPointer( |
| 87 |
int32_t pointer, float x, float y, int64_t time, float size = 0.0f) |
| 88 |
{ |
| 89 |
return false; |
| 90 |
} |
| 91 |
|
| 92 |
void SetScreenDPI(float dpi) |
| 93 |
{ |
| 94 |
if (dpi > 0.0f) |
| 95 |
m_dpi = dpi; |
| 96 |
} |
| 97 |
float GetScreenDPI() { return m_dpi; } |
| 98 |
|
| 99 |
protected: |
| 100 |
/*! |
| 101 |
* \brief DPI value of the touch screen |
| 102 |
*/ |
| 103 |
std::atomic<float> m_dpi; |
| 104 |
}; |