Prepare for multiple gesture mapping zones

This commit is contained in:
Henrik Rydgård committed 2026-02-04 15:01:06 +01:00
1 parent 8282bd0f3b
commit 03c901d0cc
8 files changed
+104 -63

No files matched your search

+33 -25
View File
@@ -1029,7 +1029,7 @@ GamepadEmuView::GamepadEmuView(const TouchControlConfig &config, float xres, flo
addCustomButton(g_Config.CustomButton[i], temp, config.touchCustom[i]);
}
if (g_Config.bGestureControlEnabled) {
if (g_Config.gestureControlsZone1.bGestureControlEnabled) {
Add(new GestureGamepad(controlMapper));
}
}
@@ -1053,7 +1053,14 @@ void GamepadEmuView::Update() {
}
}
const GestureControlConfig &GestureGamepad::GetZone() {
// TODO: Add support for multiple zones.
return g_Config.gestureControlsZone1;
}
bool GestureGamepad::Touch(const TouchInput &input) {
const GestureControlConfig &zone = GetZone();
if (usedPointerMask & (1 << input.id)) {
if (input.id == dragPointerId_)
dragPointerId_ = -1;
@@ -1074,8 +1081,8 @@ bool GestureGamepad::Touch(const TouchInput &input) {
downY_ = input.y;
const float now = time_now_d();
if (now - lastTapRelease_ < 0.3f && !haveDoubleTapped_) {
if (g_Config.iDoubleTapGesture != 0 )
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[g_Config.iDoubleTapGesture-1], KeyInputFlags::DOWN);
if (zone.iDoubleTapGesture != 0 )
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[zone.iDoubleTapGesture - 1], KeyInputFlags::DOWN);
haveDoubleTapped_ = true;
}
@@ -1089,8 +1096,8 @@ bool GestureGamepad::Touch(const TouchInput &input) {
lastX_ = input.x;
lastY_ = input.y;
if (g_Config.bAnalogGesture) {
const float k = g_Config.fAnalogGestureSensibility * 0.02;
if (zone.bAnalogGesture) {
const float k = zone.fAnalogGestureSensibility * 0.02;
float dx = (input.x - downX_)*g_display.dpi_scale_x * k;
float dy = (input.y - downY_)*g_display.dpi_scale_y * k;
dx = std::min(1.0f, std::max(-1.0f, dx));
@@ -1106,12 +1113,12 @@ bool GestureGamepad::Touch(const TouchInput &input) {
lastTapRelease_ = time_now_d();
if (haveDoubleTapped_) {
if (g_Config.iDoubleTapGesture != 0)
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[g_Config.iDoubleTapGesture-1], KeyInputFlags::UP);
if (zone.iDoubleTapGesture != 0)
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[zone.iDoubleTapGesture - 1], KeyInputFlags::UP);
haveDoubleTapped_ = false;
}
if (g_Config.bAnalogGesture)
if (zone.bAnalogGesture)
__CtrlSetAnalogXY(0, 0, 0);
}
}
@@ -1125,51 +1132,52 @@ void GestureGamepad::Draw(UIContext &dc) {
uint32_t colorBg = colorAlpha(GetButtonColor(), opacity);
if (g_Config.bAnalogGesture && dragPointerId_ != -1) {
if (GetZone().bAnalogGesture && dragPointerId_ != -1) {
dc.Draw()->DrawImage(ImageID("I_CIRCLE"), downX_, downY_, 0.7f, colorBg, ALIGN_CENTER);
}
}
void GestureGamepad::Update() {
const float th = 1.0f;
float dx = deltaX_ * g_display.dpi_scale_x * g_Config.fSwipeSensitivity;
float dy = deltaY_ * g_display.dpi_scale_y * g_Config.fSwipeSensitivity;
if (g_Config.iSwipeRight != 0) {
float dx = deltaX_ * g_display.dpi_scale_x * GetZone().fSwipeSensitivity;
float dy = deltaY_ * g_display.dpi_scale_y * GetZone().fSwipeSensitivity;
if (GetZone().iSwipeRight != 0) {
if (dx > th) {
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[g_Config.iSwipeRight-1], KeyInputFlags::DOWN);
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[GetZone().iSwipeRight - 1], KeyInputFlags::DOWN);
swipeRightReleased_ = false;
} else if (!swipeRightReleased_) {
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[g_Config.iSwipeRight-1], KeyInputFlags::UP);
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[GetZone().iSwipeRight -1], KeyInputFlags::UP);
swipeRightReleased_ = true;
}
}
if (g_Config.iSwipeLeft != 0) {
if (GetZone().iSwipeLeft != 0) {
if (dx < -th) {
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[g_Config.iSwipeLeft-1], KeyInputFlags::DOWN);
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[GetZone().iSwipeLeft - 1], KeyInputFlags::DOWN);
swipeLeftReleased_ = false;
} else if (!swipeLeftReleased_) {
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[g_Config.iSwipeLeft-1], KeyInputFlags::UP);
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[GetZone().iSwipeLeft - 1], KeyInputFlags::UP);
swipeLeftReleased_ = true;
}
}
if (g_Config.iSwipeUp != 0) {
if (GetZone().iSwipeUp != 0) {
if (dy < -th) {
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[g_Config.iSwipeUp-1], KeyInputFlags::DOWN);
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[GetZone().iSwipeUp - 1], KeyInputFlags::DOWN);
swipeUpReleased_ = false;
} else if (!swipeUpReleased_) {
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[g_Config.iSwipeUp-1], KeyInputFlags::UP);
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[GetZone().iSwipeUp - 1], KeyInputFlags::UP);
swipeUpReleased_ = true;
}
}
if (g_Config.iSwipeDown != 0) {
if (GetZone().iSwipeDown != 0) {
if (dy > th) {
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[g_Config.iSwipeDown-1], KeyInputFlags::DOWN);
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[GetZone().iSwipeDown - 1], KeyInputFlags::DOWN);
swipeDownReleased_ = false;
} else if (!swipeDownReleased_) {
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[g_Config.iSwipeDown-1], KeyInputFlags::UP);
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[GetZone().iSwipeDown - 1], KeyInputFlags::UP);
swipeDownReleased_ = true;
}
}
deltaX_ *= g_Config.fSwipeSmoothing;
deltaY_ *= g_Config.fSwipeSmoothing;
const float smoothing = GetZone().fSwipeSmoothing;
deltaX_ *= smoothing;
deltaY_ *= smoothing;
}