FreeRDP
Loading...
Searching...
No Matches
TestSDLWheel.cpp
1#include "../../SDL3/sdl_wheel.hpp"
2
3#include <iostream>
4
5/* Sends n events of `notches` each (SDL's mouse wheel y) and checks the RDP rotation they
6 * add up to. 120 is one notch ([MS-RDPBCGR] 2.2.8.1.1.3.1.1.3). */
7static bool check(const char* what, float notches, int n, INT32 expect)
8{
9 SdlWheelAxis axis;
10 INT32 sum = 0;
11 for (int i = 0; i < n; i++)
12 sum += axis.add(notches);
13 if (sum != expect)
14 {
15 std::cerr << "[TestSDLWheel] " << what << ": " << n << " x " << notches << " notches gave "
16 << sum << ", expected " << expect << std::endl;
17 return false;
18 }
19 return true;
20}
21
22int TestSDLWheel(int argc, char* argv[])
23{
24 (void)argc;
25 (void)argv;
26
27 bool ok = true;
28 /* a mouse wheel: one notch per event, nothing changes */
29 ok &= check("mouse wheel", 1.0f, 3, 360);
30 ok &= check("mouse wheel up", -1.0f, 3, -360);
31 /* a browser touchpad: SDL makes 100 pixels one notch, so 4 px is 0.04 (4.8 units) */
32 ok &= check("touchpad 4 px", 4.0f / 100.0f, 50, 240);
33 ok &= check("touchpad 4 px up", -4.0f / 100.0f, 50, -240);
34 /* half a pixel is 0.6 units: alone it is nothing, 100 of them are half a notch */
35 ok &= check("touchpad 0.5 px", 0.5f / 100.0f, 100, 60);
36 /* a high resolution wheel: an eighth of a notch per event */
37 ok &= check("high resolution wheel", 1.0f / 8.0f, 8, 120);
38 return ok ? 0 : 1;
39}