Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Left/right gesture separation #18043

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Left and right gesture support
  • Loading branch information
iota97 committed Sep 1, 2023
commit 4bbc176592c928c79ffef85ae332c99def567fb3
22 changes: 22 additions & 0 deletions Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,28 @@ static const ConfigSetting controlSettings[] = {

ConfigSetting("AnalogGesture", &g_Config.bAnalogGesture, false, CfgFlag::PER_GAME),
ConfigSetting("AnalogGestureSensibility", &g_Config.fAnalogGestureSensibility, 1.0f, CfgFlag::PER_GAME),

ConfigSetting("SwipeUpLeft", &g_Config.iSwipeUpLeft, 0, CfgFlag::PER_GAME),
ConfigSetting("SwipeDownLeft", &g_Config.iSwipeDownLeft, 0, CfgFlag::PER_GAME),
ConfigSetting("SwipeLeftLeft", &g_Config.iSwipeLeftLeft, 0, CfgFlag::PER_GAME),
ConfigSetting("SwipeRightLeft", &g_Config.iSwipeRightLeft, 0, CfgFlag::PER_GAME),
ConfigSetting("SwipeSensitivityLeft", &g_Config.fSwipeSensitivityLeft, 1.0f, CfgFlag::PER_GAME),
ConfigSetting("SwipeSmoothingLeft", &g_Config.fSwipeSmoothingLeft, 0.3f, CfgFlag::PER_GAME),
ConfigSetting("DoubleTapGestureLeft", &g_Config.iDoubleTapGestureLeft, 0, CfgFlag::PER_GAME),
ConfigSetting("GestureControlEnabledLeft", &g_Config.bGestureControlEnabledLeft, false, CfgFlag::PER_GAME),
ConfigSetting("AnalogGestureLeft", &g_Config.bAnalogGestureLeft, false, CfgFlag::PER_GAME),
ConfigSetting("AnalogGestureSensibilityLeft", &g_Config.fAnalogGestureSensibilityLeft, 1.0f, CfgFlag::PER_GAME),

ConfigSetting("SwipeUpRight", &g_Config.iSwipeUpRight, 0, CfgFlag::PER_GAME),
ConfigSetting("SwipeDownRight", &g_Config.iSwipeDownRight, 0, CfgFlag::PER_GAME),
ConfigSetting("SwipeLeftRight", &g_Config.iSwipeLeftRight, 0, CfgFlag::PER_GAME),
ConfigSetting("SwipeRightRight", &g_Config.iSwipeRightRight, 0, CfgFlag::PER_GAME),
ConfigSetting("SwipeSensitivityRight", &g_Config.fSwipeSensitivityRight, 1.0f, CfgFlag::PER_GAME),
ConfigSetting("SwipeSmoothingRight", &g_Config.fSwipeSmoothingRight, 0.3f, CfgFlag::PER_GAME),
ConfigSetting("DoubleTapGestureRight", &g_Config.iDoubleTapGestureRight, 0, CfgFlag::PER_GAME),
ConfigSetting("GestureControlEnabledRight", &g_Config.bGestureControlEnabledRight, false, CfgFlag::PER_GAME),
ConfigSetting("AnalogGestureRight", &g_Config.bAnalogGestureRight, false, CfgFlag::PER_GAME),
ConfigSetting("AnalogGestureSensibilityRight", &g_Config.fAnalogGestureSensibilityRight, 1.0f, CfgFlag::PER_GAME),
};

