mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-31 03:26:47 +01:00
Add scaling of touch buttons
This commit is contained in:
1 parent
2f06061f36
commit
c21e1ee2cc
2 files changed
+15
-10
No files matched your search
@@ -38,10 +38,11 @@ void TouchButton::draw(DrawBuffer &db, uint32_t color, uint32_t colorOverlay)
|
||||
colorOverlay |= 0xFF000000;
|
||||
scale = 2.0f;
|
||||
}
|
||||
scale *= scale_;
|
||||
// We only mirror background
|
||||
db.DrawImageRotated(imageIndex_, x_ + w_/2, y_ + h_/2, scale, rotationAngle_, color, mirror_h_);
|
||||
db.DrawImageRotated(imageIndex_, x_ + w_*scale_/2, y_ + h_*scale_/2, scale, rotationAngle_, color, mirror_h_);
|
||||
if (overlayImageIndex_ != -1)
|
||||
db.DrawImageRotated(overlayImageIndex_, x_ + w_/2, y_ + h_/2, scale, rotationAngle_, colorOverlay);
|
||||
db.DrawImageRotated(overlayImageIndex_, x_ + w_*scale_/2, y_ + h_*scale_/2, scale, rotationAngle_, colorOverlay);
|
||||
}
|
||||
|
||||
TouchStick::TouchStick(const Atlas *atlas, int bgImageIndex, int stickImageIndex, int stick)
|
||||
@@ -54,7 +55,7 @@ TouchStick::TouchStick(const Atlas *atlas, int bgImageIndex, int stickImageIndex
|
||||
|
||||
void TouchStick::update(InputState &input_state)
|
||||
{
|
||||
float inv_stick_size = 1.0f / stick_size_;
|
||||
float inv_stick_size = 1.0f / (stick_size_ * scale_);
|
||||
bool all_up = true;
|
||||
for (int i = 0; i < MAX_POINTERS; i++) {
|
||||
if (input_state.pointer_down[i]) {
|
||||
@@ -108,6 +109,6 @@ skip:
|
||||
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_size_, stick_y_ + stick_delta_y_ * stick_size_, 1.0f, color, ALIGN_CENTER);
|
||||
db.DrawImage(bgImageIndex_, stick_x_, stick_y_, 1.0f * scale_, color, ALIGN_CENTER);
|
||||
db.DrawImage(stickImageIndex_, stick_x_ + stick_delta_x_ * stick_size_ * scale_, stick_y_ + stick_delta_y_ * stick_size_ * scale_, 1.0f * scale_, color, ALIGN_CENTER);
|
||||
}
|
||||
+9
-5
@@ -15,16 +15,17 @@ public:
|
||||
void update(InputState &input_state);
|
||||
void draw(DrawBuffer &db, uint32_t color, uint32_t colorOverlay);
|
||||
|
||||
void setPos(float x, float y) {
|
||||
x_ = x - w_ / 2;
|
||||
y_ = y - h_ / 2;
|
||||
void setPos(float x, float y, float scale) {
|
||||
scale_ = scale;
|
||||
x_ = x - w_ * scale / 2;
|
||||
y_ = y - h_ * scale / 2;
|
||||
}
|
||||
|
||||
private:
|
||||
virtual bool isInside(float px, float py) const
|
||||
{
|
||||
float margin = 5.0f;
|
||||
return px >= x_ - margin && py >= y_ - margin && px <= x_ + w_ + margin && py <= y_ + h_ + margin;
|
||||
return px >= x_ - margin * scale_ && py >= y_ - margin * scale_ && px <= x_ + (w_ + margin) * scale_ && py <= y_ + (h_ + margin) * scale_;
|
||||
}
|
||||
|
||||
const Atlas *atlas_;
|
||||
@@ -38,6 +39,7 @@ private:
|
||||
float x_, y_;
|
||||
float w_;
|
||||
float h_;
|
||||
float scale_;
|
||||
|
||||
bool isDown_;
|
||||
|
||||
@@ -57,9 +59,10 @@ public:
|
||||
void update(InputState &input_state);
|
||||
void draw(DrawBuffer &db, uint32_t color);
|
||||
|
||||
void setPos(float x, float y) {
|
||||
void setPos(float x, float y, float scale) {
|
||||
stick_x_ = x;
|
||||
stick_y_ = y;
|
||||
scale_ = scale;
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -70,6 +73,7 @@ private:
|
||||
int stick_size_;
|
||||
float stick_x_;
|
||||
float stick_y_;
|
||||
float scale_;
|
||||
bool dragging_[MAX_POINTERS];
|
||||
bool lastPointerDown_[MAX_POINTERS];
|
||||
|
||||
|
||||
Reference in new issue
Block a user