mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Virtual stick fixes
This commit is contained in:
parent
3c231e9056
commit
ec05ad7487
2 changed files with 19 additions and 4 deletions
|
@ -46,7 +46,9 @@ void TouchButton::draw(DrawBuffer &db, uint32_t color, uint32_t colorOverlay)
|
|||
TouchStick::TouchStick(const Atlas *atlas, int bgImageIndex, int stickImageIndex, int stick)
|
||||
: atlas_(atlas), bgImageIndex_(bgImageIndex), stickImageIndex_(stickImageIndex), stick_(stick)
|
||||
{
|
||||
stick_size_ = atlas_->images[bgImageIndex].w;
|
||||
stick_size_ = atlas_->images[bgImageIndex].w / 3.5f;
|
||||
memset(dragging_, 0, sizeof(dragging_));
|
||||
memset(lastPointerDown_, 0, sizeof(lastPointerDown_));
|
||||
}
|
||||
|
||||
void TouchStick::update(InputState &input_state)
|
||||
|
@ -57,8 +59,15 @@ void TouchStick::update(InputState &input_state)
|
|||
float dx = (input_state.pointer_x[i] - stick_x_) * inv_stick_size;
|
||||
float dy = (input_state.pointer_y[i] - stick_y_) * inv_stick_size;
|
||||
// Ignore outside box
|
||||
if (fabsf(dx) > 1.4f || fabsf(dy) > 1.4f)
|
||||
continue;
|
||||
if (!dragging_[i] && (fabsf(dx) > 1.4f || fabsf(dy) > 1.4f))
|
||||
goto skip;
|
||||
if (!lastPointerDown_[i] && (fabsf(dx) < 1.4f && fabsf(dy) < 1.4f))
|
||||
{
|
||||
dragging_[i] = true;
|
||||
}
|
||||
if (!dragging_[i])
|
||||
goto skip;
|
||||
|
||||
// Clamp to a circle
|
||||
float len = sqrtf(dx * dx + dy * dy);
|
||||
if (len > 1.0f) {
|
||||
|
@ -74,7 +83,11 @@ void TouchStick::update(InputState &input_state)
|
|||
input_state.pad_rstick_x = dx;
|
||||
input_state.pad_rstick_y = -dy;
|
||||
}
|
||||
} else {
|
||||
dragging_[i] = false;
|
||||
}
|
||||
skip:
|
||||
lastPointerDown_[i] = input_state.pointer_down[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,5 +95,5 @@ void TouchStick::draw(DrawBuffer &db, uint32_t color)
|
|||
{
|
||||
if (bgImageIndex_ != -1)
|
||||
db.DrawImage(bgImageIndex_, stick_x_, stick_y_, 1.0f, color, ALIGN_CENTER);
|
||||
db.DrawImage(stickImageIndex_, stick_x_ + stick_delta_x_, stick_y_ + stick_delta_y_, 1.0f, color, ALIGN_CENTER);
|
||||
db.DrawImage(stickImageIndex_, stick_x_ + stick_delta_x_ * stick_size_, stick_y_ + stick_delta_y_ * stick_size_, 1.0f, color, ALIGN_CENTER);
|
||||
}
|
||||
|
|
|
@ -70,6 +70,8 @@ private:
|
|||
int stick_size_;
|
||||
float stick_x_;
|
||||
float stick_y_;
|
||||
bool dragging_[MAX_POINTERS];
|
||||
bool lastPointerDown_[MAX_POINTERS];
|
||||
|
||||
// maintained for drawing only
|
||||
float stick_delta_x_;
|
||||
|
|
Loading…
Add table
Reference in a new issue