src/video/android/SDL_androidmouse.c
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Tue, 30 Aug 2016 21:14:52 +0200
changeset 10295 b75ad23f8811
parent 10051 2c6c612344b5
child 10737 3406a0f8b041
permissions -rw-r--r--
Android: Fixed missing mouse motion events while button down (thanks, Sylvain!).

Happened for real mouse if SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH was active.

Fixes Bugzilla #3313.
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
     4 
     5   This software is provided 'as-is', without any express or implied
     6   warranty.  In no event will the authors be held liable for any damages
     7   arising from the use of this software.
     8 
     9   Permission is granted to anyone to use this software for any purpose,
    10   including commercial applications, and to alter it and redistribute it
    11   freely, subject to the following restrictions:
    12 
    13   1. The origin of this software must not be misrepresented; you must not
    14      claim that you wrote the original software. If you use this software
    15      in a product, an acknowledgment in the product documentation would be
    16      appreciated but is not required.
    17   2. Altered source versions must be plainly marked as such, and must not be
    18      misrepresented as being the original software.
    19   3. This notice may not be removed or altered from any source distribution.
    20 */
    21 
    22 #include "../../SDL_internal.h"
    23 
    24 #if SDL_VIDEO_DRIVER_ANDROID
    25 
    26 #include "SDL_androidmouse.h"
    27 
    28 #include "SDL_events.h"
    29 #include "../../events/SDL_mouse_c.h"
    30 
    31 #include "../../core/android/SDL_android.h"
    32 
    33 #define ACTION_DOWN 0
    34 #define ACTION_UP 1
    35 #define ACTION_MOVE 2
    36 #define ACTION_HOVER_MOVE 7
    37 #define ACTION_SCROLL 8
    38 #define BUTTON_PRIMARY 1
    39 #define BUTTON_SECONDARY 2
    40 #define BUTTON_TERTIARY 4
    41 #define BUTTON_BACK 8
    42 #define BUTTON_FORWARD 16
    43 
    44 static Uint8 SDLButton;
    45 
    46 void
    47 Android_InitMouse(void)
    48 {
    49     SDLButton = 0;
    50 }
    51 
    52 void Android_OnMouse( int androidButton, int action, float x, float y) {
    53     if (!Android_Window) {
    54         return;
    55     }
    56 
    57     switch(action) {
    58         case ACTION_DOWN:
    59             // Determine which button originated the event, and store it for ACTION_UP
    60             SDLButton = SDL_BUTTON_LEFT;
    61             if (androidButton == BUTTON_SECONDARY) {
    62                 SDLButton = SDL_BUTTON_RIGHT;
    63             } else if (androidButton == BUTTON_TERTIARY) {
    64                 SDLButton = SDL_BUTTON_MIDDLE;
    65             } else if (androidButton == BUTTON_FORWARD) {
    66                 SDLButton = SDL_BUTTON_X1;
    67             } else if (androidButton == BUTTON_BACK) {
    68                 SDLButton = SDL_BUTTON_X2;
    69             }
    70             SDL_SendMouseMotion(Android_Window, 0, 0, x, y);
    71             SDL_SendMouseButton(Android_Window, 0, SDL_PRESSED, SDLButton);
    72             break;
    73 
    74         case ACTION_UP:
    75             // Android won't give us the button that originated the ACTION_DOWN event, so we'll
    76             // assume it's the one we stored
    77             SDL_SendMouseMotion(Android_Window, 0, 0, x, y);
    78             SDL_SendMouseButton(Android_Window, 0, SDL_RELEASED, SDLButton);
    79             break;
    80 
    81         case ACTION_MOVE:
    82         case ACTION_HOVER_MOVE:
    83             SDL_SendMouseMotion(Android_Window, 0, 0, x, y);
    84             break;
    85 
    86         case ACTION_SCROLL:
    87             SDL_SendMouseWheel(Android_Window, 0, x, y, SDL_MOUSEWHEEL_NORMAL);
    88             break;
    89 
    90         default:
    91             break;
    92     }
    93 }
    94 
    95 #endif /* SDL_VIDEO_DRIVER_ANDROID */
    96 
    97 /* vi: set ts=4 sw=4 expandtab: */
    98