Added hints SDL_HINT_MOUSE_DOUBLE_CLICK_TIME and SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS to allow tuning double-click sensitivity.
authorSam Lantinga <slouken@libsdl.org>
Fri, 14 Sep 2018 19:26:26 -0700
changeset 12188f081a5675f93
parent 12187 e755760381d8
child 12189 bd18236f41b5
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
include/SDL_hints.h
src/events/SDL_mouse.c
src/events/SDL_mouse_c.h
src/video/windows/SDL_windowsmouse.c
     1.1 --- a/include/SDL_hints.h	Fri Sep 14 18:31:03 2018 -0700
     1.2 +++ b/include/SDL_hints.h	Fri Sep 14 19:26:26 2018 -0700
     1.3 @@ -263,6 +263,16 @@
     1.4  #define SDL_HINT_GRAB_KEYBOARD              "SDL_GRAB_KEYBOARD"
     1.5  
     1.6  /**
     1.7 + *  \brief  A variable setting the double click time, in milliseconds.
     1.8 + */
     1.9 +#define SDL_HINT_MOUSE_DOUBLE_CLICK_TIME    "SDL_MOUSE_DOUBLE_CLICK_TIME"
    1.10 +
    1.11 +/**
    1.12 + *  \brief  A variable setting the double click radius, in pixels.
    1.13 + */
    1.14 +#define SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS    "SDL_MOUSE_DOUBLE_CLICK_RADIUS"
    1.15 +
    1.16 +/**
    1.17   *  \brief  A variable setting the speed scale for mouse motion, in floating point, when the mouse is not in relative mode
    1.18   */
    1.19  #define SDL_HINT_MOUSE_NORMAL_SPEED_SCALE    "SDL_MOUSE_NORMAL_SPEED_SCALE"
     2.1 --- a/src/events/SDL_mouse.c	Fri Sep 14 18:31:03 2018 -0700
     2.2 +++ b/src/events/SDL_mouse.c	Fri Sep 14 19:26:26 2018 -0700
     2.3 @@ -33,13 +33,39 @@
     2.4  
     2.5  /* The mouse state */
     2.6  static SDL_Mouse SDL_mouse;
     2.7 -static Uint32 SDL_double_click_time = 500;
     2.8 -static int SDL_double_click_radius = 1;
     2.9  
    2.10  static int
    2.11  SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int x, int y);
    2.12  
    2.13  static void SDLCALL
    2.14 +SDL_MouseDoubleClickTimeChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
    2.15 +{
    2.16 +    SDL_Mouse *mouse = (SDL_Mouse *)userdata;
    2.17 +
    2.18 +    if (hint && *hint) {
    2.19 +        mouse->double_click_time = SDL_atoi(hint);
    2.20 +    } else {
    2.21 +#ifdef __WIN32__
    2.22 +        mouse->double_click_time = GetDoubleClickTime();
    2.23 +#else
    2.24 +        mouse->double_click_time = 500;
    2.25 +#endif
    2.26 +    }
    2.27 +}
    2.28 +
    2.29 +static void SDLCALL
    2.30 +SDL_MouseDoubleClickRadiusChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
    2.31 +{
    2.32 +    SDL_Mouse *mouse = (SDL_Mouse *)userdata;
    2.33 +
    2.34 +    if (hint && *hint) {
    2.35 +        mouse->double_click_radius = SDL_atoi(hint);
    2.36 +    } else {
    2.37 +        mouse->double_click_radius = 32;    /* 32 pixels seems about right for touch interfaces */
    2.38 +    }
    2.39 +}
    2.40 +
    2.41 +static void SDLCALL
    2.42  SDL_MouseNormalSpeedScaleChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
    2.43  {
    2.44      SDL_Mouse *mouse = (SDL_Mouse *)userdata;
    2.45 @@ -83,6 +109,12 @@
    2.46  
    2.47      SDL_zerop(mouse);
    2.48  
    2.49 +    SDL_AddHintCallback(SDL_HINT_MOUSE_DOUBLE_CLICK_TIME,
    2.50 +                        SDL_MouseDoubleClickTimeChanged, mouse);
    2.51 +
    2.52 +    SDL_AddHintCallback(SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS,
    2.53 +                        SDL_MouseDoubleClickRadiusChanged, mouse);
    2.54 +
    2.55      SDL_AddHintCallback(SDL_HINT_MOUSE_NORMAL_SPEED_SCALE,
    2.56                          SDL_MouseNormalSpeedScaleChanged, mouse);
    2.57  
    2.58 @@ -114,12 +146,6 @@
    2.59      return &SDL_mouse;
    2.60  }
    2.61  
    2.62 -void
    2.63 -SDL_SetDoubleClickTime(Uint32 interval)
    2.64 -{
    2.65 -    SDL_double_click_time = interval;
    2.66 -}
    2.67 -
    2.68  SDL_Window *
    2.69  SDL_GetMouseFocus(void)
    2.70  {
    2.71 @@ -454,9 +480,9 @@
    2.72              if (state == SDL_PRESSED) {
    2.73                  Uint32 now = SDL_GetTicks();
    2.74  
    2.75 -                if (SDL_TICKS_PASSED(now, clickstate->last_timestamp + SDL_double_click_time) ||
    2.76 -                    SDL_abs(mouse->x - clickstate->last_x) > SDL_double_click_radius ||
    2.77 -                    SDL_abs(mouse->y - clickstate->last_y) > SDL_double_click_radius) {
    2.78 +                if (SDL_TICKS_PASSED(now, clickstate->last_timestamp + mouse->double_click_time) ||
    2.79 +                    SDL_abs(mouse->x - clickstate->last_x) > mouse->double_click_radius ||
    2.80 +                    SDL_abs(mouse->y - clickstate->last_y) > mouse->double_click_radius) {
    2.81                      clickstate->click_count = 0;
    2.82                  }
    2.83                  clickstate->last_timestamp = now;
     3.1 --- a/src/events/SDL_mouse_c.h	Fri Sep 14 18:31:03 2018 -0700
     3.2 +++ b/src/events/SDL_mouse_c.h	Fri Sep 14 19:26:26 2018 -0700
     3.3 @@ -90,6 +90,8 @@
     3.4      float relative_speed_scale;
     3.5      float scale_accum_x;
     3.6      float scale_accum_y;
     3.7 +    Uint32 double_click_time;
     3.8 +    int double_click_radius;
     3.9      SDL_bool touch_mouse_events;
    3.10  
    3.11      /* Data for double-click tracking */
    3.12 @@ -112,9 +114,6 @@
    3.13  /* Get the mouse state structure */
    3.14  SDL_Mouse *SDL_GetMouse(void);
    3.15  
    3.16 -/* Set the default double-click interval */
    3.17 -extern void SDL_SetDoubleClickTime(Uint32 interval);
    3.18 -
    3.19  /* Set the default mouse cursor */
    3.20  extern void SDL_SetDefaultCursor(SDL_Cursor * cursor);
    3.21  
     4.1 --- a/src/video/windows/SDL_windowsmouse.c	Fri Sep 14 18:31:03 2018 -0700
     4.2 +++ b/src/video/windows/SDL_windowsmouse.c	Fri Sep 14 19:26:26 2018 -0700
     4.3 @@ -304,8 +304,6 @@
     4.4      mouse->GetGlobalMouseState = WIN_GetGlobalMouseState;
     4.5  
     4.6      SDL_SetDefaultCursor(WIN_CreateDefaultCursor());
     4.7 -
     4.8 -    SDL_SetDoubleClickTime(GetDoubleClickTime());
     4.9  }
    4.10  
    4.11  void