src/video/android/SDL_androidtouch.c
author Sam Lantinga <slouken@libsdl.org>
Fri, 08 Apr 2011 13:03:26 -0700
changeset 5535 96594ac5fd1a
parent 5262 b530ef003506
child 5982 f324bd81b52c
permissions -rw-r--r--
SDL 1.3 is now under the zlib license.
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2011 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 #include "SDL_config.h"
    22 
    23 #include <android/log.h>
    24 
    25 #include "SDL_events.h"
    26 #include "../../events/SDL_mouse_c.h"
    27 
    28 #include "SDL_androidtouch.h"
    29 
    30 
    31 #define ACTION_DOWN 0
    32 #define ACTION_UP 1
    33 #define ACTION_MOVE 2
    34 #define ACTION_CANCEL 3
    35 #define ACTION_OUTSIDE 4
    36 
    37 void Android_OnTouch(int action, float x, float y, float p)
    38 {
    39     if (!Android_Window) {
    40         return;
    41     }
    42 
    43     if ((action != ACTION_CANCEL) && (action != ACTION_OUTSIDE)) {
    44         SDL_SetMouseFocus(Android_Window);
    45         SDL_SendMouseMotion(Android_Window, 0, (int)x, (int)y);
    46         switch(action) {
    47         case ACTION_DOWN:
    48             SDL_SendMouseButton(Android_Window, SDL_PRESSED, SDL_BUTTON_LEFT);
    49             break;
    50         case ACTION_UP:
    51             SDL_SendMouseButton(Android_Window, SDL_RELEASED, SDL_BUTTON_LEFT);
    52             break;
    53         }
    54     } else {
    55         SDL_SetMouseFocus(NULL);
    56     }
    57 }
    58 
    59 /* vi: set ts=4 sw=4 expandtab: */