FreeRDP
Loading...
Searching...
No Matches
sdl_wheel.hpp
1
19
20#pragma once
21
22#include <cmath>
23#include <cstdint>
24
25#include <winpr/wtypes.h>
26
27/* One wheel axis in RDP rotation units, 120 to a notch ([MS-RDPBCGR] 2.2.8.1.1.3.1.1.3).
28 * SDL reports fractions of a notch: a touchpad, a high resolution wheel, a browser's pixel
29 * deltas (SDL's Emscripten backend makes 100 pixels one notch, so 4 px is 4.8 units).
30 * Converting each event alone drops its fraction, and an event of less than one unit is
31 * lost entirely, so the rest is carried to the next event. It is kept in thousandths of a
32 * unit: whole numbers add up exactly where 50 x 0.04f x 120 in floats is 239.99. */
34{
35 public:
36 [[nodiscard]] INT32 add(float notches)
37 {
38 _milli += std::llround(static_cast<double>(notches) * 120.0 * 1000.0);
39 const int64_t units = _milli / 1000; /* toward zero; the rest keeps its sign */
40 _milli -= units * 1000;
41 return static_cast<INT32>(units);
42 }
43
44 private:
45 int64_t _milli = 0;
46};