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
Next Next commit
Move config to constructor parameters
  • Loading branch information
iota97 committed Sep 1, 2023
commit d2eaeaa62674c6177ad349978e975e50458a2d2f
51 changes: 26 additions & 25 deletions UI/GamepadEmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,8 @@ 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, 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));

return root;
}
Expand All @@ -898,8 +899,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 +914,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 +931,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 +950,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_;
}
16 changes: 15 additions & 1 deletion UI/GamepadEmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,27 @@ class CustomButton : public MultiTouchButton {

class GestureGamepad : public UI::View {
public:
GestureGamepad(ControlMapper* controllMapper) : controlMapper_(controllMapper) {};
GestureGamepad(ControlMapper* controllMapper, int doubleTapGesture, bool analogGesture,
float analogGestureSensibility, float swipeSensitivity, float swipeSmoothing,
int swipeRight, int swipeDown, int swipeLeft, int swipeUp) : controlMapper_(controllMapper),
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:
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