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.
slouken@5001
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@5535
     3
  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
slouken@5001
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@5001
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@5001
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@5001
    20
*/
slouken@5001
    21
#include "SDL_config.h"
slouken@5001
    22
slouken@5001
    23
#include <android/log.h>
slouken@5001
    24
slouken@5001
    25
#include "SDL_events.h"
slouken@5001
    26
#include "../../events/SDL_mouse_c.h"
slouken@5001
    27
slouken@5001
    28
#include "SDL_androidtouch.h"
slouken@5001
    29
slouken@5001
    30
slouken@5001
    31
#define ACTION_DOWN 0
slouken@5001
    32
#define ACTION_UP 1
slouken@5001
    33
#define ACTION_MOVE 2
slouken@5001
    34
#define ACTION_CANCEL 3
slouken@5001
    35
#define ACTION_OUTSIDE 4
slouken@5001
    36
slouken@5001
    37
void Android_OnTouch(int action, float x, float y, float p)
slouken@5001
    38
{
slouken@5001
    39
    if (!Android_Window) {
slouken@5001
    40
        return;
slouken@5001
    41
    }
slouken@5001
    42
slouken@5001
    43
    if ((action != ACTION_CANCEL) && (action != ACTION_OUTSIDE)) {
slouken@5001
    44
        SDL_SetMouseFocus(Android_Window);
slouken@5001
    45
        SDL_SendMouseMotion(Android_Window, 0, (int)x, (int)y);
slouken@5001
    46
        switch(action) {
slouken@5001
    47
        case ACTION_DOWN:
slouken@5001
    48
            SDL_SendMouseButton(Android_Window, SDL_PRESSED, SDL_BUTTON_LEFT);
slouken@5001
    49
            break;
slouken@5001
    50
        case ACTION_UP:
slouken@5001
    51
            SDL_SendMouseButton(Android_Window, SDL_RELEASED, SDL_BUTTON_LEFT);
slouken@5001
    52
            break;
slouken@5001
    53
        }
slouken@5001
    54
    } else {
slouken@5001
    55
        SDL_SetMouseFocus(NULL);
slouken@5001
    56
    }
slouken@5001
    57
}
slouken@5001
    58
slouken@5001
    59
/* vi: set ts=4 sw=4 expandtab: */