From 6cd444f0fab9f7af501e76705b3dd77a4bbea10a Mon Sep 17 00:00:00 2001
From: Christoph Reichenbach <[EMAIL REDACTED]>
Date: Sat, 2 Apr 2022 21:28:56 +0000
Subject: [PATCH] Visualise scroll wheel events in testmouse
---
test/testmouse.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/test/testmouse.c b/test/testmouse.c
index c73adca512c..11a17606644 100644
--- a/test/testmouse.c
+++ b/test/testmouse.c
@@ -39,6 +39,11 @@ static Line *active = NULL;
static Line *lines = NULL;
static int buttons = 0;
+static SDL_bool wheel_x_active = SDL_FALSE;
+static SDL_bool wheel_y_active = SDL_FALSE;
+static float wheel_x = SCREEN_WIDTH * 0.5f;
+static float wheel_y = SCREEN_HEIGHT * 0.5f;
+
static SDL_bool done = SDL_FALSE;
void
@@ -81,6 +86,25 @@ loop(void *arg)
/* Check for events */
while (SDL_PollEvent(&event)) {
switch (event.type) {
+ case SDL_MOUSEWHEEL:
+ if (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED) {
+ event.wheel.preciseX *= -1.0f;
+ event.wheel.preciseY *= -1.0f;
+ event.wheel.x *= -1;
+ event.wheel.y *= -1;
+ }
+ if (event.wheel.preciseX != 0.0f) {
+ wheel_x_active = SDL_TRUE;
+ /* "positive to the right and negative to the left" */
+ wheel_x += event.wheel.preciseX * 10.0f;
+ }
+ if (event.wheel.preciseY != 0.0f) {
+ wheel_y_active = SDL_TRUE;
+ /* "positive away from the user and negative towards the user" */
+ wheel_y -= event.wheel.preciseY * 10.0f;
+ }
+ break;
+
case SDL_MOUSEMOTION:
if (!active)
break;
@@ -134,6 +158,16 @@ loop(void *arg)
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
+ /* Mouse wheel */
+ SDL_SetRenderDrawColor(renderer, 0, 255, 128, 255);
+ if (wheel_x_active) {
+ SDL_RenderDrawLine(renderer, wheel_x, 0, wheel_x, SCREEN_HEIGHT);
+ }
+ if (wheel_y_active) {
+ SDL_RenderDrawLine(renderer, 0, wheel_y, SCREEN_WIDTH, wheel_y);
+ }
+
+ /* Lines from mouse clicks */
DrawLines(renderer);
if (active)
DrawLine(renderer, active);