mirror of
https://github.com/libretro/ppsspp.git
synced 2025-02-19 00:19:26 +00:00
Generalize the code mapping android key events into pad button bits, add support for keys needed to navigate UI.
This commit is contained in:
parent
ef98d30c38
commit
7151e4c06e
@ -33,8 +33,6 @@ std::string frameCommandParam;
|
||||
|
||||
const bool extraLog = true;
|
||||
|
||||
static uint32_t pad_buttons_async_set;
|
||||
static uint32_t pad_buttons_async_clear;
|
||||
static float left_joystick_x_async;
|
||||
static float left_joystick_y_async;
|
||||
static float right_joystick_x_async;
|
||||
@ -42,8 +40,6 @@ static float right_joystick_y_async;
|
||||
static float hat_joystick_x_async;
|
||||
static float hat_joystick_y_async;
|
||||
|
||||
static uint32_t pad_buttons_down;
|
||||
|
||||
int optimalFramesPerBuffer = 0;
|
||||
int optimalSampleRate = 0;
|
||||
|
||||
@ -142,9 +138,7 @@ extern "C" void Java_com_henrikrydgard_libnative_NativeApp_init
|
||||
renderer_inited = false;
|
||||
first_lost = true;
|
||||
|
||||
pad_buttons_down = 0;
|
||||
pad_buttons_async_set = 0;
|
||||
pad_buttons_async_clear = 0;
|
||||
g_buttonTracker.Reset();
|
||||
|
||||
left_joystick_x_async = 0;
|
||||
left_joystick_y_async = 0;
|
||||
@ -262,20 +256,13 @@ extern "C" void Java_com_henrikrydgard_libnative_NativeRenderer_displayRender(JN
|
||||
// TODO: Look into if these locks are a perf loss
|
||||
{
|
||||
lock_guard guard(input_state.lock);
|
||||
pad_buttons_down |= pad_buttons_async_set;
|
||||
pad_buttons_down &= ~pad_buttons_async_clear;
|
||||
|
||||
input_state.pad_buttons = pad_buttons_down;
|
||||
|
||||
UpdateInputState(&input_state);
|
||||
}
|
||||
|
||||
{
|
||||
lock_guard guard(input_state.lock);
|
||||
input_state.pad_lstick_x = left_joystick_x_async;
|
||||
input_state.pad_lstick_y = left_joystick_y_async;
|
||||
input_state.pad_rstick_x = right_joystick_x_async;
|
||||
input_state.pad_rstick_y = right_joystick_y_async;
|
||||
|
||||
UpdateInputState(&input_state);
|
||||
}
|
||||
NativeUpdate(input_state);
|
||||
|
||||
@ -367,15 +354,6 @@ extern "C" void JNICALL Java_com_henrikrydgard_libnative_NativeApp_touch
|
||||
// ELOG("Touch Exit %i", pointerId);
|
||||
}
|
||||
|
||||
static inline void AsyncDown(int padbutton) {
|
||||
pad_buttons_async_set |= padbutton;
|
||||
pad_buttons_async_clear &= ~padbutton;
|
||||
}
|
||||
|
||||
static inline void AsyncUp(int padbutton) {
|
||||
pad_buttons_async_set &= ~padbutton;
|
||||
pad_buttons_async_clear |= padbutton;
|
||||
}
|
||||
|
||||
extern "C" void Java_com_henrikrydgard_libnative_NativeApp_keyDown(JNIEnv *, jclass, jint deviceId, jint key) {
|
||||
KeyInput keyInput;
|
||||
@ -383,19 +361,7 @@ extern "C" void Java_com_henrikrydgard_libnative_NativeApp_keyDown(JNIEnv *, jcl
|
||||
keyInput.keyCode = key;
|
||||
keyInput.flags = KEY_DOWN;
|
||||
NativeKey(keyInput);
|
||||
|
||||
// Pad mapping
|
||||
switch (key) {
|
||||
case KEYCODE_BACK: AsyncDown(PAD_BUTTON_BACK); break; // Back
|
||||
case KEYCODE_MENU: AsyncDown(PAD_BUTTON_MENU); break; // Menu
|
||||
case KEYCODE_BUTTON_CROSS_PS3:
|
||||
AsyncDown(PAD_BUTTON_A);
|
||||
break;
|
||||
case KEYCODE_BUTTON_CIRCLE_PS3:
|
||||
AsyncDown(PAD_BUTTON_B);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
g_buttonTracker.Process(keyInput);
|
||||
}
|
||||
|
||||
extern "C" void Java_com_henrikrydgard_libnative_NativeApp_keyUp(JNIEnv *, jclass, jint deviceId, jint key) {
|
||||
@ -404,24 +370,7 @@ extern "C" void Java_com_henrikrydgard_libnative_NativeApp_keyUp(JNIEnv *, jclas
|
||||
keyInput.keyCode = key;
|
||||
keyInput.flags = KEY_UP;
|
||||
NativeKey(keyInput);
|
||||
|
||||
// Pad mapping
|
||||
switch (key) {
|
||||
case KEYCODE_BACK:
|
||||
AsyncUp(PAD_BUTTON_BACK);
|
||||
break; // Back
|
||||
case KEYCODE_MENU:
|
||||
AsyncUp(PAD_BUTTON_MENU);
|
||||
break; // Menu
|
||||
case KEYCODE_BUTTON_CROSS_PS3:
|
||||
AsyncUp(PAD_BUTTON_A);
|
||||
break;
|
||||
case KEYCODE_BUTTON_CIRCLE_PS3:
|
||||
AsyncUp(PAD_BUTTON_B);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
g_buttonTracker.Process(keyInput);
|
||||
}
|
||||
|
||||
extern "C" void Java_com_henrikrydgard_libnative_NativeApp_beginJoystickEvent(
|
||||
|
@ -51,7 +51,7 @@ void LaunchEmail(const char *email_address)
|
||||
|
||||
InputState input_state;
|
||||
|
||||
// Input
|
||||
// Input - urgh, these may collide with the android keycodes when we bring in input/keycodes.h
|
||||
const unsigned int buttonMappings[18] = {
|
||||
KEYCODE_K, //Cross
|
||||
KEYCODE_L, //Circle
|
||||
@ -131,7 +131,7 @@ void BlackberryMain::handleInput(screen_event_t screen_event)
|
||||
if (value == buttonMappings[b] & 0xFF) {
|
||||
if (flags & KEY_DOWN)
|
||||
pad_buttons |= (1<<b);
|
||||
else
|
||||
if (flags & KEY_UP)
|
||||
pad_buttons &= ~(1<<b);
|
||||
}
|
||||
}
|
||||
@ -243,6 +243,8 @@ void BlackberryMain::runMain() {
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO: This is broken. Instead we should just send keyboard events through using NativeKey and not
|
||||
// even bother with these bitfields.
|
||||
input_state.pad_buttons = pad_buttons | controller_buttons;
|
||||
pad_buttons &= ~PAD_BUTTON_MENU;
|
||||
UpdateInputState(&input_state);
|
||||
|
@ -615,6 +615,7 @@ int main(int argc, char *argv[]) {
|
||||
key.keyCode = KeyMapRawSDLtoNative.find(k)->second;
|
||||
key.deviceId = DEVICE_ID_KEYBOARD;
|
||||
NativeKey(key);
|
||||
g_buttonTracker.Process(key);
|
||||
break;
|
||||
}
|
||||
case SDL_KEYUP:
|
||||
@ -625,6 +626,7 @@ int main(int argc, char *argv[]) {
|
||||
key.keyCode = KeyMapRawSDLtoNative.find(k)->second;
|
||||
key.deviceId = DEVICE_ID_KEYBOARD;
|
||||
NativeKey(key);
|
||||
g_buttonTracker.Process(key);
|
||||
break;
|
||||
}
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "input_state.h"
|
||||
#include <iostream>
|
||||
#include "input/input_state.h"
|
||||
#include "input/keycodes.h"
|
||||
|
||||
const char *GetDeviceName(int deviceId) {
|
||||
switch (deviceId) {
|
||||
@ -12,3 +12,64 @@ const char *GetDeviceName(int deviceId) {
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
// Default pad mapping to button bits. Used for UI and stuff that doesn't use PPSSPP's key mapping system.
|
||||
int MapPadButtonFixed(int keycode) {
|
||||
switch (keycode) {
|
||||
case KEYCODE_BACK: return PAD_BUTTON_BACK; // Back
|
||||
case KEYCODE_MENU: return PAD_BUTTON_MENU; // Menu
|
||||
|
||||
case KEYCODE_Z:
|
||||
case KEYCODE_SPACE:
|
||||
case KEYCODE_BUTTON_1:
|
||||
case KEYCODE_BUTTON_A: // same as KEYCODE_OUYA_BUTTON_O and KEYCODE_BUTTON_CROSS_PS3
|
||||
return PAD_BUTTON_A;
|
||||
|
||||
case KEYCODE_ESCAPE:
|
||||
case KEYCODE_BUTTON_2:
|
||||
case KEYCODE_BUTTON_B: // same as KEYCODE_OUYA_BUTTON_A and KEYCODE_BUTTON_CIRCLE_PS3:
|
||||
return PAD_BUTTON_B;
|
||||
|
||||
case KEYCODE_DPAD_LEFT: return PAD_BUTTON_LEFT;
|
||||
case KEYCODE_DPAD_RIGHT: return PAD_BUTTON_RIGHT;
|
||||
case KEYCODE_DPAD_UP: return PAD_BUTTON_UP;
|
||||
case KEYCODE_DPAD_DOWN: return PAD_BUTTON_DOWN;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ButtonTracker::Update(InputState &input_state) {
|
||||
pad_buttons_ |= pad_buttons_async_set;
|
||||
pad_buttons_ &= ~pad_buttons_async_clear;
|
||||
input_state.pad_buttons = pad_buttons_;
|
||||
}
|
||||
|
||||
void ButtonTracker::Process(const KeyInput &input) {
|
||||
int btn = MapPadButtonFixed(input.keyCode);
|
||||
if (btn == 0)
|
||||
return;
|
||||
|
||||
// For now, use a fixed mapping. Good enough for the basics on most platforms.
|
||||
if (input.flags & KEY_DOWN) {
|
||||
pad_buttons_async_set |= btn;
|
||||
pad_buttons_async_clear &= ~btn;
|
||||
}
|
||||
if (input.flags & KEY_UP) {
|
||||
pad_buttons_async_set &= ~btn;
|
||||
pad_buttons_async_clear |= btn;
|
||||
}
|
||||
}
|
||||
|
||||
ButtonTracker g_buttonTracker;
|
||||
|
||||
void UpdateInputState(InputState *input) {
|
||||
g_buttonTracker.Update(*input);
|
||||
input->pad_buttons_down = (input->pad_last_buttons ^ input->pad_buttons) & input->pad_buttons;
|
||||
input->pad_buttons_up = (input->pad_last_buttons ^ input->pad_buttons) & input->pad_last_buttons;
|
||||
}
|
||||
|
||||
void EndInputState(InputState *input) {
|
||||
input->pad_last_buttons = input->pad_buttons;
|
||||
}
|
@ -109,14 +109,8 @@ private:
|
||||
DISALLOW_COPY_AND_ASSIGN(InputState);
|
||||
};
|
||||
|
||||
inline void UpdateInputState(InputState *input) {
|
||||
input->pad_buttons_down = (input->pad_last_buttons ^ input->pad_buttons) & input->pad_buttons;
|
||||
input->pad_buttons_up = (input->pad_last_buttons ^ input->pad_buttons) & input->pad_last_buttons;
|
||||
}
|
||||
|
||||
inline void EndInputState(InputState *input) {
|
||||
input->pad_last_buttons = input->pad_buttons;
|
||||
}
|
||||
void UpdateInputState(InputState *input);
|
||||
void EndInputState(InputState *input);
|
||||
|
||||
enum {
|
||||
TOUCH_MOVE = 1,
|
||||
@ -160,3 +154,25 @@ struct AxisInput {
|
||||
float value;
|
||||
int flags;
|
||||
};
|
||||
|
||||
|
||||
class ButtonTracker {
|
||||
public:
|
||||
ButtonTracker() { Reset(); }
|
||||
void Reset() {
|
||||
pad_buttons_ = 0;
|
||||
pad_buttons_async_set = 0;
|
||||
pad_buttons_async_clear = 0;
|
||||
}
|
||||
void Process(const KeyInput &input);
|
||||
void Update(InputState &input_state);
|
||||
uint32_t GetPadButtons() const { return pad_buttons_; }
|
||||
|
||||
private:
|
||||
uint32_t pad_buttons_;
|
||||
uint32_t pad_buttons_async_set;
|
||||
uint32_t pad_buttons_async_clear;
|
||||
};
|
||||
|
||||
// Platforms should call g_buttonTracker.Process().
|
||||
extern ButtonTracker g_buttonTracker;
|
@ -294,7 +294,7 @@ int UITextureButton(UIContext *ctx, int id, const LayoutManager &layout, float w
|
||||
y += txOffset * 2;
|
||||
}
|
||||
ui_draw2d.DrawImage4Grid(drop_shadow, x - dropsize, y, x+w + dropsize, y+h+dropsize*1.5,
|
||||
alphaMul(color,0.5f), 1.0f);
|
||||
blackAlpha(0.5f), 1.0f);
|
||||
ui_draw2d.Flush(true);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user