mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-28 16:53:40 +01:00
ControlMapper: Allow overriding PSP button event handling through a callback.
This commit is contained in:
1 parent
4739d6c37d
commit
534896d2ab
10 files changed
+27
-8
No files matched your search
@@ -14,6 +14,8 @@
|
||||
#include "Common/Math/lin/matrix4x4.h"
|
||||
|
||||
#include "Core/HLE/sceDisplay.h"
|
||||
#include "Core/HLE/sceCtrl.h"
|
||||
|
||||
#include "Core/Config.h"
|
||||
#include "Core/KeyMap.h"
|
||||
#include "Core/System.h"
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "Common/TimeUtil.h"
|
||||
#include "Common/Log.h"
|
||||
|
||||
#include "Core/HLE/sceCtrl.h"
|
||||
#include "Core/KeyMap.h"
|
||||
#include "Core/ControlMapper.h"
|
||||
#include "Core/Config.h"
|
||||
@@ -40,9 +41,10 @@ void ConvertAnalogStick(float &x, float &y) {
|
||||
y = Clamp(y / norm * mappedNorm, -1.0f, 1.0f);
|
||||
}
|
||||
|
||||
void ControlMapper::SetCallbacks(std::function<void(int)> onVKeyDown, std::function<void(int)> onVKeyUp, std::function<void(int, float, float)> setPSPAnalog) {
|
||||
void ControlMapper::SetCallbacks(std::function<void(int)> onVKeyDown, std::function<void(int)> onVKeyUp, std::function<void(int, bool)> setPSPButtonState, std::function<void(int, float, float)> setPSPAnalog) {
|
||||
onVKeyDown_ = onVKeyDown;
|
||||
onVKeyUp_ = onVKeyUp;
|
||||
setPSPButtonState_ = setPSPButtonState;
|
||||
setPSPAnalog_ = setPSPAnalog;
|
||||
}
|
||||
|
||||
@@ -71,7 +73,6 @@ void ControlMapper::SetPSPAxis(int device, char axis, float value, int stick) {
|
||||
bool inDeadZone = fabsf(value) < g_Config.fAnalogDeadzone * 0.7f;
|
||||
|
||||
bool ignore = false;
|
||||
|
||||
if (inDeadZone && lastNonDeadzoneDeviceID_[stick] != device) {
|
||||
// Ignore this event! See issue #15465
|
||||
ignore = true;
|
||||
@@ -221,9 +222,9 @@ void ControlMapper::pspKey(int deviceId, int pspKeyCode, int flags) {
|
||||
} else {
|
||||
// INFO_LOG(SYSTEM, "pspKey %i %i", pspKeyCode, flags);
|
||||
if (flags & KEY_DOWN)
|
||||
__CtrlButtonDown(pspKeyCode);
|
||||
setPSPButtonState_(pspKeyCode, true);
|
||||
if (flags & KEY_UP)
|
||||
__CtrlButtonUp(pspKeyCode);
|
||||
setPSPButtonState_(pspKeyCode, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,12 +302,12 @@ void ControlMapper::onVKeyUp(int deviceId, int vkey) {
|
||||
|
||||
case VIRTKEY_ANALOG_ROTATE_CW:
|
||||
autoRotatingAnalogCW_ = false;
|
||||
__CtrlSetAnalogXY(0, 0.0f, 0.0f);
|
||||
setPSPAnalog_(0, 0.0f, 0.0f);
|
||||
break;
|
||||
|
||||
case VIRTKEY_ANALOG_ROTATE_CCW:
|
||||
autoRotatingAnalogCCW_ = false;
|
||||
__CtrlSetAnalogXY(0, 0.0f, 0.0f);
|
||||
setPSPAnalog_(0, 0.0f, 0.0f);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@@ -23,6 +23,7 @@ public:
|
||||
void SetCallbacks(
|
||||
std::function<void(int)> onVKeyDown,
|
||||
std::function<void(int)> onVKeyUp,
|
||||
std::function<void(int, bool)> setPSPButtonState,
|
||||
std::function<void(int, float, float)> setPSPAnalog);
|
||||
|
||||
// Optional callback, only used in config
|
||||
@@ -53,6 +54,7 @@ private:
|
||||
bool autoRotatingAnalogCCW_ = false;
|
||||
|
||||
// Callbacks
|
||||
std::function<void(int, bool)> setPSPButtonState_;
|
||||
std::function<void(int)> onVKeyDown_;
|
||||
std::function<void(int)> onVKeyUp_;
|
||||
std::function<void(int, float, float)> setPSPAnalog_;
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/Swap.h"
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "Common/Log.h"
|
||||
#include "Common/StringUtils.h"
|
||||
#include "Core/HLE/sceUtility.h"
|
||||
#include "Core/HLE/sceCtrl.h" // psp keys
|
||||
#include "Core/Config.h"
|
||||
#include "Core/KeyMap.h"
|
||||
#include "Core/KeyMapDefaults.h"
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
#include "Common/Input/InputState.h" // KeyDef
|
||||
#include "Common/Input/KeyCodes.h" // keyboard keys
|
||||
#include "Core/HLE/sceCtrl.h" // psp keys
|
||||
#include "Core/KeyMapDefaults.h"
|
||||
|
||||
#define KEYMAP_ERROR_KEY_ALREADY_USED -1
|
||||
|
||||
@@ -448,7 +448,11 @@ void KeyMappingNewMouseKeyDialog::axis(const AxisInput &axis) {
|
||||
}
|
||||
|
||||
AnalogSetupScreen::AnalogSetupScreen(const Path &gamePath) : UIDialogScreenWithGameBackground(gamePath) {
|
||||
mapper_.SetCallbacks([](int vkey) {}, [](int vkey) {}, [&](int stick, float x, float y) {
|
||||
mapper_.SetCallbacks(
|
||||
[](int vkey) {},
|
||||
[](int vkey) {},
|
||||
[&](int button, bool down) {},
|
||||
[&](int stick, float x, float y) {
|
||||
analogX_[stick] = x;
|
||||
analogY_[stick] = y;
|
||||
});
|
||||
|
||||
@@ -178,6 +178,13 @@ EmuScreen::EmuScreen(const Path &filename)
|
||||
controlMapper_.SetCallbacks(
|
||||
std::bind(&EmuScreen::onVKeyDown, this, _1),
|
||||
std::bind(&EmuScreen::onVKeyUp, this, _1),
|
||||
[](int pspKey, bool down) {
|
||||
if (down) {
|
||||
__CtrlButtonDown(pspKey);
|
||||
} else {
|
||||
__CtrlButtonUp(pspKey);
|
||||
}
|
||||
},
|
||||
&SetPSPAnalog);
|
||||
|
||||
// Make sure we don't leave it at powerdown after the last game.
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "Common/UI/View.h"
|
||||
#include "Common/UI/ViewGroup.h"
|
||||
#include "Core/CoreParameter.h"
|
||||
#include "Core/HLE/sceCtrl.h"
|
||||
#include "UI/EmuScreen.h"
|
||||
|
||||
class GamepadView : public UI::View {
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
#include "Common/StringUtils.h"
|
||||
#include "Core/System.h"
|
||||
#include "Core/Reporting.h"
|
||||
#include "Core/HLE/sceCtrl.h"
|
||||
#include "Core/ELF/PBPReader.h"
|
||||
#include "Core/ELF/ParamSFO.h"
|
||||
#include "Core/Util/GameManager.h"
|
||||
|
||||
Reference in new issue
Block a user