src/video/android/SDL_androidmouse.c
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Tue, 12 Jan 2016 22:23:00 +0100
changeset 10051 2c6c612344b5
parent 10049 0052384f717f
child 10295 b75ad23f8811
permissions -rw-r--r--
Android: Added mouse initialization to reset state.

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