[Commits] SDL: Added hints SDL_HINT_MOUSE_DOUBLE_CLICK_TIME and SDL_HINT_...

libsdl.org revision control commits-owner at libsdl.org
Fri Sep 14 19:27:45 PDT 2018


details:   https://hg.libsdl.org/SDL/rev/f081a5675f93
changeset: 12188:f081a5675f93
user:      Sam Lantinga <slouken at libsdl.org>
date:      Fri Sep 14 19:26:26 2018 -0700
description:
Added hints  SDL_HINT_MOUSE_DOUBLE_CLICK_TIME and SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS to allow tuning double-click sensitivity.
Also increased the default double-click radius to 32 pixels to be more forgiving for touch interfaces

diffstat:

 include/SDL_hints.h                  |  10 +++++++
 src/events/SDL_mouse.c               |  48 +++++++++++++++++++++++++++--------
 src/events/SDL_mouse_c.h             |   5 +--
 src/video/windows/SDL_windowsmouse.c |   2 -
 4 files changed, 49 insertions(+), 16 deletions(-)

diffs (138 lines):

diff -r e755760381d8 -r f081a5675f93 include/SDL_hints.h
--- a/include/SDL_hints.h	Fri Sep 14 18:31:03 2018 -0700
+++ b/include/SDL_hints.h	Fri Sep 14 19:26:26 2018 -0700
@@ -263,6 +263,16 @@
 #define SDL_HINT_GRAB_KEYBOARD              "SDL_GRAB_KEYBOARD"
 
 /**
+ *  \brief  A variable setting the double click time, in milliseconds.
+ */
+#define SDL_HINT_MOUSE_DOUBLE_CLICK_TIME    "SDL_MOUSE_DOUBLE_CLICK_TIME"
+
+/**
+ *  \brief  A variable setting the double click radius, in pixels.
+ */
+#define SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS    "SDL_MOUSE_DOUBLE_CLICK_RADIUS"
+
+/**
  *  \brief  A variable setting the speed scale for mouse motion, in floating point, when the mouse is not in relative mode
  */
 #define SDL_HINT_MOUSE_NORMAL_SPEED_SCALE    "SDL_MOUSE_NORMAL_SPEED_SCALE"
diff -r e755760381d8 -r f081a5675f93 src/events/SDL_mouse.c
--- a/src/events/SDL_mouse.c	Fri Sep 14 18:31:03 2018 -0700
+++ b/src/events/SDL_mouse.c	Fri Sep 14 19:26:26 2018 -0700
@@ -33,13 +33,39 @@
 
 /* The mouse state */
 static SDL_Mouse SDL_mouse;
-static Uint32 SDL_double_click_time = 500;
-static int SDL_double_click_radius = 1;
 
 static int
 SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int x, int y);
 
 static void SDLCALL
+SDL_MouseDoubleClickTimeChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
+{
+    SDL_Mouse *mouse = (SDL_Mouse *)userdata;
+
+    if (hint && *hint) {
+        mouse->double_click_time = SDL_atoi(hint);
+    } else {
+#ifdef __WIN32__
+        mouse->double_click_time = GetDoubleClickTime();
+#else
+        mouse->double_click_time = 500;
+#endif
+    }
+}
+
+static void SDLCALL
+SDL_MouseDoubleClickRadiusChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
+{
+    SDL_Mouse *mouse = (SDL_Mouse *)userdata;
+
+    if (hint && *hint) {
+        mouse->double_click_radius = SDL_atoi(hint);
+    } else {
+        mouse->double_click_radius = 32;    /* 32 pixels seems about right for touch interfaces */
+    }
+}
+
+static void SDLCALL
 SDL_MouseNormalSpeedScaleChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
 {
     SDL_Mouse *mouse = (SDL_Mouse *)userdata;
@@ -83,6 +109,12 @@
 
     SDL_zerop(mouse);
 
+    SDL_AddHintCallback(SDL_HINT_MOUSE_DOUBLE_CLICK_TIME,
+                        SDL_MouseDoubleClickTimeChanged, mouse);
+
+    SDL_AddHintCallback(SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS,
+                        SDL_MouseDoubleClickRadiusChanged, mouse);
+
     SDL_AddHintCallback(SDL_HINT_MOUSE_NORMAL_SPEED_SCALE,
                         SDL_MouseNormalSpeedScaleChanged, mouse);
 
@@ -114,12 +146,6 @@
     return &SDL_mouse;
 }
 
-void
-SDL_SetDoubleClickTime(Uint32 interval)
-{
-    SDL_double_click_time = interval;
-}
-
 SDL_Window *
 SDL_GetMouseFocus(void)
 {
@@ -454,9 +480,9 @@
             if (state == SDL_PRESSED) {
                 Uint32 now = SDL_GetTicks();
 
-                if (SDL_TICKS_PASSED(now, clickstate->last_timestamp + SDL_double_click_time) ||
-                    SDL_abs(mouse->x - clickstate->last_x) > SDL_double_click_radius ||
-                    SDL_abs(mouse->y - clickstate->last_y) > SDL_double_click_radius) {
+                if (SDL_TICKS_PASSED(now, clickstate->last_timestamp + mouse->double_click_time) ||
+                    SDL_abs(mouse->x - clickstate->last_x) > mouse->double_click_radius ||
+                    SDL_abs(mouse->y - clickstate->last_y) > mouse->double_click_radius) {
                     clickstate->click_count = 0;
                 }
                 clickstate->last_timestamp = now;
diff -r e755760381d8 -r f081a5675f93 src/events/SDL_mouse_c.h
--- a/src/events/SDL_mouse_c.h	Fri Sep 14 18:31:03 2018 -0700
+++ b/src/events/SDL_mouse_c.h	Fri Sep 14 19:26:26 2018 -0700
@@ -90,6 +90,8 @@
     float relative_speed_scale;
     float scale_accum_x;
     float scale_accum_y;
+    Uint32 double_click_time;
+    int double_click_radius;
     SDL_bool touch_mouse_events;
 
     /* Data for double-click tracking */
@@ -112,9 +114,6 @@
 /* Get the mouse state structure */
 SDL_Mouse *SDL_GetMouse(void);
 
-/* Set the default double-click interval */
-extern void SDL_SetDoubleClickTime(Uint32 interval);
-
 /* Set the default mouse cursor */
 extern void SDL_SetDefaultCursor(SDL_Cursor * cursor);
 
diff -r e755760381d8 -r f081a5675f93 src/video/windows/SDL_windowsmouse.c
--- a/src/video/windows/SDL_windowsmouse.c	Fri Sep 14 18:31:03 2018 -0700
+++ b/src/video/windows/SDL_windowsmouse.c	Fri Sep 14 19:26:26 2018 -0700
@@ -304,8 +304,6 @@
     mouse->GetGlobalMouseState = WIN_GetGlobalMouseState;
 
     SDL_SetDefaultCursor(WIN_CreateDefaultCursor());
-
-    SDL_SetDoubleClickTime(GetDoubleClickTime());
 }
 
 void


More information about the commits mailing list