src/video/android/SDL_androidmouse.c
author Joseba García Etxebarria <joseba.gar@gmail.com>
Tue, 24 Mar 2015 20:45:29 +0100
changeset 9438 fff5af5de6dd
child 9439 0d01b53cdbea
permissions -rw-r--r--
* Improve mouse support in Android. These changes require Android API v12 to compile
joseba@9438
     1
/*
joseba@9438
     2
  Simple DirectMedia Layer
joseba@9438
     3
  Copyright (C) 1997-2014 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
#include "SDL_Log.h"
joseba@9438
    28
joseba@9438
    29
#include "SDL_events.h"
joseba@9438
    30
#include "../../events/SDL_mouse_c.h"
joseba@9438
    31
joseba@9438
    32
#include "../../core/android/SDL_android.h"
joseba@9438
    33
joseba@9438
    34
#define ACTION_DOWN 0
joseba@9438
    35
#define ACTION_UP 1
joseba@9438
    36
#define ACTION_HOVER_MOVE 7
joseba@9438
    37
#define ACTION_SCROLL 8
joseba@9438
    38
#define BUTTON_PRIMARY 1
joseba@9438
    39
#define BUTTON_SECONDARY 2
joseba@9438
    40
#define BUTTON_TERTIARY 4
joseba@9438
    41
joseba@9438
    42
void Android_OnMouse( int androidButton, int action, float x, float y) {
joseba@9438
    43
    static Uint8 SDLButton;
joseba@9438
    44
joseba@9438
    45
    if (!Android_Window) {
joseba@9438
    46
        return;
joseba@9438
    47
    }
joseba@9438
    48
joseba@9438
    49
    switch(action) {
joseba@9438
    50
        case ACTION_DOWN:
joseba@9438
    51
            // Determine which button originated the event, and store it for ACTION_UP
joseba@9438
    52
            SDLButton = SDL_BUTTON_LEFT;
joseba@9438
    53
            if (androidButton == BUTTON_SECONDARY) {
joseba@9438
    54
                SDLButton = SDL_BUTTON_RIGHT;
joseba@9438
    55
            } else if (androidButton == BUTTON_TERTIARY) {
joseba@9438
    56
                SDLButton = SDL_BUTTON_MIDDLE;
joseba@9438
    57
            }
joseba@9438
    58
            SDL_SendMouseMotion(Android_Window, 0, 0, x, y);
joseba@9438
    59
            SDL_SendMouseButton(Android_Window, 0, SDL_PRESSED, SDLButton);
joseba@9438
    60
            break;
joseba@9438
    61
joseba@9438
    62
        case ACTION_UP:
joseba@9438
    63
            // Android won't give us the button that originated the ACTION_DOWN event, so we'll
joseba@9438
    64
            // assume it's the one we stored
joseba@9438
    65
            SDL_SendMouseMotion(Android_Window, 0, 0, x, y);
joseba@9438
    66
            SDL_SendMouseButton(Android_Window, 0, SDL_RELEASED, SDLButton);
joseba@9438
    67
            break;
joseba@9438
    68
joseba@9438
    69
        case ACTION_HOVER_MOVE:
joseba@9438
    70
            SDL_SendMouseMotion(Android_Window, 0, 0, x, y);
joseba@9438
    71
            break;
joseba@9438
    72
joseba@9438
    73
        case ACTION_SCROLL:
joseba@9438
    74
            SDL_SendMouseWheel(Android_Window, 0, x, y);
joseba@9438
    75
            break;
joseba@9438
    76
joseba@9438
    77
        default:
joseba@9438
    78
            break;
joseba@9438
    79
    }
joseba@9438
    80
}
joseba@9438
    81
joseba@9438
    82
#endif /* SDL_VIDEO_DRIVER_ANDROID */
joseba@9438
    83
joseba@9438
    84
/* vi: set ts=4 sw=4 expandtab: */
joseba@9438
    85