Skip to content

Commit

Permalink
Configurable analog head size
Browse files Browse the repository at this point in the history
  • Loading branch information
iota97 committed May 24, 2021
1 parent 8d08991 commit f06916a
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 10 deletions.
6 changes: 6 additions & 0 deletions Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,10 @@ static ConfigSetting controlSettings[] = {
ConfigSetting("AnalogRotationCWKeyX", "AnalogRotationKeyCWY", "AnalogRotationKeyCWScale", "ShowAnalogRotationCWKey", &g_Config.touchAnalogRotationCWKey, defaultTouchPosHide, true, true),
ConfigSetting("AnalogRotationCCWKeyX", "AnalogRotationKeyCCWY", "AnalogRotationKeyCCWScale", "ShowAnalogRotationCCWKey", &g_Config.touchAnalogRotationCCWKey, defaultTouchPosHide, true, true),

ConfigSetting("LeftStickHeadScale", &g_Config.fLeftStickHeadScale, 1.0f, true, true),
ConfigSetting("RightStickHeadScale", &g_Config.fRightStickHeadScale, 1.0f, true, true),
ConfigSetting("HideStickBackground", &g_Config.bHideStickBackground, false, true, true),

#ifdef _WIN32
ConfigSetting("DInputAnalogDeadzone", &g_Config.fDInputAnalogDeadzone, 0.1f, true, true),
ConfigSetting("DInputAnalogInverseMode", &g_Config.iDInputAnalogInverseMode, 0, true, true),
Expand Down Expand Up @@ -1780,6 +1784,8 @@ void Config::ResetControlLayout() {
reset(g_Config.touchRapidFireKey);
reset(g_Config.touchAnalogRotationCWKey);
reset(g_Config.touchAnalogRotationCCWKey);
g_Config.fLeftStickHeadScale = 1.0f;
g_Config.fRightStickHeadScale = 1.0f;
}

void Config::GetReportingInfo(UrlEncoder &data) {
Expand Down
4 changes: 4 additions & 0 deletions Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ struct Config {
ConfigTouchPos touchAnalogRotationCWKey;
ConfigTouchPos touchAnalogRotationCCWKey;

float fLeftStickHeadScale;
float fRightStickHeadScale;
bool bHideStickBackground;

// Controls Visibility
bool bShowTouchControls;

Expand Down
4 changes: 4 additions & 0 deletions UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,10 @@ void GameSettingsScreen::CreateViews() {
CheckBox *floatingAnalog = controlsSettings->Add(new CheckBox(&g_Config.bAutoCenterTouchAnalog, co->T("Auto-centering analog stick")));
floatingAnalog->SetEnabledPtr(&g_Config.bShowTouchControls);

// Hide stick background, usefull when increasing the size
CheckBox *hideStickBackground = controlsSettings->Add(new CheckBox(&g_Config.bHideStickBackground, co->T("Hide touch analog stick background circle")));
hideStickBackground->SetEnabledPtr(&g_Config.bShowTouchControls);

// Combo key setup
Choice *comboKey = controlsSettings->Add(new Choice(co->T("Combo Key Setup")));
comboKey->OnClick.Handle(this, &GameSettingsScreen::OnComboKey);
Expand Down
31 changes: 23 additions & 8 deletions UI/GamepadEmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,12 @@ void PSPStick::Draw(UIContext &dc) {
float dx, dy;
__CtrlPeekAnalog(stick_, &dx, &dy);

dc.Draw()->DrawImage(bgImg_, stickX, stickY, 1.0f * scale_, colorBg, ALIGN_CENTER);
if (!g_Config.bHideStickBackground)
dc.Draw()->DrawImage(bgImg_, stickX, stickY, 1.0f * scale_, colorBg, ALIGN_CENTER);
float headScale = stick_ ? g_Config.fRightStickHeadScale : g_Config.fLeftStickHeadScale;
if (dragPointerId_ != -1 && g_Config.iTouchButtonStyle == 2 && stickDownImg_ != stickImageIndex_)
dc.Draw()->DrawImage(stickDownImg_, stickX + dx * stick_size_ * scale_, stickY - dy * stick_size_ * scale_, 1.0f * scale_, downBg, ALIGN_CENTER);
dc.Draw()->DrawImage(stickImageIndex_, stickX + dx * stick_size_ * scale_, stickY - dy * stick_size_ * scale_, 1.0f * scale_, colorBg, ALIGN_CENTER);
dc.Draw()->DrawImage(stickDownImg_, stickX + dx * stick_size_ * scale_, stickY - dy * stick_size_ * scale_, 1.0f * scale_ * headScale, downBg, ALIGN_CENTER);
dc.Draw()->DrawImage(stickImageIndex_, stickX + dx * stick_size_ * scale_, stickY - dy * stick_size_ * scale_, 1.0f * scale_ * headScale, colorBg, ALIGN_CENTER);
}

void PSPStick::Touch(const TouchInput &input) {
Expand All @@ -445,8 +447,14 @@ void PSPStick::Touch(const TouchInput &input) {
__CtrlSetAnalogY(0.0f, stick_);
return;
}
auto InputInHeadRange = [&]() {
float x = bounds_.centerX()-input.x;
float y = bounds_.centerY()-input.y;
float r = stick_size_*scale_* (stick_ ? g_Config.fRightStickHeadScale : g_Config.fLeftStickHeadScale);
return x*x + y*y < r*r;
};
if (input.flags & TOUCH_DOWN) {
if (dragPointerId_ == -1 && bounds_.Contains(input.x, input.y)) {
if (dragPointerId_ == -1 && InputInHeadRange()) {
if (g_Config.bAutoCenterTouchAnalog) {
centerX_ = input.x;
centerY_ = input.y;
Expand Down Expand Up @@ -528,10 +536,11 @@ void PSPCustomStick::Draw(UIContext &dc) {
dx = posX_;
dy = -posY_;

dc.Draw()->DrawImage(bgImg_, stickX, stickY, 1.0f * scale_, colorBg, ALIGN_CENTER);
if (!g_Config.bHideStickBackground)
dc.Draw()->DrawImage(bgImg_, stickX, stickY, 1.0f * scale_, colorBg, ALIGN_CENTER);
if (dragPointerId_ != -1 && g_Config.iTouchButtonStyle == 2 && stickDownImg_ != stickImageIndex_)
dc.Draw()->DrawImage(stickDownImg_, stickX + dx * stick_size_ * scale_, stickY - dy * stick_size_ * scale_, 1.0f * scale_, downBg, ALIGN_CENTER);
dc.Draw()->DrawImage(stickImageIndex_, stickX + dx * stick_size_ * scale_, stickY - dy * stick_size_ * scale_, 1.0f * scale_, colorBg, ALIGN_CENTER);
dc.Draw()->DrawImage(stickDownImg_, stickX + dx * stick_size_ * scale_, stickY - dy * stick_size_ * scale_, 1.0f*scale_*g_Config.fRightStickHeadScale, downBg, ALIGN_CENTER);
dc.Draw()->DrawImage(stickImageIndex_, stickX + dx * stick_size_ * scale_, stickY - dy * stick_size_ * scale_, 1.0f*scale_*g_Config.fRightStickHeadScale, colorBg, ALIGN_CENTER);
}

void PSPCustomStick::Touch(const TouchInput &input) {
Expand All @@ -544,8 +553,14 @@ void PSPCustomStick::Touch(const TouchInput &input) {
posY_ = 0.0f;
return;
}
auto InputInHeadRange = [&]() {
float x = bounds_.centerX()-input.x;
float y = bounds_.centerY()-input.y;
float r = stick_size_*scale_*g_Config.fRightStickHeadScale;
return x*x + y*y < r*r;
};
if (input.flags & TOUCH_DOWN) {
if (dragPointerId_ == -1 && bounds_.Contains(input.x, input.y)) {
if (dragPointerId_ == -1 && InputInHeadRange()) {
if (g_Config.bAutoCenterTouchAnalog) {
centerX_ = input.x;
centerY_ = input.y;
Expand Down
37 changes: 35 additions & 2 deletions UI/TouchControlLayoutScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,35 @@ class PSPDPadButtons : public DragDropButton {
float &spacing_;
};

class PSPStickDragDrop : public DragDropButton {
public:
PSPStickDragDrop(ConfigTouchPos &pos, const char *key, ImageID bgImg, ImageID img, const Bounds &screenBounds, float &spacing)
: DragDropButton(pos, key, bgImg, img, screenBounds), spacing_(spacing) {
}

void Draw(UIContext &dc) override {
float opacity = g_Config.iTouchButtonOpacity / 100.0f;

uint32_t colorBg = colorAlpha(GetButtonColor(), opacity);
uint32_t downBg = colorAlpha(0x00FFFFFF, opacity * 0.5f);

const ImageID stickImage = g_Config.iTouchButtonStyle ? ImageID("I_STICK_LINE") : ImageID("I_STICK");
const ImageID stickBg = g_Config.iTouchButtonStyle ? ImageID("I_STICK_BG_LINE") : ImageID("I_STICK_BG");

dc.Draw()->DrawImage(stickBg, bounds_.centerX(), bounds_.centerY(), scale_, colorBg, ALIGN_CENTER);
dc.Draw()->DrawImage(stickImage, bounds_.centerX(), bounds_.centerY(), scale_ * spacing_, colorBg, ALIGN_CENTER);
}

float GetSpacing() const override { return spacing_; }
void SetSpacing(float s) override {
// In mapping spacing is clamped between 0.5 and 3.0 and passed to this method
spacing_ = s/3;
}

private:
float &spacing_;
};

class SnapGrid : public UI::View {
public:
SnapGrid(int leftMargin, int rightMargin, int topMargin, int bottomMargin, u32 color) {
Expand Down Expand Up @@ -398,8 +427,12 @@ void ControlLayoutView::CreateViews() {
rbutton->FlipImageH(true);
}

addDragDropButton(g_Config.touchAnalogStick, "Left analog stick", stickBg, stickImage);
addDragDropButton(g_Config.touchRightAnalogStick, "Right analog stick", stickBg, stickImage);
if (g_Config.touchAnalogStick.show) {
controls_.push_back(new PSPStickDragDrop(g_Config.touchAnalogStick, "Left analog stick", stickBg, stickImage, bounds, g_Config.fLeftStickHeadScale));
}
if (g_Config.touchRightAnalogStick.show) {
controls_.push_back(new PSPStickDragDrop(g_Config.touchRightAnalogStick, "Right analog stick", stickBg, stickImage, bounds, g_Config.fRightStickHeadScale));
}
addDragDropButton(g_Config.touchCombo0, "Combo 1 button", roundImage, comboKeyImages[0]);
addDragDropButton(g_Config.touchCombo1, "Combo 2 button", roundImage, comboKeyImages[1]);
addDragDropButton(g_Config.touchCombo2, "Combo 3 button", roundImage, comboKeyImages[2]);
Expand Down

0 comments on commit f06916a

Please sign in to comment.