src/events/SDL_mouse.c
changeset 12188 f081a5675f93
parent 12024 3688283680b1
child 12462 b57435750c5b
     1.1 --- a/src/events/SDL_mouse.c	Fri Sep 14 18:31:03 2018 -0700
     1.2 +++ b/src/events/SDL_mouse.c	Fri Sep 14 19:26:26 2018 -0700
     1.3 @@ -33,13 +33,39 @@
     1.4  
     1.5  /* The mouse state */
     1.6  static SDL_Mouse SDL_mouse;
     1.7 -static Uint32 SDL_double_click_time = 500;
     1.8 -static int SDL_double_click_radius = 1;
     1.9  
    1.10  static int
    1.11  SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int x, int y);
    1.12  
    1.13  static void SDLCALL
    1.14 +SDL_MouseDoubleClickTimeChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
    1.15 +{
    1.16 +    SDL_Mouse *mouse = (SDL_Mouse *)userdata;
    1.17 +
    1.18 +    if (hint && *hint) {
    1.19 +        mouse->double_click_time = SDL_atoi(hint);
    1.20 +    } else {
    1.21 +#ifdef __WIN32__
    1.22 +        mouse->double_click_time = GetDoubleClickTime();
    1.23 +#else
    1.24 +        mouse->double_click_time = 500;
    1.25 +#endif
    1.26 +    }
    1.27 +}
    1.28 +
    1.29 +static void SDLCALL
    1.30 +SDL_MouseDoubleClickRadiusChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
    1.31 +{
    1.32 +    SDL_Mouse *mouse = (SDL_Mouse *)userdata;
    1.33 +
    1.34 +    if (hint && *hint) {
    1.35 +        mouse->double_click_radius = SDL_atoi(hint);
    1.36 +    } else {
    1.37 +        mouse->double_click_radius = 32;    /* 32 pixels seems about right for touch interfaces */
    1.38 +    }
    1.39 +}
    1.40 +
    1.41 +static void SDLCALL
    1.42  SDL_MouseNormalSpeedScaleChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
    1.43  {
    1.44      SDL_Mouse *mouse = (SDL_Mouse *)userdata;
    1.45 @@ -83,6 +109,12 @@
    1.46  
    1.47      SDL_zerop(mouse);
    1.48  
    1.49 +    SDL_AddHintCallback(SDL_HINT_MOUSE_DOUBLE_CLICK_TIME,
    1.50 +                        SDL_MouseDoubleClickTimeChanged, mouse);
    1.51 +
    1.52 +    SDL_AddHintCallback(SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS,
    1.53 +                        SDL_MouseDoubleClickRadiusChanged, mouse);
    1.54 +
    1.55      SDL_AddHintCallback(SDL_HINT_MOUSE_NORMAL_SPEED_SCALE,
    1.56                          SDL_MouseNormalSpeedScaleChanged, mouse);
    1.57  
    1.58 @@ -114,12 +146,6 @@
    1.59      return &SDL_mouse;
    1.60  }
    1.61  
    1.62 -void
    1.63 -SDL_SetDoubleClickTime(Uint32 interval)
    1.64 -{
    1.65 -    SDL_double_click_time = interval;
    1.66 -}
    1.67 -
    1.68  SDL_Window *
    1.69  SDL_GetMouseFocus(void)
    1.70  {
    1.71 @@ -454,9 +480,9 @@
    1.72              if (state == SDL_PRESSED) {
    1.73                  Uint32 now = SDL_GetTicks();
    1.74  
    1.75 -                if (SDL_TICKS_PASSED(now, clickstate->last_timestamp + SDL_double_click_time) ||
    1.76 -                    SDL_abs(mouse->x - clickstate->last_x) > SDL_double_click_radius ||
    1.77 -                    SDL_abs(mouse->y - clickstate->last_y) > SDL_double_click_radius) {
    1.78 +                if (SDL_TICKS_PASSED(now, clickstate->last_timestamp + mouse->double_click_time) ||
    1.79 +                    SDL_abs(mouse->x - clickstate->last_x) > mouse->double_click_radius ||
    1.80 +                    SDL_abs(mouse->y - clickstate->last_y) > mouse->double_click_radius) {
    1.81                      clickstate->click_count = 0;
    1.82                  }
    1.83                  clickstate->last_timestamp = now;