src/video/android/SDL_androidmouse.c
author Ryan C. Gordon <icculus@icculus.org>
Wed, 25 Mar 2015 10:48:59 -0400
changeset 9440 a72c15020efa
parent 9439 0d01b53cdbea
child 9619 b94b6d0bff0f
permissions -rw-r--r--
Removed unnecessary SDL_log.h include.
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
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
joseba@9438
    40
joseba@9438
    41
void Android_OnMouse( int androidButton, int action, float x, float y) {
joseba@9438
    42
    static Uint8 SDLButton;
joseba@9438
    43
joseba@9438
    44
    if (!Android_Window) {
joseba@9438
    45
        return;
joseba@9438
    46
    }
joseba@9438
    47
joseba@9438
    48
    switch(action) {
joseba@9438
    49
        case ACTION_DOWN:
joseba@9438
    50
            // Determine which button originated the event, and store it for ACTION_UP
joseba@9438
    51
            SDLButton = SDL_BUTTON_LEFT;
joseba@9438
    52
            if (androidButton == BUTTON_SECONDARY) {
joseba@9438
    53
                SDLButton = SDL_BUTTON_RIGHT;
joseba@9438
    54
            } else if (androidButton == BUTTON_TERTIARY) {
joseba@9438
    55
                SDLButton = SDL_BUTTON_MIDDLE;
joseba@9438
    56
            }
joseba@9438
    57
            SDL_SendMouseMotion(Android_Window, 0, 0, x, y);
joseba@9438
    58
            SDL_SendMouseButton(Android_Window, 0, SDL_PRESSED, SDLButton);
joseba@9438
    59
            break;
joseba@9438
    60
joseba@9438
    61
        case ACTION_UP:
joseba@9438
    62
            // Android won't give us the button that originated the ACTION_DOWN event, so we'll
joseba@9438
    63
            // assume it's the one we stored
joseba@9438
    64
            SDL_SendMouseMotion(Android_Window, 0, 0, x, y);
joseba@9438
    65
            SDL_SendMouseButton(Android_Window, 0, SDL_RELEASED, SDLButton);
joseba@9438
    66
            break;
joseba@9438
    67
joseba@9438
    68
        case ACTION_HOVER_MOVE:
joseba@9438
    69
            SDL_SendMouseMotion(Android_Window, 0, 0, x, y);
joseba@9438
    70
            break;
joseba@9438
    71
joseba@9438
    72
        case ACTION_SCROLL:
joseba@9439
    73
            SDL_SendMouseWheel(Android_Window, 0, x, y, SDL_MOUSEWHEEL_NORMAL);
joseba@9438
    74
            break;
joseba@9438
    75
joseba@9438
    76
        default:
joseba@9438
    77
            break;
joseba@9438
    78
    }
joseba@9438
    79
}
joseba@9438
    80
joseba@9438
    81
#endif /* SDL_VIDEO_DRIVER_ANDROID */
joseba@9438
    82
joseba@9438
    83
/* vi: set ts=4 sw=4 expandtab: */
joseba@9438
    84