[PVR][Estuary] Timer settings dialog: Show client name in timer type selection dialog...
[xbmc.git] / xbmc / utils / MovingSpeed.h
blob70214a6671d7e2e66930db0a339978dd4446ab24
1 /*
2 * Copyright (C) 2022 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #pragma once
11 #include <map>
12 #include <stdint.h>
13 #include <string_view>
15 namespace UTILS
17 namespace MOVING_SPEED
20 struct EventCfg
22 /*!
23 * \param acceleration Acceleration in pixels per second (px/sec)
24 * \param maxVelocity Max movement speed, it depends from acceleration value,
25 * a suitable value could be (acceleration value)*3. Set 0 to disable it
26 * \param resetTimeout Resets acceleration speed if idle for specified millisecs
28 EventCfg(float acceleration, float maxVelocity, uint32_t resetTimeout)
29 : m_acceleration{acceleration}, m_maxVelocity{maxVelocity}, m_resetTimeout{resetTimeout}
33 /*!
34 * \param acceleration Acceleration in pixels per second (px/sec)
35 * \param maxVelocity Max movement speed, it depends from acceleration value,
36 * a suitable value could be (acceleration value)*3. Set 0 to disable it
37 * \param resetTimeout Resets acceleration speed if idle for specified millisecs
38 * \param delta Specify the minimal increment step, and the result of distance
39 value will be rounded by delta. Set 0 to disable it
41 EventCfg(float acceleration, float maxVelocity, uint32_t resetTimeout, float delta)
42 : m_acceleration{acceleration},
43 m_maxVelocity{maxVelocity},
44 m_resetTimeout{resetTimeout},
45 m_delta{delta}
49 float m_acceleration;
50 float m_maxVelocity;
51 uint32_t m_resetTimeout;
52 float m_delta{0};
55 enum class EventType
57 NONE = 0,
58 UP,
59 DOWN,
60 LEFT,
61 RIGHT
64 typedef std::map<EventType, EventCfg> MapEventConfig;
66 /*!
67 * \brief Class to calculate the velocity for a motion effect.
68 * To ensure it works, the GetUpdatedDistance method must be called at each
69 * input received (e.g. continuous key press of same key on the keyboard).
70 * The motion effect will stop at the event ID change (different key pressed).
72 class CMovingSpeed
74 public:
75 /*!
76 * \brief Add the configuration for an event
77 * \param eventId The id for the event, must be unique
78 * \param acceleration Acceleration in pixels per second (px/sec)
79 * \param maxVelocity Max movement speed, it depends from acceleration value,
80 * a suitable value could be (acceleration value)*3. Set 0 to disable it
81 * \param resetTimeout Resets acceleration speed if idle for specified millisecs
83 void AddEventConfig(uint32_t eventId,
84 float acceleration,
85 float maxVelocity,
86 uint32_t resetTimeout);
88 /*!
89 * \brief Add the configuration for an event
90 * \param eventId The id for the event, must be unique
91 * \param event The event configuration
93 void AddEventConfig(uint32_t eventId, EventCfg event);
95 /*!
96 * \brief Add a map of events configuration
97 * \param configs The map of events configuration where key value is event id,
99 void AddEventMapConfig(MapEventConfig& configs);
102 * \brief Reset stored velocity to all events
103 * \param event The event configuration
105 void Reset();
108 * \brief Reset stored velocity for a specific event
109 * \param event The event ID
111 void Reset(uint32_t eventId);
114 * \brief Get the updated distance based on acceleration speed
115 * \param eventId The id for the event to handle
116 * \return The distance
118 float GetUpdatedDistance(uint32_t eventId);
121 * \brief Get the updated distance based on acceleration speed
122 * \param eventType The event type to handle
123 * \return The distance
125 float GetUpdatedDistance(EventType eventType)
127 return GetUpdatedDistance(static_cast<uint32_t>(eventType));
130 private:
131 struct EventData
133 EventData(EventCfg config) : m_config{config} {}
135 EventCfg m_config;
136 float m_currentVelocity{1.0f};
137 uint32_t m_lastFrameTime{0};
140 uint32_t m_currentEventId{0};
141 std::map<uint32_t, EventData> m_eventsData;
145 * \brief Parse a string event type to enum EventType.
146 * \param eventType The event type as string
147 * \return The EventType if has success, otherwise EventType::NONE
149 EventType ParseEventType(std::string_view eventType);
151 } // namespace MOVING_SPEED
152 } // namespace UTILS