src/video/android/SDL_androidtouch.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 13 Jan 2011 18:31:15 -0800
changeset 5001 77df56570442
child 5262 b530ef003506
permissions -rw-r--r--
Added "mouse" support for the Android touch screen
slouken@5001
     1
/*
slouken@5001
     2
    SDL - Simple DirectMedia Layer
slouken@5001
     3
    Copyright (C) 1997-2010 Sam Lantinga
slouken@5001
     4
slouken@5001
     5
    This library is free software; you can redistribute it and/or
slouken@5001
     6
    modify it under the terms of the GNU Lesser General Public
slouken@5001
     7
    License as published by the Free Software Foundation; either
slouken@5001
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@5001
     9
slouken@5001
    10
    This library is distributed in the hope that it will be useful,
slouken@5001
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@5001
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@5001
    13
    Lesser General Public License for more details.
slouken@5001
    14
slouken@5001
    15
    You should have received a copy of the GNU Lesser General Public
slouken@5001
    16
    License along with this library; if not, write to the Free Software
slouken@5001
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@5001
    18
slouken@5001
    19
    Sam Lantinga
slouken@5001
    20
    slouken@libsdl.org
slouken@5001
    21
*/
slouken@5001
    22
#include "SDL_config.h"
slouken@5001
    23
slouken@5001
    24
#include <android/log.h>
slouken@5001
    25
slouken@5001
    26
#include "SDL_events.h"
slouken@5001
    27
#include "../../events/SDL_mouse_c.h"
slouken@5001
    28
slouken@5001
    29
#include "SDL_androidtouch.h"
slouken@5001
    30
slouken@5001
    31
slouken@5001
    32
#define ACTION_DOWN 0
slouken@5001
    33
#define ACTION_UP 1
slouken@5001
    34
#define ACTION_MOVE 2
slouken@5001
    35
#define ACTION_CANCEL 3
slouken@5001
    36
#define ACTION_OUTSIDE 4
slouken@5001
    37
slouken@5001
    38
void Android_OnTouch(int action, float x, float y, float p)
slouken@5001
    39
{
slouken@5001
    40
    if (!Android_Window) {
slouken@5001
    41
        return;
slouken@5001
    42
    }
slouken@5001
    43
slouken@5001
    44
    if ((action != ACTION_CANCEL) && (action != ACTION_OUTSIDE)) {
slouken@5001
    45
        SDL_SetMouseFocus(Android_Window);
slouken@5001
    46
        SDL_SendMouseMotion(Android_Window, 0, (int)x, (int)y);
slouken@5001
    47
        switch(action) {
slouken@5001
    48
        case ACTION_DOWN:
slouken@5001
    49
            SDL_SendMouseButton(Android_Window, SDL_PRESSED, SDL_BUTTON_LEFT);
slouken@5001
    50
            break;
slouken@5001
    51
        case ACTION_UP:
slouken@5001
    52
            SDL_SendMouseButton(Android_Window, SDL_RELEASED, SDL_BUTTON_LEFT);
slouken@5001
    53
            break;
slouken@5001
    54
        }
slouken@5001
    55
    } else {
slouken@5001
    56
        SDL_SetMouseFocus(NULL);
slouken@5001
    57
    }
slouken@5001
    58
}
slouken@5001
    59
slouken@5001
    60
/* vi: set ts=4 sw=4 expandtab: */