From c21e1ee2cced55bb68edefbb58ba4b30bde807ba Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sat, 26 Jan 2013 17:25:00 +0100 Subject: [PATCH] Add scaling of touch buttons --- ui/virtual_input.cpp | 11 ++++++----- ui/virtual_input.h | 14 +++++++++----- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/ui/virtual_input.cpp b/ui/virtual_input.cpp index 7e6d756789..e9d051397c 100644 --- a/ui/virtual_input.cpp +++ b/ui/virtual_input.cpp @@ -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); } diff --git a/ui/virtual_input.h b/ui/virtual_input.h index bfc7ed5c37..adeb81c5e5 100644 --- a/ui/virtual_input.h +++ b/ui/virtual_input.h @@ -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];