Merge pull request #14848 from iota97/dpad-size-fix

Fix DPAD size calculation
This commit is contained in:
Henrik Rydgård 2021-11-20 15:58:56 +01:00 committed by GitHub
commit 20c3c8f291
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 8 deletions

View File

@ -227,8 +227,14 @@ PSPDpad::PSPDpad(ImageID arrowIndex, const char *key, ImageID arrowDownIndex, Im
}
void PSPDpad::GetContentDimensions(const UIContext &dc, float &w, float &h) const {
w = D_pad_Radius * spacing_ * 4;
h = D_pad_Radius * spacing_ * 4;
const AtlasImage *image = dc.Draw()->GetAtlas()->getImage(arrowIndex_);
if (image) {
w = 2.0f * D_pad_Radius * spacing_ + image->w * scale_;
h = w;
} else {
w = 0.0f;
h = 0.0f;
}
}
void PSPDpad::Touch(const TouchInput &input) {
@ -259,20 +265,20 @@ void PSPDpad::Touch(const TouchInput &input) {
}
void PSPDpad::ProcessTouch(float x, float y, bool down) {
float stick_size = spacing_ * D_pad_Radius * scale_;
float stick_size = bounds_.w;
float inv_stick_size = 1.0f / stick_size;
const float deadzone = 0.17f;
const float deadzone = 0.05f;
float dx = (x - bounds_.centerX()) * inv_stick_size;
float dy = (y - bounds_.centerY()) * inv_stick_size;
float rad = sqrtf(dx*dx + dy*dy);
if (rad < deadzone || rad > 2.0f)
if (rad < deadzone || fabs(dx) > 0.5f || fabs(dy) > 0.5)
down = false;
int ctrlMask = 0;
int lastDown = down_;
bool fourWay = g_Config.bDisableDpadDiagonals || rad < 0.7f;
bool fourWay = g_Config.bDisableDpadDiagonals || rad < 0.2f;
if (down) {
if (fourWay) {
int direction = (int)(floorf((atan2f(dy, dx) / (2 * M_PI) * 4) + 0.5f)) & 3;

View File

@ -273,8 +273,8 @@ public:
void GetContentDimensions(const UIContext &dc, float &w, float &h) const override {
const AtlasImage *image = dc.Draw()->GetAtlas()->getImage(ImageID("I_DIR"));
w = 2 * D_pad_Radius * spacing_ + image->w * scale_;
h = 2 * D_pad_Radius * spacing_ + image->h * scale_;
w = 2.0f * D_pad_Radius * spacing_ + image->w * scale_;
h = w;
};
float GetSpacing() const override { return spacing_; }