src/events/SDL_mouse.c
changeset 10366 e1b52e69578b
parent 9998 f67cf37e9cd4
child 10390 420482621a34
     1.1 --- a/src/events/SDL_mouse.c	Sat Sep 24 13:28:40 2016 -0300
     1.2 +++ b/src/events/SDL_mouse.c	Sat Sep 24 18:46:34 2016 -0300
     1.3 @@ -322,15 +322,13 @@
     1.4      return &mouse->clickstate[button];
     1.5  }
     1.6  
     1.7 -int
     1.8 -SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button)
     1.9 +static int
    1.10 +SDL_PrivateSendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
    1.11  {
    1.12      SDL_Mouse *mouse = SDL_GetMouse();
    1.13      int posted;
    1.14      Uint32 type;
    1.15      Uint32 buttonstate = mouse->buttonstate;
    1.16 -    SDL_MouseClickState *clickstate = GetMouseClickState(mouse, button);
    1.17 -    Uint8 click_count;
    1.18  
    1.19      /* Figure out which event to perform */
    1.20      switch (state) {
    1.21 @@ -358,7 +356,8 @@
    1.22      }
    1.23      mouse->buttonstate = buttonstate;
    1.24  
    1.25 -    if (clickstate) {
    1.26 +    if (clicks < 0) {
    1.27 +        SDL_MouseClickState *clickstate = GetMouseClickState(mouse, button);
    1.28          if (state == SDL_PRESSED) {
    1.29              Uint32 now = SDL_GetTicks();
    1.30  
    1.31 @@ -374,9 +373,7 @@
    1.32                  ++clickstate->click_count;
    1.33              }
    1.34          }
    1.35 -        click_count = clickstate->click_count;
    1.36 -    } else {
    1.37 -        click_count = 1;
    1.38 +        clicks = clickstate->click_count;
    1.39      }
    1.40  
    1.41      /* Post the event, if desired */
    1.42 @@ -388,7 +385,7 @@
    1.43          event.button.which = mouseID;
    1.44          event.button.state = state;
    1.45          event.button.button = button;
    1.46 -        event.button.clicks = click_count;
    1.47 +        event.button.clicks = (Uint8) SDL_min(clicks, 255);
    1.48          event.button.x = mouse->x;
    1.49          event.button.y = mouse->y;
    1.50          posted = (SDL_PushEvent(&event) > 0);
    1.51 @@ -398,8 +395,21 @@
    1.52      if (window && state == SDL_RELEASED) {
    1.53          SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate);
    1.54      }
    1.55 +    
    1.56 +    return posted;
    1.57 +}
    1.58  
    1.59 -    return posted;
    1.60 +int
    1.61 +SDL_SendMouseButtonClicks(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
    1.62 +{
    1.63 +    clicks = SDL_max(clicks, 0);
    1.64 +    return SDL_PrivateSendMouseButton(window, mouseID, state, button, clicks);
    1.65 +}
    1.66 +
    1.67 +int
    1.68 +SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button)
    1.69 +{
    1.70 +    return SDL_PrivateSendMouseButton(window, mouseID, state, button, -1);
    1.71  }
    1.72  
    1.73  int