Pass Android gamepad key press to virtual key function of example

This commit is contained in:
saschawillems 2016-05-15 11:13:14 +02:00
parent b1a07ddff8
commit de0c29b586
2 changed files with 57 additions and 9 deletions

View file

@ -1062,6 +1062,44 @@ int32_t VulkanExampleBase::handleAppInput(struct android_app* app, AInputEvent*
}
return 1;
}
if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_KEY)
{
int32_t keyCode = AKeyEvent_getKeyCode((const AInputEvent*)event);
int32_t action = AKeyEvent_getAction((const AInputEvent*)event);
int32_t button = 0;
if (action == AKEY_EVENT_ACTION_UP)
return 0;
switch (keyCode)
{
case AKEYCODE_BUTTON_A:
vulkanExample->keyPressed(GAMEPAD_BUTTON_A);
break;
case AKEYCODE_BUTTON_B:
vulkanExample->keyPressed(GAMEPAD_BUTTON_B);
break;
case AKEYCODE_BUTTON_X:
vulkanExample->keyPressed(GAMEPAD_BUTTON_X);
break;
case AKEYCODE_BUTTON_Y:
vulkanExample->keyPressed(GAMEPAD_BUTTON_Y);
break;
case AKEYCODE_BUTTON_L1:
vulkanExample->keyPressed(GAMEPAD_BUTTON_L1);
break;
case AKEYCODE_BUTTON_R1:
vulkanExample->keyPressed(GAMEPAD_BUTTON_R1);
break;
case AKEYCODE_BUTTON_START:
vulkanExample->keyPressed(GAMEPAD_BUTTON_START);
break;
};
LOGD("Button %d pressed", keyCode);
}
return 0;
}

View file

@ -40,6 +40,14 @@
#include "vulkanTextureLoader.hpp"
#include "vulkanMeshLoader.hpp"
#define GAMEPAD_BUTTON_A 0x1000
#define GAMEPAD_BUTTON_B 0x1001
#define GAMEPAD_BUTTON_X 0x1002
#define GAMEPAD_BUTTON_Y 0x1003
#define GAMEPAD_BUTTON_L1 0x1004
#define GAMEPAD_BUTTON_R1 0x1005
#define GAMEPAD_BUTTON_START 0x1006
class VulkanExampleBase
{
private:
@ -158,15 +166,8 @@ public:
VkImageView view;
} depthStencil;
// OS specific
#if defined(_WIN32)
HWND window;
HINSTANCE windowInstance;
#elif defined(__ANDROID__)
android_app* androidApp;
// true if application has focused, false if moved to background
bool focused = false;
// Gamepad state (only one)
// Gamepad state (only one pad supported)
struct
{
struct
@ -177,6 +178,15 @@ public:
float rz = 0.0f;
} axes;
} gamePadState;
// OS specific
#if defined(_WIN32)
HWND window;
HINSTANCE windowInstance;
#elif defined(__ANDROID__)
android_app* androidApp;
// true if application has focused, false if moved to background
bool focused = false;
#elif defined(__linux__)
struct {
bool left = false;