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.
13 #include <string_view>
17 namespace MOVING_SPEED
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
}
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
},
51 uint32_t m_resetTimeout
;
64 typedef std::map
<EventType
, EventCfg
> MapEventConfig
;
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).
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
,
86 uint32_t resetTimeout
);
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
);
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
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
));
133 EventData(EventCfg config
) : m_config
{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