change SDL 1.2 to SDL 2.0
[platform/upstream/SDL.git] / src / video / android / SDL_androidmouse.c
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_HOVER_MOVE 7
36 #define ACTION_SCROLL 8
37 #define BUTTON_PRIMARY 1
38 #define BUTTON_SECONDARY 2
39 #define BUTTON_TERTIARY 4
40
41 void Android_OnMouse( int androidButton, int action, float x, float y) {
42     static Uint8 SDLButton;
43
44     if (!Android_Window) {
45         return;
46     }
47
48     switch(action) {
49         case ACTION_DOWN:
50             // Determine which button originated the event, and store it for ACTION_UP
51             SDLButton = SDL_BUTTON_LEFT;
52             if (androidButton == BUTTON_SECONDARY) {
53                 SDLButton = SDL_BUTTON_RIGHT;
54             } else if (androidButton == BUTTON_TERTIARY) {
55                 SDLButton = SDL_BUTTON_MIDDLE;
56             }
57             SDL_SendMouseMotion(Android_Window, 0, 0, x, y);
58             SDL_SendMouseButton(Android_Window, 0, SDL_PRESSED, SDLButton);
59             break;
60
61         case ACTION_UP:
62             // Android won't give us the button that originated the ACTION_DOWN event, so we'll
63             // assume it's the one we stored
64             SDL_SendMouseMotion(Android_Window, 0, 0, x, y);
65             SDL_SendMouseButton(Android_Window, 0, SDL_RELEASED, SDLButton);
66             break;
67
68         case ACTION_HOVER_MOVE:
69             SDL_SendMouseMotion(Android_Window, 0, 0, x, y);
70             break;
71
72         case ACTION_SCROLL:
73             SDL_SendMouseWheel(Android_Window, 0, x, y, SDL_MOUSEWHEEL_NORMAL);
74             break;
75
76         default:
77             break;
78     }
79 }
80
81 #endif /* SDL_VIDEO_DRIVER_ANDROID */
82
83 /* vi: set ts=4 sw=4 expandtab: */
84