src/video/android/SDL_androidmouse.c
changeset 9438 fff5af5de6dd
child 9439 0d01b53cdbea
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/android/SDL_androidmouse.c	Tue Mar 24 20:45:29 2015 +0100
     1.3 @@ -0,0 +1,85 @@
     1.4 +/*
     1.5 +  Simple DirectMedia Layer
     1.6 +  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
     1.7 +
     1.8 +  This software is provided 'as-is', without any express or implied
     1.9 +  warranty.  In no event will the authors be held liable for any damages
    1.10 +  arising from the use of this software.
    1.11 +
    1.12 +  Permission is granted to anyone to use this software for any purpose,
    1.13 +  including commercial applications, and to alter it and redistribute it
    1.14 +  freely, subject to the following restrictions:
    1.15 +
    1.16 +  1. The origin of this software must not be misrepresented; you must not
    1.17 +     claim that you wrote the original software. If you use this software
    1.18 +     in a product, an acknowledgment in the product documentation would be
    1.19 +     appreciated but is not required.
    1.20 +  2. Altered source versions must be plainly marked as such, and must not be
    1.21 +     misrepresented as being the original software.
    1.22 +  3. This notice may not be removed or altered from any source distribution.
    1.23 +*/
    1.24 +
    1.25 +#include "../../SDL_internal.h"
    1.26 +
    1.27 +#if SDL_VIDEO_DRIVER_ANDROID
    1.28 +
    1.29 +#include "SDL_androidmouse.h"
    1.30 +#include "SDL_Log.h"
    1.31 +
    1.32 +#include "SDL_events.h"
    1.33 +#include "../../events/SDL_mouse_c.h"
    1.34 +
    1.35 +#include "../../core/android/SDL_android.h"
    1.36 +
    1.37 +#define ACTION_DOWN 0
    1.38 +#define ACTION_UP 1
    1.39 +#define ACTION_HOVER_MOVE 7
    1.40 +#define ACTION_SCROLL 8
    1.41 +#define BUTTON_PRIMARY 1
    1.42 +#define BUTTON_SECONDARY 2
    1.43 +#define BUTTON_TERTIARY 4
    1.44 +
    1.45 +void Android_OnMouse( int androidButton, int action, float x, float y) {
    1.46 +    static Uint8 SDLButton;
    1.47 +
    1.48 +    if (!Android_Window) {
    1.49 +        return;
    1.50 +    }
    1.51 +
    1.52 +    switch(action) {
    1.53 +        case ACTION_DOWN:
    1.54 +            // Determine which button originated the event, and store it for ACTION_UP
    1.55 +            SDLButton = SDL_BUTTON_LEFT;
    1.56 +            if (androidButton == BUTTON_SECONDARY) {
    1.57 +                SDLButton = SDL_BUTTON_RIGHT;
    1.58 +            } else if (androidButton == BUTTON_TERTIARY) {
    1.59 +                SDLButton = SDL_BUTTON_MIDDLE;
    1.60 +            }
    1.61 +            SDL_SendMouseMotion(Android_Window, 0, 0, x, y);
    1.62 +            SDL_SendMouseButton(Android_Window, 0, SDL_PRESSED, SDLButton);
    1.63 +            break;
    1.64 +
    1.65 +        case ACTION_UP:
    1.66 +            // Android won't give us the button that originated the ACTION_DOWN event, so we'll
    1.67 +            // assume it's the one we stored
    1.68 +            SDL_SendMouseMotion(Android_Window, 0, 0, x, y);
    1.69 +            SDL_SendMouseButton(Android_Window, 0, SDL_RELEASED, SDLButton);
    1.70 +            break;
    1.71 +
    1.72 +        case ACTION_HOVER_MOVE:
    1.73 +            SDL_SendMouseMotion(Android_Window, 0, 0, x, y);
    1.74 +            break;
    1.75 +
    1.76 +        case ACTION_SCROLL:
    1.77 +            SDL_SendMouseWheel(Android_Window, 0, x, y);
    1.78 +            break;
    1.79 +
    1.80 +        default:
    1.81 +            break;
    1.82 +    }
    1.83 +}
    1.84 +
    1.85 +#endif /* SDL_VIDEO_DRIVER_ANDROID */
    1.86 +
    1.87 +/* vi: set ts=4 sw=4 expandtab: */
    1.88 +