Analog stick gesture

This commit is contained in:
iota97 committed 2023-09-01 09:32:21 +02:00
1 parent 2260b194e7
commit 01083c87ea
5 files changed
+39 -1

No files matched your search

+3
View File
@@ -804,6 +804,9 @@ static const ConfigSetting controlSettings[] = {
ConfigSetting("SystemControls", &g_Config.bSystemControls, true, CfgFlag::DEFAULT),
ConfigSetting("RapidFileInterval", &g_Config.iRapidFireInterval, 5, CfgFlag::DEFAULT),
ConfigSetting("AnalogGesture", &g_Config.bAnalogGesture, false, CfgFlag::PER_GAME),
ConfigSetting("AnalogGestureSensibility", &g_Config.fAnalogGestureSensibility, 1.0f, CfgFlag::PER_GAME),
};
static const ConfigSetting networkSettings[] = {
+2
View File
@@ -298,6 +298,8 @@ public:
float fSwipeSensitivity;
float fSwipeSmoothing;
int iDoubleTapGesture;
bool bAnalogGesture;
float fAnalogGestureSensibility;
// Disable diagonals
bool bDisableDpadDiagonals;
+4
View File
@@ -2151,6 +2151,10 @@ void GestureMappingScreen::CreateViews() {
vert->Add(new ItemHeader(co->T("Double tap")));
vert->Add(new PopupMultiChoice(&g_Config.iDoubleTapGesture, mc->T("Double tap button"), gestureButton, 0, ARRAY_SIZE(gestureButton), I18NCat::MAPPABLECONTROLS, screenManager()))->SetEnabledPtr(&g_Config.bGestureControlEnabled);
vert->Add(new ItemHeader(co->T("Analog Stick")));
vert->Add(new CheckBox(&g_Config.bAnalogGesture, co->T("Enable analog stick gesture")));
vert->Add(new PopupSliderChoiceFloat(&g_Config.fAnalogGestureSensibility, 0.01f, 5.0f, 1.0f, co->T("Sensitivity"), 0.01f, screenManager(), "x"))->SetEnabledPtr(&g_Config.bAnalogGesture);
}
RestoreSettingsScreen::RestoreSettingsScreen(const char *title)
+27 -1
View File
@@ -894,7 +894,8 @@ bool GestureGamepad::Touch(const TouchInput &input) {
dragPointerId_ = input.id;
lastX_ = input.x;
lastY_ = input.y;
downX_ = input.x;
downY_ = input.y;
const float now = time_now_d();
if (now - lastTapRelease_ < 0.3f && !haveDoubleTapped_) {
if (g_Config.iDoubleTapGesture != 0 )
@@ -911,6 +912,15 @@ bool GestureGamepad::Touch(const TouchInput &input) {
deltaY_ += input.y - lastY_;
lastX_ = input.x;
lastY_ = input.y;
if (g_Config.bAnalogGesture) {
const float k = g_Config.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));
dy = std::min(1.0f, std::max(-1.0f, dy));
__CtrlSetAnalogXY(0, dx, -dy);
}
}
}
if (input.flags & TOUCH_UP) {
@@ -924,11 +934,27 @@ bool GestureGamepad::Touch(const TouchInput &input) {
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[g_Config.iDoubleTapGesture-1], KEY_UP);
haveDoubleTapped_ = false;
}
if (g_Config.bAnalogGesture)
__CtrlSetAnalogXY(0, 0, 0);
}
}
return true;
}
void GestureGamepad::Draw(UIContext &dc) {
float opacity = g_Config.iTouchButtonOpacity / 100.0;
if (opacity <= 0.0f)
return;
uint32_t colorBg = colorAlpha(GetButtonColor(), opacity);
if (g_Config.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;
+3
View File
@@ -199,6 +199,7 @@ public:
bool Touch(const TouchInput &input) override;
void Update() override;
void Draw(UIContext &dc) override;
protected:
@@ -206,6 +207,8 @@ protected:
float lastY_ = 0.0f;
float deltaX_ = 0.0f;
float deltaY_ = 0.0f;
float downX_;
float downY_;
float lastTapRelease_ = 0.0f;
float lastTouchDown_ = 0.0f;
int dragPointerId_ = -1;