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 all commits
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
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
63 changes: 38 additions & 25 deletions UI/GamepadEmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,16 @@ UI::ViewGroup *CreatePadLayout(float xres, float yres, bool *pause, bool showPau
}

if (g_Config.bGestureControlEnabled)
root->Add(new GestureGamepad(controllMapper));
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 @@ -890,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 All @@ -898,8 +911,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], KEY_DOWN);
if (doubleTapGesture_ != 0 )
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[doubleTapGesture_-1], KEY_DOWN);
haveDoubleTapped_ = true;
}

Expand All @@ -913,8 +926,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 (analogGesture_) {
const float k = analogGestureSensibility_ * 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));
Expand All @@ -930,12 +943,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], KEY_UP);
if (doubleTapGesture_ != 0)
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[doubleTapGesture_-1], KEY_UP);
haveDoubleTapped_ = false;
}

if (g_Config.bAnalogGesture)
if (analogGesture_)
__CtrlSetAnalogXY(0, 0, 0);
}
}
Expand All @@ -949,52 +962,52 @@ void GestureGamepad::Draw(UIContext &dc) {

uint32_t colorBg = colorAlpha(GetButtonColor(), opacity);

if (g_Config.bAnalogGesture && dragPointerId_ != -1) {
if (analogGesture_ && 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 * swipeSensitivity_;
float dy = deltaY_ * g_display.dpi_scale_y * swipeSensitivity_;
if (swipeRight_ != 0) {
if (dx > th) {
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[g_Config.iSwipeRight-1], KEY_DOWN);
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[swipeRight_-1], KEY_DOWN);
swipeRightReleased_ = false;
} else if (!swipeRightReleased_) {
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[g_Config.iSwipeRight-1], KEY_UP);
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[swipeRight_-1], KEY_UP);
swipeRightReleased_ = true;
}
}
if (g_Config.iSwipeLeft != 0) {
if (swipeLeft_ != 0) {
if (dx < -th) {
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[g_Config.iSwipeLeft-1], KEY_DOWN);
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[swipeLeft_-1], KEY_DOWN);
swipeLeftReleased_ = false;
} else if (!swipeLeftReleased_) {
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[g_Config.iSwipeLeft-1], KEY_UP);
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[swipeLeft_-1], KEY_UP);
swipeLeftReleased_ = true;
}
}
if (g_Config.iSwipeUp != 0) {
if (swipeUp_ != 0) {
if (dy < -th) {
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[g_Config.iSwipeUp-1], KEY_DOWN);
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[swipeUp_-1], KEY_DOWN);
swipeUpReleased_ = false;
} else if (!swipeUpReleased_) {
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[g_Config.iSwipeUp-1], KEY_UP);
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[swipeUp_-1], KEY_UP);
swipeUpReleased_ = true;
}
}
if (g_Config.iSwipeDown != 0) {
if (swipeDown_ != 0) {
if (dy > th) {
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[g_Config.iSwipeDown-1], KEY_DOWN);
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[swipeDown_-1], KEY_DOWN);
swipeDownReleased_ = false;
} else if (!swipeDownReleased_) {
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[g_Config.iSwipeDown-1], KEY_UP);
controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[swipeDown_-1], KEY_UP);
swipeDownReleased_ = true;
}
}
deltaX_ *= g_Config.fSwipeSmoothing;
deltaY_ *= g_Config.fSwipeSmoothing;
deltaX_ *= swipeSmoothing_;
deltaY_ *= swipeSmoothing_;
}
23 changes: 22 additions & 1 deletion UI/GamepadEmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,36 @@ 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) : controlMapper_(controllMapper) {};
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), area_(area),
doubleTapGesture_(doubleTapGesture), analogGesture_(analogGesture),
analogGestureSensibility_(analogGestureSensibility), swipeSensitivity_(swipeSensitivity), swipeSmoothing_(swipeSmoothing),
swipeRight_(swipeRight), swipeDown_(swipeDown), swipeLeft_(swipeLeft), swipeUp_(swipeUp) {}

bool Touch(const TouchInput &input) override;
void Update() override;
void Draw(UIContext &dc) override;

protected:
GestureArea area_;
int doubleTapGesture_;
bool analogGesture_;
float analogGestureSensibility_;
float swipeSensitivity_;
float swipeSmoothing_;
int swipeRight_;
int swipeDown_;
int swipeLeft_;
int swipeUp_;

float lastX_ = 0.0f;
float lastY_ = 0.0f;
Expand Down