src/events/SDL_mouse.c
changeset 12188 f081a5675f93
parent 12024 3688283680b1
child 12462 b57435750c5b
equal deleted inserted replaced
12187:e755760381d8 12188:f081a5675f93
    31 
    31 
    32 /* #define DEBUG_MOUSE */
    32 /* #define DEBUG_MOUSE */
    33 
    33 
    34 /* The mouse state */
    34 /* The mouse state */
    35 static SDL_Mouse SDL_mouse;
    35 static SDL_Mouse SDL_mouse;
    36 static Uint32 SDL_double_click_time = 500;
       
    37 static int SDL_double_click_radius = 1;
       
    38 
    36 
    39 static int
    37 static int
    40 SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int x, int y);
    38 SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int x, int y);
       
    39 
       
    40 static void SDLCALL
       
    41 SDL_MouseDoubleClickTimeChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
       
    42 {
       
    43     SDL_Mouse *mouse = (SDL_Mouse *)userdata;
       
    44 
       
    45     if (hint && *hint) {
       
    46         mouse->double_click_time = SDL_atoi(hint);
       
    47     } else {
       
    48 #ifdef __WIN32__
       
    49         mouse->double_click_time = GetDoubleClickTime();
       
    50 #else
       
    51         mouse->double_click_time = 500;
       
    52 #endif
       
    53     }
       
    54 }
       
    55 
       
    56 static void SDLCALL
       
    57 SDL_MouseDoubleClickRadiusChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
       
    58 {
       
    59     SDL_Mouse *mouse = (SDL_Mouse *)userdata;
       
    60 
       
    61     if (hint && *hint) {
       
    62         mouse->double_click_radius = SDL_atoi(hint);
       
    63     } else {
       
    64         mouse->double_click_radius = 32;    /* 32 pixels seems about right for touch interfaces */
       
    65     }
       
    66 }
    41 
    67 
    42 static void SDLCALL
    68 static void SDLCALL
    43 SDL_MouseNormalSpeedScaleChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
    69 SDL_MouseNormalSpeedScaleChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
    44 {
    70 {
    45     SDL_Mouse *mouse = (SDL_Mouse *)userdata;
    71     SDL_Mouse *mouse = (SDL_Mouse *)userdata;
    81 {
   107 {
    82     SDL_Mouse *mouse = SDL_GetMouse();
   108     SDL_Mouse *mouse = SDL_GetMouse();
    83 
   109 
    84     SDL_zerop(mouse);
   110     SDL_zerop(mouse);
    85 
   111 
       
   112     SDL_AddHintCallback(SDL_HINT_MOUSE_DOUBLE_CLICK_TIME,
       
   113                         SDL_MouseDoubleClickTimeChanged, mouse);
       
   114 
       
   115     SDL_AddHintCallback(SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS,
       
   116                         SDL_MouseDoubleClickRadiusChanged, mouse);
       
   117 
    86     SDL_AddHintCallback(SDL_HINT_MOUSE_NORMAL_SPEED_SCALE,
   118     SDL_AddHintCallback(SDL_HINT_MOUSE_NORMAL_SPEED_SCALE,
    87                         SDL_MouseNormalSpeedScaleChanged, mouse);
   119                         SDL_MouseNormalSpeedScaleChanged, mouse);
    88 
   120 
    89     SDL_AddHintCallback(SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE,
   121     SDL_AddHintCallback(SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE,
    90                         SDL_MouseRelativeSpeedScaleChanged, mouse);
   122                         SDL_MouseRelativeSpeedScaleChanged, mouse);
   110 
   142 
   111 SDL_Mouse *
   143 SDL_Mouse *
   112 SDL_GetMouse(void)
   144 SDL_GetMouse(void)
   113 {
   145 {
   114     return &SDL_mouse;
   146     return &SDL_mouse;
   115 }
       
   116 
       
   117 void
       
   118 SDL_SetDoubleClickTime(Uint32 interval)
       
   119 {
       
   120     SDL_double_click_time = interval;
       
   121 }
   147 }
   122 
   148 
   123 SDL_Window *
   149 SDL_Window *
   124 SDL_GetMouseFocus(void)
   150 SDL_GetMouseFocus(void)
   125 {
   151 {
   452         SDL_MouseClickState *clickstate = GetMouseClickState(mouse, button);
   478         SDL_MouseClickState *clickstate = GetMouseClickState(mouse, button);
   453         if (clickstate) {
   479         if (clickstate) {
   454             if (state == SDL_PRESSED) {
   480             if (state == SDL_PRESSED) {
   455                 Uint32 now = SDL_GetTicks();
   481                 Uint32 now = SDL_GetTicks();
   456 
   482 
   457                 if (SDL_TICKS_PASSED(now, clickstate->last_timestamp + SDL_double_click_time) ||
   483                 if (SDL_TICKS_PASSED(now, clickstate->last_timestamp + mouse->double_click_time) ||
   458                     SDL_abs(mouse->x - clickstate->last_x) > SDL_double_click_radius ||
   484                     SDL_abs(mouse->x - clickstate->last_x) > mouse->double_click_radius ||
   459                     SDL_abs(mouse->y - clickstate->last_y) > SDL_double_click_radius) {
   485                     SDL_abs(mouse->y - clickstate->last_y) > mouse->double_click_radius) {
   460                     clickstate->click_count = 0;
   486                     clickstate->click_count = 0;
   461                 }
   487                 }
   462                 clickstate->last_timestamp = now;
   488                 clickstate->last_timestamp = now;
   463                 clickstate->last_x = mouse->x;
   489                 clickstate->last_x = mouse->x;
   464                 clickstate->last_y = mouse->y;
   490                 clickstate->last_y = mouse->y;