static const ConfigSetting networkSettings[] = {
Expand Down
22 changes: 22 additions & 0 deletions Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,28 @@ struct Config {
bool bAnalogGesture;
float fAnalogGestureSensibility;

bool bGestureControlEnabledLeft;
int iSwipeUpLeft;
int iSwipeDownLeft;
int iSwipeLeftLeft;
int iSwipeRightLeft;
float fSwipeSensitivityLeft;
float fSwipeSmoothingLeft;
int iDoubleTapGestureLeft;
bool bAnalogGestureLeft;
float fAnalogGestureSensibilityLeft;

bool bGestureControlEnabledRight;
int iSwipeUpRight;
int iSwipeDownRight;
int iSwipeLeftRight;
int iSwipeRightRight;
float fSwipeSensitivityRight;
float fSwipeSmoothingRight;
int iDoubleTapGestureRight;
bool bAnalogGestureRight;
float fAnalogGestureSensibilityRight;

// Disable diagonals
bool bDisableDpadDiagonals;
bool bGamepadOnlyFocused;
Expand Down
115 changes: 115 additions & 0 deletions UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2133,6 +2133,41 @@ void GestureMappingScreen::CreateViews() {
LinearLayout *vert = rightPanel->Add(new LinearLayout(ORIENT_VERTICAL, new LayoutParams(FILL_PARENT, FILL_PARENT)));
vert->SetSpacing(0);

Choice *global = vert->Add(new Choice(co->T("Global gesture mapping")));
global->OnClick.Add([=](EventParams &e) {
screenManager()->push(new GestureMappingGlobalScreen(gamePath_));
return UI::EVENT_DONE;
});

Choice *left = vert->Add(new Choice(co->T("Left side gesture mapping")));
left->OnClick.Add([=](EventParams &e) {
screenManager()->push(new GestureMappingLeftScreen(gamePath_));
return UI::EVENT_DONE;
});

Choice *right = vert->Add(new Choice(co->T("Right side gesture mapping")));
right->OnClick.Add([=](EventParams &e) {
screenManager()->push(new GestureMappingRightScreen(gamePath_));
return UI::EVENT_DONE;
});
}

void GestureMappingGlobalScreen::CreateViews() {
using namespace UI;

auto di = GetI18NCategory(I18NCat::DIALOG);
auto co = GetI18NCategory(I18NCat::CONTROLS);
auto mc = GetI18NCategory(I18NCat::MAPPABLECONTROLS);

root_ = new AnchorLayout(new LayoutParams(FILL_PARENT, FILL_PARENT));
AddStandardBack(root_);
TabHolder *tabHolder = new TabHolder(ORIENT_VERTICAL, 200, new AnchorLayoutParams(10, 0, 10, 0, false));
root_->Add(tabHolder);
ScrollView *rightPanel = new ScrollView(ORIENT_VERTICAL);
tabHolder->AddTab(co->T("Gesture"), rightPanel);
LinearLayout *vert = rightPanel->Add(new LinearLayout(ORIENT_VERTICAL, new LayoutParams(FILL_PARENT, FILL_PARENT)));
vert->SetSpacing(0);

static const char *gestureButton[ARRAY_SIZE(GestureKey::keyList)+1];
gestureButton[0] = "None";
for (int i = 1; i < ARRAY_SIZE(gestureButton); ++i) {
Expand All @@ -2157,6 +2192,86 @@ void GestureMappingScreen::CreateViews() {
vert->Add(new PopupSliderChoiceFloat(&g_Config.fAnalogGestureSensibility, 0.01f, 5.0f, 1.0f, co->T("Sensitivity"), 0.01f, screenManager(), "x"))->SetEnabledPtr(&g_Config.bAnalogGesture);
}

void GestureMappingLeftScreen::CreateViews() {
using namespace UI;

auto di = GetI18NCategory(I18NCat::DIALOG);
auto co = GetI18NCategory(I18NCat::CONTROLS);
auto mc = GetI18NCategory(I18NCat::MAPPABLECONTROLS);

root_ = new AnchorLayout(new LayoutParams(FILL_PARENT, FILL_PARENT));
AddStandardBack(root_);
TabHolder *tabHolder = new TabHolder(ORIENT_VERTICAL, 200, new AnchorLayoutParams(10, 0, 10, 0, false));
root_->Add(tabHolder);
ScrollView *rightPanel = new ScrollView(ORIENT_VERTICAL);
tabHolder->AddTab(co->T("Gesture"), rightPanel);
LinearLayout *vert = rightPanel->Add(new LinearLayout(ORIENT_VERTICAL, new LayoutParams(FILL_PARENT, FILL_PARENT)));
vert->SetSpacing(0);

static const char *gestureButton[ARRAY_SIZE(GestureKey::keyList)+1];
gestureButton[0] = "None";
for (int i = 1; i < ARRAY_SIZE(gestureButton); ++i) {
gestureButton[i] = KeyMap::GetPspButtonNameCharPointer(GestureKey::keyList[i-1]);
}

vert->Add(new CheckBox(&g_Config.bGestureControlEnabledLeft, co->T("Enable gesture control - left side")));

vert->Add(new ItemHeader(co->T("Swipe")));
vert->Add(new PopupMultiChoice(&g_Config.iSwipeUpLeft, mc->T("Swipe Up"), gestureButton, 0, ARRAY_SIZE(gestureButton), I18NCat::MAPPABLECONTROLS, screenManager()))->SetEnabledPtr(&g_Config.bGestureControlEnabledLeft);
vert->Add(new PopupMultiChoice(&g_Config.iSwipeDownLeft, mc->T("Swipe Down"), gestureButton, 0, ARRAY_SIZE(gestureButton), I18NCat::MAPPABLECONTROLS, screenManager()))->SetEnabledPtr(&g_Config.bGestureControlEnabledLeft);
vert->Add(new PopupMultiChoice(&g_Config.iSwipeLeftLeft, mc->T("Swipe Left"), gestureButton, 0, ARRAY_SIZE(gestureButton), I18NCat::MAPPABLECONTROLS, screenManager()))->SetEnabledPtr(&g_Config.bGestureControlEnabledLeft);
vert->Add(new PopupMultiChoice(&g_Config.iSwipeRightLeft, mc->T("Swipe Right"), gestureButton, 0, ARRAY_SIZE(gestureButton), I18NCat::MAPPABLECONTROLS, screenManager()))->SetEnabledPtr(&g_Config.bGestureControlEnabledLeft);
vert->Add(new PopupSliderChoiceFloat(&g_Config.fSwipeSensitivityLeft, 0.01f, 1.0f, 1.0f, co->T("Swipe sensitivity"), 0.01f, screenManager(), "x"))->SetEnabledPtr(&g_Config.bGestureControlEnabledLeft);
vert->Add(new PopupSliderChoiceFloat(&g_Config.fSwipeSmoothingLeft, 0.0f, 0.95f, 0.3f, co->T("Swipe smoothing"), 0.05f, screenManager(), "x"))->SetEnabledPtr(&g_Config.bGestureControlEnabledLeft);

vert->Add(new ItemHeader(co->T("Double tap")));
vert->Add(new PopupMultiChoice(&g_Config.iDoubleTapGestureLeft, mc->T("Double tap button"), gestureButton, 0, ARRAY_SIZE(gestureButton), I18NCat::MAPPABLECONTROLS, screenManager()))->SetEnabledPtr(&g_Config.bGestureControlEnabledLeft);

vert->Add(new ItemHeader(co->T("Analog Stick")));
vert->Add(new CheckBox(&g_Config.bAnalogGestureLeft, co->T("Enable analog stick gesture")));
vert->Add(new PopupSliderChoiceFloat(&g_Config.fAnalogGestureSensibilityLeft, 0.01f, 5.0f, 1.0f, co->T("Sensitivity"), 0.01f, screenManager(), "x"))->SetEnabledPtr(&g_Config.bAnalogGestureLeft);
}

void GestureMappingRightScreen::CreateViews() {
using namespace UI;

auto di = GetI18NCategory(I18NCat::DIALOG);
auto co = GetI18NCategory(I18NCat::CONTROLS);
auto mc = GetI18NCategory(I18NCat::MAPPABLECONTROLS);

root_ = new AnchorLayout(new LayoutParams(FILL_PARENT, FILL_PARENT));
AddStandardBack(root_);
TabHolder *tabHolder = new TabHolder(ORIENT_VERTICAL, 200, new AnchorLayoutParams(10, 0, 10, 0, false));
root_->Add(tabHolder);
ScrollView *rightPanel = new ScrollView(ORIENT_VERTICAL);
tabHolder->AddTab(co->T("Gesture"), rightPanel);
LinearLayout *vert = rightPanel->Add(new LinearLayout(ORIENT_VERTICAL, new LayoutParams(FILL_PARENT, FILL_PARENT)));
vert->SetSpacing(0);

static const char *gestureButton[ARRAY_SIZE(GestureKey::keyList)+1];
gestureButton[0] = "None";
for (int i = 1; i < ARRAY_SIZE(gestureButton); ++i) {
gestureButton[i] = KeyMap::GetPspButtonNameCharPointer(GestureKey::keyList[i-1]);
}

vert->Add(new CheckBox(&g_Config.bGestureControlEnabledRight, co->T("Enable gesture control")));

vert->Add(new ItemHeader(co->T("Swipe")));
vert->Add(new PopupMultiChoice(&g_Config.iSwipeUpRight, mc->T("Swipe Up"), gestureButton, 0, ARRAY_SIZE(gestureButton), I18NCat::MAPPABLECONTROLS, screenManager()))->SetEnabledPtr(&g_Config.bGestureControlEnabledRight);
vert->Add(new PopupMultiChoice(&g_Config.iSwipeDownRight, mc->T("Swipe Down"), gestureButton, 0, ARRAY_SIZE(gestureButton), I18NCat::MAPPABLECONTROLS, screenManager()))->SetEnabledPtr(&g_Config.bGestureControlEnabledRight);
vert->Add(new PopupMultiChoice(&g_Config.iSwipeLeftRight, mc->T("Swipe Left"), gestureButton, 0, ARRAY_SIZE(gestureButton), I18NCat::MAPPABLECONTROLS, screenManager()))->SetEnabledPtr(&g_Config.bGestureControlEnabledRight);
vert->Add(new PopupMultiChoice(&g_Config.iSwipeRightRight, mc->T("Swipe Right"), gestureButton, 0, ARRAY_SIZE(gestureButton), I18NCat::MAPPABLECONTROLS, screenManager()))->SetEnabledPtr(&g_Config.bGestureControlEnabledRight);
vert->Add(new PopupSliderChoiceFloat(&g_Config.fSwipeSensitivityRight, 0.01f, 1.0f, 1.0f, co->T("Swipe sensitivity"), 0.01f, screenManager(), "x"))->SetEnabledPtr(&g_Config.bGestureControlEnabledRight);
vert->Add(new PopupSliderChoiceFloat(&g_Config.fSwipeSmoothingRight, 0.0f, 0.95f, 0.3f, co->T("Swipe smoothing"), 0.05f, screenManager(), "x"))->SetEnabledPtr(&g_Config.bGestureControlEnabledRight);

vert->Add(new ItemHeader(co->T("Double tap")));
vert->Add(new PopupMultiChoice(&g_Config.iDoubleTapGestureRight, mc->T("Double tap button"), gestureButton, 0, ARRAY_SIZE(gestureButton), I18NCat::MAPPABLECONTROLS, screenManager()))->SetEnabledPtr(&g_Config.bGestureControlEnabledRight);

vert->Add(new ItemHeader(co->T("Analog Stick")));
vert->Add(new CheckBox(&g_Config.bAnalogGestureRight, co->T("Enable analog stick gesture")));
vert->Add(new PopupSliderChoiceFloat(&g_Config.fAnalogGestureSensibilityRight, 0.01f, 5.0f, 1.0f, co->T("Sensitivity"), 0.01f, screenManager(), "x"))->SetEnabledPtr(&g_Config.bAnalogGestureRight);
}

RestoreSettingsScreen::RestoreSettingsScreen(const char *title)
: PopupScreen(title, "OK", "Cancel") {}

Expand Down
24 changes: 24 additions & 0 deletions UI/GameSettingsScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,30 @@ class GestureMappingScreen : public UIDialogScreenWithGameBackground {
const char *tag() const override { return "GestureMapping"; }
};

class GestureMappingGlobalScreen : public UIDialogScreenWithGameBackground {
public:
GestureMappingGlobalScreen(const Path &gamePath) : UIDialogScreenWithGameBackground(gamePath) {}
void CreateViews() override;

const char *tag() const override { return "GestureMapping global"; }
};

class GestureMappingLeftScreen : public UIDialogScreenWithGameBackground {
public:
GestureMappingLeftScreen(const Path &gamePath) : UIDialogScreenWithGameBackground(gamePath) {}
void CreateViews() override;

const char *tag() const override { return "GestureMapping left"; }
};

class GestureMappingRightScreen : public UIDialogScreenWithGameBackground {
public:
GestureMappingRightScreen(const Path &gamePath) : UIDialogScreenWithGameBackground(gamePath) {}
void CreateViews() override;

const char *tag() const override { return "GestureMapping right"; }
};

class RestoreSettingsScreen : public PopupScreen {
public:
RestoreSettingsScreen(const char *title);
Expand Down
14 changes: 13 additions & 1 deletion UI/GamepadEmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -872,9 +872,17 @@ UI::ViewGroup *CreatePadLayout(float xres, float yres, bool *pause, bool showPau
}

if (g_Config.bGestureControlEnabled)
root->Add(new GestureGamepad(controllMapper, g_Config.iDoubleTapGesture, g_Config.bAnalogGesture, g_Config.fAnalogGestureSensibility,
root->Add(new GestureGamepad(controllMapper, GestureArea::GLOBAL, g_Config.iDoubleTapGesture, g_Config.bAnalogGesture, g_Config.fAnalogGestureSensibility,
g_Config.fSwipeSensitivity, g_Config.fSwipeSmoothing, g_Config.iSwipeRight, g_Config.iSwipeDown, g_Config.iSwipeLeft, g_Config.iSwipeUp));

if (g_Config.bGestureControlEnabledLeft)
root->Add(new GestureGamepad(controllMapper, GestureArea::LEFT, g_Config.iDoubleTapGestureLeft, g_Config.bAnalogGestureLeft, g_Config.fAnalogGestureSensibilityLeft,
g_Config.fSwipeSensitivityLeft, g_Config.fSwipeSmoothingLeft, g_Config.iSwipeRightLeft, g_Config.iSwipeDownLeft, g_Config.iSwipeLeftLeft, g_Config.iSwipeUpLeft));

if (g_Config.bGestureControlEnabledRight)
root->Add(new GestureGamepad(controllMapper, GestureArea::RIGHT, g_Config.iDoubleTapGestureRight, g_Config.bAnalogGestureRight, g_Config.fAnalogGestureSensibilityRight,
g_Config.fSwipeSensitivityRight, g_Config.fSwipeSmoothingRight, g_Config.iSwipeRightRight, g_Config.iSwipeDownRight, g_Config.iSwipeLeftRight, g_Config.iSwipeUpRight));

return root;
}

Expand All @@ -891,6 +899,10 @@ bool GestureGamepad::Touch(const TouchInput &input) {
}

if (input.flags & TOUCH_DOWN) {
if ((area_ == GestureArea::LEFT && input.x > g_display.pixel_xres*0.5f) || (area_ == GestureArea::RIGHT && input.x < g_display.pixel_xres*0.5f)) {
return false;
}

if (dragPointerId_ == -1) {
dragPointerId_ = input.id;
lastX_ = input.x;
Expand Down
11 changes: 9 additions & 2 deletions UI/GamepadEmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,17 @@ class CustomButton : public MultiTouchButton {
bool invertedContextDimension_; // Swap width and height
};

enum class GestureArea {
GLOBAL,
LEFT,
RIGHT,
};

class GestureGamepad : public UI::View {
public:
GestureGamepad(ControlMapper* controllMapper, int doubleTapGesture, bool analogGesture,
GestureGamepad(ControlMapper* controllMapper, GestureArea area, int doubleTapGesture, bool analogGesture,
float analogGestureSensibility, float swipeSensitivity, float swipeSmoothing,
int swipeRight, int swipeDown, int swipeLeft, int swipeUp) : controlMapper_(controllMapper),
int swipeRight, int swipeDown, int swipeLeft, int swipeUp) : controlMapper_(controllMapper), area_(area),
doubleTapGesture_(doubleTapGesture), analogGesture_(analogGesture),
analogGestureSensibility_(analogGestureSensibility), swipeSensitivity_(swipeSensitivity), swipeSmoothing_(swipeSmoothing),
swipeRight_(swipeRight), swipeDown_(swipeDown), swipeLeft_(swipeLeft), swipeUp_(swipeUp) {}
Expand All @@ -207,6 +213,7 @@ class GestureGamepad : public UI::View {
void Draw(UIContext &dc) override;

protected:
GestureArea area_;
int doubleTapGesture_;
bool analogGesture_;
float analogGestureSensibility_;
Expand Down