2012-10-16 19:46:31 +02:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
|
2012-10-18 06:06:55 +02:00
|
|
|
* Copyright (C) 2011-2012 - Daniel De Matteis
|
2012-10-16 19:46:31 +02:00
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2012-10-27 20:22:00 +02:00
|
|
|
#include <dlfcn.h>
|
2012-10-16 19:46:31 +02:00
|
|
|
#include "android-general.h"
|
|
|
|
#include "../../../general.h"
|
|
|
|
#include "../../../driver.h"
|
|
|
|
|
2012-10-18 06:06:55 +02:00
|
|
|
/* Process the next input event */
|
2012-10-28 02:20:25 +01:00
|
|
|
static float AMotionEvent_getAxisValue(const AInputEvent* motion_event, int32_t axis, size_t pointer_index);
|
|
|
|
|
|
|
|
#define AKEY_EVENT_NO_ACTION 255
|
2012-10-18 06:06:55 +02:00
|
|
|
|
2012-10-16 19:46:31 +02:00
|
|
|
static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
|
|
|
|
{
|
2012-10-28 02:20:25 +01:00
|
|
|
float x,y;
|
2012-10-28 03:14:50 +01:00
|
|
|
int action, keycode, source, type, id;
|
2012-10-28 02:20:25 +01:00
|
|
|
|
|
|
|
action = AKEY_EVENT_NO_ACTION;
|
|
|
|
type = AInputEvent_getType(event);
|
|
|
|
source = AInputEvent_getSource(event);
|
2012-10-28 03:14:50 +01:00
|
|
|
id = AInputEvent_getDeviceId(event);
|
2012-10-28 02:20:25 +01:00
|
|
|
|
|
|
|
switch(type)
|
2012-10-16 19:46:31 +02:00
|
|
|
{
|
2012-10-28 02:20:25 +01:00
|
|
|
case AINPUT_EVENT_TYPE_KEY:
|
|
|
|
action = AKeyEvent_getAction(event);
|
|
|
|
keycode = AKeyEvent_getKeyCode(event);
|
2012-10-28 03:14:50 +01:00
|
|
|
RARCH_LOG("AINPUT_EVENT_TYPE_KEY, id: %d.\n", id);
|
2012-10-28 02:20:25 +01:00
|
|
|
break;
|
|
|
|
case AINPUT_EVENT_TYPE_MOTION:
|
|
|
|
x = AMotionEvent_getX(event, 0);
|
|
|
|
y = AMotionEvent_getY(event, 0);
|
2012-10-28 03:14:50 +01:00
|
|
|
RARCH_LOG("AINPUT_EVENT_TYPE_MOTION, id: %d, x: %f, y: %f.\n", id, x, y);
|
2012-10-28 02:20:25 +01:00
|
|
|
break;
|
2012-10-16 19:46:31 +02:00
|
|
|
}
|
2012-10-28 02:20:25 +01:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
x = AMotionEvent_getAxisValue(event, 0, 0);
|
|
|
|
y = AMotionEvent_getAxisValue(event, 0, 0);
|
|
|
|
#endif
|
|
|
|
if(action != AKEY_EVENT_NO_ACTION)
|
|
|
|
{
|
|
|
|
switch(action)
|
|
|
|
{
|
|
|
|
case AKEY_EVENT_ACTION_DOWN:
|
2012-10-28 03:14:50 +01:00
|
|
|
RARCH_LOG("AKEY_EVENT_ACTION_DOWN, id: %d, keycode: %d.\n", id, keycode);
|
2012-10-28 02:20:25 +01:00
|
|
|
break;
|
|
|
|
case AKEY_EVENT_ACTION_UP:
|
2012-10-28 03:14:50 +01:00
|
|
|
RARCH_LOG("AKEY_EVENT_ACTION_UP, id: %d, keycode: %d.\n", id, keycode);
|
2012-10-28 02:20:25 +01:00
|
|
|
break;
|
|
|
|
case AKEY_EVENT_ACTION_MULTIPLE:
|
2012-10-28 03:14:50 +01:00
|
|
|
RARCH_LOG("AKEY_EVENT_ACTION_MULTIPLE, id: %d, keycode: %d.\n", id, keycode);
|
2012-10-28 02:20:25 +01:00
|
|
|
break;
|
|
|
|
default:
|
2012-10-28 03:14:50 +01:00
|
|
|
RARCH_LOG("AKEY_EVENT_NO_ACTION, id: %d, keycode: %d.\n", id, keycode);
|
2012-10-28 02:20:25 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(source)
|
|
|
|
{
|
|
|
|
case AINPUT_SOURCE_DPAD:
|
2012-10-28 03:14:50 +01:00
|
|
|
RARCH_LOG("AINPUT_SOURCE_DPAD, id: %d, keycode: %d.\n", id, keycode);
|
2012-10-28 02:20:25 +01:00
|
|
|
break;
|
|
|
|
case AINPUT_SOURCE_TOUCHSCREEN:
|
2012-10-28 03:14:50 +01:00
|
|
|
RARCH_LOG("AINPUT_SOURCE_TOUCHSCREEN, id: %d, keycode: %d.\n", id, keycode);
|
2012-10-28 02:20:25 +01:00
|
|
|
break;
|
|
|
|
case AINPUT_SOURCE_TOUCHPAD:
|
2012-10-28 03:14:50 +01:00
|
|
|
RARCH_LOG("AINPUT_SOURCE_TOUCHPAD, id: %d, keycode: %d.\n", id, keycode);
|
2012-10-28 02:20:25 +01:00
|
|
|
break;
|
|
|
|
case AINPUT_SOURCE_ANY:
|
2012-10-28 03:14:50 +01:00
|
|
|
RARCH_LOG("AINPUT_SOURCE_ANY, id: %d, keycode: %d.\n", id, keycode);
|
2012-10-28 02:20:25 +01:00
|
|
|
break;
|
|
|
|
default:
|
2012-10-28 03:14:50 +01:00
|
|
|
RARCH_LOG("AINPUT_SOURCE_DEFAULT, id: %d, keycode: %d.\n", id, keycode);
|
2012-10-28 02:20:25 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
2012-10-16 19:46:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void *android_input_init(void)
|
|
|
|
{
|
2012-10-27 20:22:00 +02:00
|
|
|
void *libandroid = 0;
|
|
|
|
|
2012-10-16 19:46:31 +02:00
|
|
|
g_android.app->onInputEvent = engine_handle_input;
|
2012-10-27 20:22:00 +02:00
|
|
|
|
2012-10-16 19:46:31 +02:00
|
|
|
return (void*)-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void android_input_poll(void *data)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int16_t android_input_state(void *data, const struct retro_keybind **retro_keybinds, unsigned port, unsigned device, unsigned index, unsigned id)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)retro_keybinds;
|
|
|
|
(void)port;
|
|
|
|
(void)device;
|
|
|
|
(void)index;
|
|
|
|
(void)id;
|
|
|
|
|
2012-10-21 17:30:02 +02:00
|
|
|
|
2012-10-16 19:46:31 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool android_input_key_pressed(void *data, int key)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)key;
|
|
|
|
|
2012-10-21 17:30:02 +02:00
|
|
|
switch (key)
|
|
|
|
{
|
|
|
|
case RARCH_QUIT_KEY:
|
|
|
|
if(g_android.init_quit)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
(void)0;
|
|
|
|
}
|
|
|
|
|
2012-10-16 19:46:31 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void android_input_free(void *data)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
}
|
|
|
|
|
|
|
|
const input_driver_t input_android = {
|
|
|
|
android_input_init,
|
|
|
|
android_input_poll,
|
|
|
|
android_input_state,
|
|
|
|
android_input_key_pressed,
|
|
|
|
android_input_free,
|
|
|
|
"android_input",
|
|
|
|
};
|
|
|
|
|