2013-10-19 22:34:48 +00:00
|
|
|
// Copyright (c) 2013- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
2017-06-03 15:41:56 +00:00
|
|
|
#include <algorithm>
|
2013-10-19 22:34:48 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2020-10-01 11:05:04 +00:00
|
|
|
#include "Common/Data/Color/RGBAUtil.h"
|
2020-10-04 21:24:14 +00:00
|
|
|
#include "Common/Render/DrawBuffer.h"
|
2020-10-01 11:05:04 +00:00
|
|
|
#include "Common/Data/Text/I18n.h"
|
2020-10-03 22:25:21 +00:00
|
|
|
#include "Common/Math/math_util.h"
|
2020-10-04 18:48:47 +00:00
|
|
|
#include "Common/UI/Context.h"
|
2014-02-10 11:38:23 +00:00
|
|
|
|
2020-04-01 04:43:18 +00:00
|
|
|
#include "Common/Common.h"
|
2020-10-04 07:29:36 +00:00
|
|
|
#include "Common/Log.h"
|
2013-10-09 20:15:56 +00:00
|
|
|
#include "Core/Config.h"
|
|
|
|
#include "Core/System.h"
|
2020-04-01 04:43:18 +00:00
|
|
|
#include "UI/GamepadEmu.h"
|
|
|
|
#include "UI/TouchControlLayoutScreen.h"
|
|
|
|
#include "UI/TouchControlVisibilityScreen.h"
|
2013-10-09 20:15:56 +00:00
|
|
|
|
2013-12-10 22:19:37 +00:00
|
|
|
static u32 GetButtonColor() {
|
2018-09-30 23:48:02 +00:00
|
|
|
return g_Config.iTouchButtonStyle != 0 ? 0xFFFFFF : 0xc0b080;
|
2013-12-10 22:19:37 +00:00
|
|
|
}
|
|
|
|
|
2013-10-19 22:34:48 +00:00
|
|
|
class DragDropButton : public MultiTouchButton {
|
2013-10-09 20:15:56 +00:00
|
|
|
public:
|
2021-02-22 00:38:02 +00:00
|
|
|
DragDropButton(ConfigTouchPos &pos, const char *key, ImageID bgImg, ImageID img, const Bounds &screenBounds)
|
|
|
|
: MultiTouchButton(key, bgImg, bgImg, img, pos.scale, new UI::AnchorLayoutParams(pos.x * screenBounds.w, pos.y * screenBounds.h, UI::NONE, UI::NONE, true)),
|
2020-04-05 19:50:13 +00:00
|
|
|
x_(pos.x), y_(pos.y), theScale_(pos.scale), screenBounds_(screenBounds) {
|
2013-12-02 14:15:19 +00:00
|
|
|
scale_ = theScale_;
|
2013-10-09 20:15:56 +00:00
|
|
|
}
|
|
|
|
|
2017-06-07 02:50:19 +00:00
|
|
|
bool IsDown() override {
|
2013-12-02 14:15:19 +00:00
|
|
|
// Don't want the button to enlarge and throw the user's perspective
|
|
|
|
// of button size off whack.
|
2013-10-09 20:15:56 +00:00
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2013-12-02 14:15:19 +00:00
|
|
|
virtual void SavePosition() {
|
2020-07-11 22:21:07 +00:00
|
|
|
x_ = (bounds_.centerX() - screenBounds_.x) / screenBounds_.w;
|
|
|
|
y_ = (bounds_.centerY() - screenBounds_.y) / screenBounds_.h;
|
2013-12-02 14:15:19 +00:00
|
|
|
scale_ = theScale_;
|
2013-10-09 20:15:56 +00:00
|
|
|
}
|
|
|
|
|
2013-12-02 14:15:19 +00:00
|
|
|
virtual float GetScale() const { return theScale_; }
|
|
|
|
virtual void SetScale(float s) { theScale_ = s; scale_ = s; }
|
|
|
|
|
|
|
|
virtual float GetSpacing() const { return 1.0f; }
|
|
|
|
virtual void SetSpacing(float s) { }
|
|
|
|
|
2017-06-03 15:41:56 +00:00
|
|
|
protected:
|
|
|
|
float GetButtonOpacity() override {
|
|
|
|
float opacity = g_Config.iTouchButtonOpacity / 100.0f;
|
|
|
|
return std::max(0.5f, opacity);
|
|
|
|
}
|
|
|
|
|
2013-10-09 20:15:56 +00:00
|
|
|
private:
|
2013-11-05 04:52:31 +00:00
|
|
|
float &x_, &y_;
|
2013-12-02 14:15:19 +00:00
|
|
|
float &theScale_;
|
2020-04-05 19:50:13 +00:00
|
|
|
const Bounds &screenBounds_;
|
2013-10-09 20:15:56 +00:00
|
|
|
};
|
|
|
|
|
2013-10-19 22:34:48 +00:00
|
|
|
class PSPActionButtons : public DragDropButton {
|
2013-10-09 20:15:56 +00:00
|
|
|
public:
|
2021-02-22 00:38:02 +00:00
|
|
|
PSPActionButtons(ConfigTouchPos &pos, const char *key, float &spacing, const Bounds &screenBounds)
|
|
|
|
: DragDropButton(pos, key, ImageID::invalid(), ImageID::invalid(), screenBounds), spacing_(spacing) {
|
2013-10-09 20:15:56 +00:00
|
|
|
using namespace UI;
|
2020-02-29 20:51:14 +00:00
|
|
|
roundId_ = g_Config.iTouchButtonStyle ? ImageID("I_ROUND_LINE") : ImageID("I_ROUND");
|
2013-10-09 20:15:56 +00:00
|
|
|
};
|
|
|
|
|
2020-07-11 22:21:07 +00:00
|
|
|
void setCircleVisibility(bool visible) {
|
2013-10-20 10:06:01 +00:00
|
|
|
circleVisible_ = visible;
|
|
|
|
}
|
|
|
|
|
2020-07-11 22:21:07 +00:00
|
|
|
void setCrossVisibility(bool visible) {
|
2013-10-20 10:06:01 +00:00
|
|
|
crossVisible_ = visible;
|
|
|
|
}
|
|
|
|
|
2020-07-11 22:21:07 +00:00
|
|
|
void setTriangleVisibility(bool visible) {
|
2013-10-20 10:06:01 +00:00
|
|
|
triangleVisible_ = visible;
|
|
|
|
}
|
|
|
|
|
2020-07-11 22:21:07 +00:00
|
|
|
void setSquareVisibility(bool visible) {
|
2013-10-20 10:06:01 +00:00
|
|
|
squareVisible_ = visible;
|
|
|
|
}
|
|
|
|
|
2017-06-07 02:50:19 +00:00
|
|
|
void Draw(UIContext &dc) override {
|
2013-10-09 20:15:56 +00:00
|
|
|
float opacity = g_Config.iTouchButtonOpacity / 100.0f;
|
|
|
|
|
2013-12-10 22:19:37 +00:00
|
|
|
uint32_t colorBg = colorAlpha(GetButtonColor(), opacity);
|
2013-10-09 20:15:56 +00:00
|
|
|
uint32_t color = colorAlpha(0xFFFFFF, opacity);
|
|
|
|
|
|
|
|
int centerX = bounds_.centerX();
|
|
|
|
int centerY = bounds_.centerY();
|
|
|
|
|
2013-12-02 14:15:19 +00:00
|
|
|
float spacing = spacing_ * baseActionButtonSpacing;
|
2013-10-20 10:06:01 +00:00
|
|
|
if (circleVisible_) {
|
2013-12-02 14:15:19 +00:00
|
|
|
dc.Draw()->DrawImageRotated(roundId_, centerX + spacing, centerY, scale_, 0, colorBg, false);
|
|
|
|
dc.Draw()->DrawImageRotated(circleId_, centerX + spacing, centerY, scale_, 0, color, false);
|
2013-10-20 10:06:01 +00:00
|
|
|
}
|
2013-10-09 20:15:56 +00:00
|
|
|
|
2013-10-20 10:06:01 +00:00
|
|
|
if (crossVisible_) {
|
2013-12-02 14:15:19 +00:00
|
|
|
dc.Draw()->DrawImageRotated(roundId_, centerX, centerY + spacing, scale_, 0, colorBg, false);
|
|
|
|
dc.Draw()->DrawImageRotated(crossId_, centerX, centerY + spacing, scale_, 0, color, false);
|
2013-10-20 10:06:01 +00:00
|
|
|
}
|
2013-10-09 20:15:56 +00:00
|
|
|
|
2013-10-20 10:06:01 +00:00
|
|
|
if (triangleVisible_) {
|
2013-12-11 19:52:13 +00:00
|
|
|
float y = centerY - spacing;
|
|
|
|
y -= 2.8f * scale_;
|
2013-12-02 14:15:19 +00:00
|
|
|
dc.Draw()->DrawImageRotated(roundId_, centerX, centerY - spacing, scale_, 0, colorBg, false);
|
2013-12-11 19:52:13 +00:00
|
|
|
dc.Draw()->DrawImageRotated(triangleId_, centerX, y, scale_, 0, color, false);
|
2013-10-20 10:06:01 +00:00
|
|
|
}
|
2013-12-02 14:15:19 +00:00
|
|
|
|
|
|
|
if (squareVisible_) {
|
|
|
|
dc.Draw()->DrawImageRotated(roundId_, centerX - spacing, centerY, scale_, 0, colorBg, false);
|
|
|
|
dc.Draw()->DrawImageRotated(squareId_, centerX - spacing, centerY, scale_, 0, color, false);
|
2013-10-20 10:06:01 +00:00
|
|
|
}
|
2013-10-09 20:15:56 +00:00
|
|
|
};
|
|
|
|
|
2017-06-07 02:50:19 +00:00
|
|
|
void GetContentDimensions(const UIContext &dc, float &w, float &h) const override {
|
2020-02-29 20:51:14 +00:00
|
|
|
const AtlasImage *image = dc.Draw()->GetAtlas()->getImage(roundId_);
|
2013-10-09 20:15:56 +00:00
|
|
|
|
2020-02-29 20:51:14 +00:00
|
|
|
w = (2.0f * baseActionButtonSpacing * spacing_) + image->w * scale_;
|
|
|
|
h = (2.0f * baseActionButtonSpacing * spacing_) + image->h * scale_;
|
2013-12-02 14:15:19 +00:00
|
|
|
}
|
2013-10-19 22:34:48 +00:00
|
|
|
|
2017-06-07 02:50:19 +00:00
|
|
|
float GetSpacing() const override { return spacing_; }
|
|
|
|
void SetSpacing(float s) override { spacing_ = s; }
|
2013-10-20 10:06:01 +00:00
|
|
|
|
2013-12-02 14:15:19 +00:00
|
|
|
private:
|
2020-02-29 20:51:14 +00:00
|
|
|
bool circleVisible_ = true, crossVisible_ = true, triangleVisible_ = true, squareVisible_ = true;
|
2013-10-20 10:06:01 +00:00
|
|
|
|
2020-02-29 20:51:14 +00:00
|
|
|
ImageID roundId_ = ImageID::invalid();
|
|
|
|
ImageID circleId_ = ImageID("I_CIRCLE");
|
|
|
|
ImageID crossId_ = ImageID("I_CROSS");
|
|
|
|
ImageID triangleId_ = ImageID("I_TRIANGLE");
|
|
|
|
ImageID squareId_ = ImageID("I_SQUARE");
|
2013-10-09 20:15:56 +00:00
|
|
|
|
2013-12-02 14:15:19 +00:00
|
|
|
float &spacing_;
|
2013-10-09 20:15:56 +00:00
|
|
|
};
|
|
|
|
|
2013-10-19 22:34:48 +00:00
|
|
|
class PSPDPadButtons : public DragDropButton {
|
2013-10-09 20:15:56 +00:00
|
|
|
public:
|
2021-02-22 00:38:02 +00:00
|
|
|
PSPDPadButtons(ConfigTouchPos &pos, const char *key, float &spacing, const Bounds &screenBounds)
|
|
|
|
: DragDropButton(pos, key, ImageID::invalid(), ImageID::invalid(), screenBounds), spacing_(spacing) {
|
2013-10-09 20:15:56 +00:00
|
|
|
}
|
|
|
|
|
2017-06-07 02:50:19 +00:00
|
|
|
void Draw(UIContext &dc) override {
|
2013-10-09 20:15:56 +00:00
|
|
|
float opacity = g_Config.iTouchButtonOpacity / 100.0f;
|
|
|
|
|
2013-12-10 22:19:37 +00:00
|
|
|
uint32_t colorBg = colorAlpha(GetButtonColor(), opacity);
|
2013-10-09 20:15:56 +00:00
|
|
|
uint32_t color = colorAlpha(0xFFFFFF, opacity);
|
|
|
|
|
|
|
|
static const float xoff[4] = {1, 0, -1, 0};
|
|
|
|
static const float yoff[4] = {0, 1, 0, -1};
|
|
|
|
|
2020-02-29 20:51:14 +00:00
|
|
|
ImageID dirImage = g_Config.iTouchButtonStyle ? ImageID("I_DIR_LINE") : ImageID("I_DIR");
|
2013-12-10 22:19:37 +00:00
|
|
|
|
2013-10-09 20:15:56 +00:00
|
|
|
for (int i = 0; i < 4; i++) {
|
2013-12-11 19:52:13 +00:00
|
|
|
float r = D_pad_Radius * spacing_;
|
|
|
|
float x = bounds_.centerX() + xoff[i] * r;
|
|
|
|
float y = bounds_.centerY() + yoff[i] * r;
|
|
|
|
float x2 = bounds_.centerX() + xoff[i] * (r + 10.f * scale_);
|
|
|
|
float y2 = bounds_.centerY() + yoff[i] * (r + 10.f * scale_);
|
2013-10-09 20:15:56 +00:00
|
|
|
float angle = i * M_PI / 2;
|
|
|
|
|
2013-12-10 22:19:37 +00:00
|
|
|
dc.Draw()->DrawImageRotated(dirImage, x, y, scale_, angle + PI, colorBg, false);
|
2020-02-29 20:51:14 +00:00
|
|
|
dc.Draw()->DrawImageRotated(ImageID("I_ARROW"), x2, y2, scale_, angle + PI, color);
|
2013-10-09 20:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-07 02:50:19 +00:00
|
|
|
void GetContentDimensions(const UIContext &dc, float &w, float &h) const override {
|
2020-02-29 20:51:14 +00:00
|
|
|
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_;
|
2013-10-09 20:15:56 +00:00
|
|
|
};
|
2013-12-06 14:29:14 +00:00
|
|
|
|
2017-06-07 02:50:19 +00:00
|
|
|
float GetSpacing() const override { return spacing_; }
|
|
|
|
void SetSpacing(float s) override { spacing_ = s; }
|
2013-10-09 20:15:56 +00:00
|
|
|
|
|
|
|
private:
|
2013-12-02 14:15:19 +00:00
|
|
|
float &spacing_;
|
|
|
|
};
|
2013-10-09 20:15:56 +00:00
|
|
|
|
2020-01-14 18:18:27 +00:00
|
|
|
class SnapGrid : public UI::View {
|
|
|
|
public:
|
|
|
|
SnapGrid(int leftMargin, int rightMargin, int topMargin, int bottomMargin, u32 color) {
|
|
|
|
x1 = leftMargin;
|
|
|
|
x2 = rightMargin;
|
|
|
|
y1 = topMargin;
|
|
|
|
y2 = bottomMargin;
|
|
|
|
col = color;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Draw(UIContext &dc) override {
|
|
|
|
if (g_Config.bTouchSnapToGrid) {
|
2020-01-16 05:16:46 +00:00
|
|
|
dc.Flush();
|
2020-01-15 17:48:43 +00:00
|
|
|
dc.BeginNoTex();
|
2020-07-11 22:21:07 +00:00
|
|
|
float xOffset = bounds_.x;
|
|
|
|
float yOffset = bounds_.y;
|
2020-01-14 18:18:27 +00:00
|
|
|
for (int x = x1; x < x2; x += g_Config.iTouchSnapGridSize)
|
2020-07-11 22:21:07 +00:00
|
|
|
dc.Draw()->vLine(x + xOffset, y1 + yOffset, y2 + yOffset, col);
|
2020-01-14 18:18:27 +00:00
|
|
|
for (int y = y1; y < y2; y += g_Config.iTouchSnapGridSize)
|
2020-07-11 22:21:07 +00:00
|
|
|
dc.Draw()->hLine(x1 + xOffset, y + yOffset, x2 + xOffset, col);
|
2020-01-15 17:48:43 +00:00
|
|
|
dc.Flush();
|
|
|
|
dc.Begin();
|
2020-01-14 18:18:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-22 00:38:02 +00:00
|
|
|
std::string DescribeText() const override {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2020-01-14 18:18:27 +00:00
|
|
|
private:
|
|
|
|
int x1, x2, y1, y2;
|
|
|
|
u32 col;
|
|
|
|
};
|
|
|
|
|
2020-07-11 22:21:07 +00:00
|
|
|
class DragDropButton;
|
|
|
|
|
|
|
|
class ControlLayoutView : public UI::AnchorLayout {
|
|
|
|
public:
|
2020-07-11 22:21:46 +00:00
|
|
|
explicit ControlLayoutView(UI::LayoutParams *layoutParams)
|
|
|
|
: UI::AnchorLayout(layoutParams) {
|
|
|
|
}
|
2020-07-11 22:21:07 +00:00
|
|
|
|
|
|
|
void Touch(const TouchInput &input) override;
|
|
|
|
void CreateViews();
|
|
|
|
bool HasCreatedViews() const {
|
|
|
|
return !controls_.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
DragDropButton *pickedControl_ = nullptr;
|
|
|
|
DragDropButton *getPickedControl(const int x, const int y);
|
|
|
|
std::vector<DragDropButton *> controls_;
|
|
|
|
|
2020-07-12 07:15:31 +00:00
|
|
|
// Touch down state for dragging
|
|
|
|
float startObjectX_ = -1.0f;
|
|
|
|
float startObjectY_ = -1.0f;
|
|
|
|
float startDragX_ = -1.0f;
|
|
|
|
float startDragY_ = -1.0f;
|
2020-07-11 22:21:07 +00:00
|
|
|
float startScale_ = -1.0f;
|
|
|
|
float startSpacing_ = -1.0f;
|
|
|
|
|
|
|
|
int mode_ = 0;
|
2013-10-09 20:15:56 +00:00
|
|
|
};
|
|
|
|
|
2020-04-01 04:43:18 +00:00
|
|
|
static Point ClampTo(const Point &p, const Bounds &b) {
|
|
|
|
return Point(clamp_value(p.x, b.x, b.x + b.w), clamp_value(p.y, b.y, b.y + b.h));
|
|
|
|
}
|
|
|
|
|
2020-07-11 22:21:07 +00:00
|
|
|
void ControlLayoutView::Touch(const TouchInput &touch) {
|
2013-10-09 20:15:56 +00:00
|
|
|
using namespace UI;
|
|
|
|
|
2020-04-01 04:43:18 +00:00
|
|
|
if ((touch.flags & TOUCH_MOVE) && pickedControl_ != nullptr) {
|
2020-07-11 22:21:07 +00:00
|
|
|
if (mode_ == 0) {
|
|
|
|
const Bounds &controlBounds = pickedControl_->GetBounds();
|
2020-04-01 04:43:18 +00:00
|
|
|
|
2020-07-11 22:21:07 +00:00
|
|
|
// Allow placing the control halfway outside the play area.
|
|
|
|
Bounds validRange = this->GetBounds();
|
|
|
|
// Control coordinates are relative inside the bounds.
|
|
|
|
validRange.x = 0.0f;
|
|
|
|
validRange.y = 0.0f;
|
2020-04-01 04:43:18 +00:00
|
|
|
|
2020-07-11 22:21:07 +00:00
|
|
|
validRange.x += controlBounds.w * 0.5f;
|
|
|
|
validRange.w -= controlBounds.w;
|
|
|
|
validRange.y += controlBounds.h * 0.5f;
|
|
|
|
validRange.h -= controlBounds.h;
|
|
|
|
|
2020-07-12 07:15:31 +00:00
|
|
|
Point newPos;
|
|
|
|
newPos.x = startObjectX_ + (touch.x - startDragX_);
|
|
|
|
newPos.y = startObjectY_ + (touch.y - startDragY_);
|
2020-04-01 04:43:18 +00:00
|
|
|
if (g_Config.bTouchSnapToGrid) {
|
2020-07-12 07:47:44 +00:00
|
|
|
newPos.x -= fmod(newPos.x - controlBounds.w, g_Config.iTouchSnapGridSize);
|
|
|
|
newPos.y -= fmod(newPos.y - controlBounds.h, g_Config.iTouchSnapGridSize);
|
2020-04-01 04:43:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
newPos = ClampTo(newPos, validRange);
|
|
|
|
pickedControl_->ReplaceLayoutParams(new AnchorLayoutParams(newPos.x, newPos.y, NONE, NONE, true));
|
2020-07-11 22:21:07 +00:00
|
|
|
} else if (mode_ == 1) {
|
2013-12-02 14:15:19 +00:00
|
|
|
// Resize. Vertical = scaling, horizontal = spacing;
|
|
|
|
// Up should be bigger so let's negate in that direction
|
2020-07-12 07:15:31 +00:00
|
|
|
float diffX = (touch.x - startDragX_);
|
|
|
|
float diffY = -(touch.y - startDragY_);
|
2013-12-02 14:15:19 +00:00
|
|
|
|
2020-01-12 10:52:49 +00:00
|
|
|
// Snap to grid
|
|
|
|
if (g_Config.bTouchSnapToGrid) {
|
2020-07-12 07:47:44 +00:00
|
|
|
diffX -= fmod(touch.x - startDragX_, g_Config.iTouchSnapGridSize/2);
|
|
|
|
diffY += fmod(touch.y - startDragY_, g_Config.iTouchSnapGridSize/2);
|
2020-01-12 10:52:49 +00:00
|
|
|
}
|
2013-12-02 14:15:19 +00:00
|
|
|
float movementScale = 0.02f;
|
|
|
|
float newScale = startScale_ + diffY * movementScale;
|
|
|
|
float newSpacing = startSpacing_ + diffX * movementScale;
|
|
|
|
if (newScale > 3.0f) newScale = 3.0f;
|
|
|
|
if (newScale < 0.5f) newScale = 0.5f;
|
|
|
|
if (newSpacing > 3.0f) newSpacing = 3.0f;
|
|
|
|
if (newSpacing < 0.5f) newSpacing = 0.5f;
|
|
|
|
pickedControl_->SetSpacing(newSpacing);
|
|
|
|
pickedControl_->SetScale(newScale);
|
2013-10-09 20:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
2013-10-19 22:34:48 +00:00
|
|
|
if ((touch.flags & TOUCH_DOWN) && pickedControl_ == 0) {
|
2013-10-09 20:15:56 +00:00
|
|
|
pickedControl_ = getPickedControl(touch.x, touch.y);
|
2013-12-02 14:15:19 +00:00
|
|
|
if (pickedControl_) {
|
2020-07-12 07:15:31 +00:00
|
|
|
startDragX_ = touch.x;
|
|
|
|
startDragY_ = touch.y;
|
|
|
|
const auto &prevParams = pickedControl_->GetLayoutParams()->As<AnchorLayoutParams>();
|
|
|
|
startObjectX_ = prevParams->left;
|
|
|
|
startObjectY_ = prevParams->top;
|
|
|
|
|
2013-12-02 14:15:19 +00:00
|
|
|
startSpacing_ = pickedControl_->GetSpacing();
|
|
|
|
startScale_ = pickedControl_->GetScale();
|
|
|
|
}
|
2013-10-09 20:15:56 +00:00
|
|
|
}
|
2013-10-19 22:34:48 +00:00
|
|
|
if ((touch.flags & TOUCH_UP) && pickedControl_ != 0) {
|
2013-10-09 20:15:56 +00:00
|
|
|
pickedControl_->SavePosition();
|
|
|
|
pickedControl_ = 0;
|
2013-10-19 22:34:48 +00:00
|
|
|
}
|
2017-12-27 09:13:47 +00:00
|
|
|
}
|
|
|
|
|
2020-07-11 22:21:46 +00:00
|
|
|
void ControlLayoutView::CreateViews() {
|
|
|
|
const Bounds &bounds = GetBounds();
|
|
|
|
if (bounds.w == 0.0f || bounds.h == 0.0f) {
|
|
|
|
// Layout hasn't happened yet, return.
|
|
|
|
// See comment in TouchControlLayoutScreen::update().
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create all the views.
|
|
|
|
|
2021-02-22 00:38:02 +00:00
|
|
|
PSPActionButtons *actionButtons = new PSPActionButtons(g_Config.touchActionButtonCenter, "Action buttons", g_Config.fActionButtonSpacing, bounds);
|
2020-07-11 22:21:46 +00:00
|
|
|
actionButtons->setCircleVisibility(g_Config.bShowTouchCircle);
|
|
|
|
actionButtons->setCrossVisibility(g_Config.bShowTouchCross);
|
|
|
|
actionButtons->setTriangleVisibility(g_Config.bShowTouchTriangle);
|
|
|
|
actionButtons->setSquareVisibility(g_Config.bShowTouchSquare);
|
|
|
|
|
|
|
|
controls_.push_back(actionButtons);
|
|
|
|
|
|
|
|
ImageID rectImage = g_Config.iTouchButtonStyle ? ImageID("I_RECT_LINE") : ImageID("I_RECT");
|
|
|
|
ImageID shoulderImage = g_Config.iTouchButtonStyle ? ImageID("I_SHOULDER_LINE") : ImageID("I_SHOULDER");
|
|
|
|
ImageID stickImage = g_Config.iTouchButtonStyle ? ImageID("I_STICK_LINE") : ImageID("I_STICK");
|
|
|
|
ImageID stickBg = g_Config.iTouchButtonStyle ? ImageID("I_STICK_BG_LINE") : ImageID("I_STICK_BG");
|
|
|
|
ImageID roundImage = g_Config.iTouchButtonStyle ? ImageID("I_ROUND_LINE") : ImageID("I_ROUND");
|
|
|
|
|
|
|
|
const ImageID comboKeyImages[5] = { ImageID("I_1"), ImageID("I_2"), ImageID("I_3"), ImageID("I_4"), ImageID("I_5") };
|
|
|
|
|
2021-02-22 00:38:02 +00:00
|
|
|
auto addDragDropButton = [&](ConfigTouchPos &pos, const char *key, ImageID bgImg, ImageID img) {
|
2020-07-11 22:21:46 +00:00
|
|
|
DragDropButton *b = nullptr;
|
|
|
|
if (pos.show) {
|
2021-02-22 00:38:02 +00:00
|
|
|
b = new DragDropButton(pos, key, bgImg, img, bounds);
|
2020-07-11 22:21:46 +00:00
|
|
|
controls_.push_back(b);
|
|
|
|
}
|
|
|
|
return b;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (g_Config.touchDpad.show) {
|
2021-02-22 00:38:02 +00:00
|
|
|
controls_.push_back(new PSPDPadButtons(g_Config.touchDpad, "D-pad", g_Config.fDpadSpacing, bounds));
|
2020-07-11 22:21:46 +00:00
|
|
|
}
|
|
|
|
|
2021-02-22 00:38:02 +00:00
|
|
|
addDragDropButton(g_Config.touchSelectKey, "Select button", rectImage, ImageID("I_SELECT"));
|
|
|
|
addDragDropButton(g_Config.touchStartKey, "Start button", rectImage, ImageID("I_START"));
|
2020-07-11 22:21:46 +00:00
|
|
|
|
2021-02-22 00:38:02 +00:00
|
|
|
if (auto *unthrottle = addDragDropButton(g_Config.touchUnthrottleKey, "Unthrottle button", rectImage, ImageID("I_ARROW"))) {
|
2020-07-11 22:21:46 +00:00
|
|
|
unthrottle->SetAngle(180.0f);
|
|
|
|
}
|
2021-02-22 00:38:02 +00:00
|
|
|
if (auto *speed1 = addDragDropButton(g_Config.touchSpeed1Key, "Alternate speed 1 button", rectImage, ImageID("I_ARROW"))) {
|
2020-07-11 22:21:46 +00:00
|
|
|
speed1->SetAngle(170.0f, 180.0f);
|
|
|
|
}
|
2021-02-22 00:38:02 +00:00
|
|
|
if (auto *speed2 = addDragDropButton(g_Config.touchSpeed2Key, "Alternate speed 2 button", rectImage, ImageID("I_ARROW"))) {
|
2020-07-11 22:21:46 +00:00
|
|
|
speed2->SetAngle(190.0f, 180.0f);
|
|
|
|
}
|
2021-02-22 00:38:02 +00:00
|
|
|
if (auto *rapidFire = addDragDropButton(g_Config.touchRapidFireKey, "Rapid fire button", rectImage, ImageID("I_ARROW"))) {
|
2020-07-11 22:21:46 +00:00
|
|
|
rapidFire->SetAngle(90.0f, 180.0f);
|
|
|
|
}
|
2021-02-22 00:38:02 +00:00
|
|
|
if (auto *analogRotationCW = addDragDropButton(g_Config.touchAnalogRotationCWKey, "Analog clockwise rotation button", rectImage, ImageID("I_ARROW"))) {
|
2020-07-11 22:21:46 +00:00
|
|
|
analogRotationCW->SetAngle(190.0f, 180.0f);
|
|
|
|
}
|
2021-02-22 00:38:02 +00:00
|
|
|
if (auto *analogRotationCCW = addDragDropButton(g_Config.touchAnalogRotationCCWKey, "Analog counter clockwise rotation button", rectImage, ImageID("I_ARROW"))) {
|
2020-07-11 22:21:46 +00:00
|
|
|
analogRotationCCW->SetAngle(350.0f, 180.0f);
|
|
|
|
}
|
|
|
|
|
2021-02-22 00:38:02 +00:00
|
|
|
addDragDropButton(g_Config.touchLKey, "Left shoulder button", shoulderImage, ImageID("I_L"));
|
|
|
|
if (auto *rbutton = addDragDropButton(g_Config.touchRKey, "Right shoulder button", shoulderImage, ImageID("I_R"))) {
|
2020-07-11 22:21:46 +00:00
|
|
|
rbutton->FlipImageH(true);
|
|
|
|
}
|
|
|
|
|
2021-02-22 00:38:02 +00:00
|
|
|
addDragDropButton(g_Config.touchAnalogStick, "Left analog stick", stickBg, stickImage);
|
|
|
|
addDragDropButton(g_Config.touchRightAnalogStick, "Right analog stick", stickBg, stickImage);
|
|
|
|
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]);
|
|
|
|
addDragDropButton(g_Config.touchCombo3, "Combo 4 button", roundImage, comboKeyImages[3]);
|
|
|
|
addDragDropButton(g_Config.touchCombo4, "Combo 5 button", roundImage, comboKeyImages[4]);
|
2020-07-11 22:21:46 +00:00
|
|
|
|
|
|
|
for (size_t i = 0; i < controls_.size(); i++) {
|
|
|
|
Add(controls_[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
Add(new SnapGrid(0, bounds.w, 0, bounds.h, 0x3FFFFFFF));
|
|
|
|
}
|
|
|
|
|
|
|
|
// return the control which was picked up by the touchEvent. If a control
|
|
|
|
// was already picked up, then it's being dragged around, so just return that instead
|
|
|
|
DragDropButton *ControlLayoutView::getPickedControl(const int x, const int y) {
|
|
|
|
if (pickedControl_ != 0) {
|
|
|
|
return pickedControl_;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < controls_.size(); i++) {
|
|
|
|
DragDropButton *control = controls_[i];
|
|
|
|
const Bounds &bounds = control->GetBounds();
|
2020-07-12 08:38:53 +00:00
|
|
|
const float thresholdFactor = 0.25f;
|
|
|
|
const float thresholdW = thresholdFactor * bounds.w;
|
|
|
|
const float thresholdH = thresholdFactor * bounds.h;
|
2020-07-11 22:21:46 +00:00
|
|
|
|
2020-07-12 08:38:53 +00:00
|
|
|
Bounds tolerantBounds(bounds.x - thresholdW * 0.5, bounds.y - thresholdH * 0.5 , bounds.w + thresholdW, bounds.h + thresholdH);
|
2020-07-11 22:21:46 +00:00
|
|
|
if (tolerantBounds.Contains(x, y)) {
|
|
|
|
return control;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
TouchControlLayoutScreen::TouchControlLayoutScreen() {}
|
|
|
|
|
2017-12-27 09:13:47 +00:00
|
|
|
void TouchControlLayoutScreen::resized() {
|
|
|
|
RecreateViews();
|
|
|
|
}
|
2013-10-09 20:15:56 +00:00
|
|
|
|
2013-10-25 11:19:08 +00:00
|
|
|
void TouchControlLayoutScreen::onFinish(DialogResult reason) {
|
2019-02-23 09:49:49 +00:00
|
|
|
g_Config.Save("TouchControlLayoutScreen::onFinish");
|
2013-10-25 11:19:08 +00:00
|
|
|
}
|
|
|
|
|
2013-10-20 15:33:18 +00:00
|
|
|
UI::EventReturn TouchControlLayoutScreen::OnVisibility(UI::EventParams &e) {
|
|
|
|
screenManager()->push(new TouchControlVisibilityScreen());
|
|
|
|
return UI::EVENT_DONE;
|
|
|
|
}
|
|
|
|
|
2013-10-19 22:34:48 +00:00
|
|
|
UI::EventReturn TouchControlLayoutScreen::OnReset(UI::EventParams &e) {
|
2020-08-15 14:13:24 +00:00
|
|
|
INFO_LOG(G3D, "Resetting touch control layout");
|
2013-12-12 13:52:46 +00:00
|
|
|
g_Config.ResetControlLayout();
|
2014-02-10 14:55:21 +00:00
|
|
|
const Bounds &bounds = screenManager()->getUIContext()->GetBounds();
|
|
|
|
InitPadLayout(bounds.w, bounds.h);
|
2013-10-19 22:34:48 +00:00
|
|
|
RecreateViews();
|
|
|
|
return UI::EVENT_DONE;
|
|
|
|
};
|
2013-10-09 20:15:56 +00:00
|
|
|
|
2013-10-20 15:33:18 +00:00
|
|
|
void TouchControlLayoutScreen::dialogFinished(const Screen *dialog, DialogResult result) {
|
|
|
|
RecreateViews();
|
|
|
|
}
|
|
|
|
|
2020-07-11 22:21:07 +00:00
|
|
|
UI::EventReturn TouchControlLayoutScreen::OnMode(UI::EventParams &e) {
|
|
|
|
int mode = mode_->GetSelection();
|
|
|
|
if (layoutView_) {
|
|
|
|
layoutView_->mode_ = mode;
|
|
|
|
}
|
|
|
|
return UI::EVENT_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TouchControlLayoutScreen::update() {
|
|
|
|
UIDialogScreenWithBackground::update();
|
|
|
|
|
|
|
|
// TODO: We really, really need a cleaner solution for creating sub-views
|
|
|
|
// of custom compound controls.
|
|
|
|
if (layoutView_) {
|
|
|
|
if (!layoutView_->HasCreatedViews()) {
|
|
|
|
layoutView_->CreateViews();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-19 22:34:48 +00:00
|
|
|
void TouchControlLayoutScreen::CreateViews() {
|
|
|
|
// setup g_Config for button layout
|
2014-02-10 14:55:21 +00:00
|
|
|
const Bounds &bounds = screenManager()->getUIContext()->GetBounds();
|
|
|
|
InitPadLayout(bounds.w, bounds.h);
|
|
|
|
|
2020-07-11 22:21:07 +00:00
|
|
|
const float leftColumnWidth = 140.0f;
|
|
|
|
|
2013-10-09 20:15:56 +00:00
|
|
|
using namespace UI;
|
|
|
|
|
2020-01-26 18:43:18 +00:00
|
|
|
auto co = GetI18NCategory("Controls");
|
|
|
|
auto di = GetI18NCategory("Dialog");
|
2013-10-09 20:15:56 +00:00
|
|
|
|
|
|
|
root_ = new AnchorLayout(new LayoutParams(FILL_PARENT, FILL_PARENT));
|
|
|
|
|
2015-07-01 21:26:55 +00:00
|
|
|
Choice *reset = new Choice(di->T("Reset"), "", false, new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 84));
|
|
|
|
Choice *back = new Choice(di->T("Back"), "", false, new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 10));
|
2019-12-18 23:41:32 +00:00
|
|
|
Choice *visibility = new Choice(co->T("Visibility"), "", false, new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 298));
|
2015-07-01 20:31:04 +00:00
|
|
|
// controlsSettings->Add(new PopupSliderChoiceFloat(&g_Config.fButtonScale, 0.80, 2.0, co->T("Button Scaling"), screenManager()))
|
2013-12-02 14:15:19 +00:00
|
|
|
// ->OnChange.Handle(this, &GameSettingsScreen::OnChangeControlScaling);
|
|
|
|
|
2019-12-18 23:41:32 +00:00
|
|
|
CheckBox *snap = new CheckBox(&g_Config.bTouchSnapToGrid, di->T("Snap"), "", new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 228));
|
2020-01-12 13:28:51 +00:00
|
|
|
PopupSliderChoice *gridSize = new PopupSliderChoice(&g_Config.iTouchSnapGridSize, 2, 256, di->T("Grid"), screenManager(), "", new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 158));
|
2019-12-19 08:05:08 +00:00
|
|
|
gridSize->SetEnabledPtr(&g_Config.bTouchSnapToGrid);
|
2019-12-18 23:41:32 +00:00
|
|
|
|
|
|
|
mode_ = new ChoiceStrip(ORIENT_VERTICAL, new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 140 + 158 + 64 + 10));
|
2015-07-01 21:26:55 +00:00
|
|
|
mode_->AddChoice(di->T("Move"));
|
|
|
|
mode_->AddChoice(di->T("Resize"));
|
2021-02-28 20:25:37 +00:00
|
|
|
mode_->SetSelection(0, false);
|
2020-07-11 22:21:07 +00:00
|
|
|
mode_->OnChoice.Handle(this, &TouchControlLayoutScreen::OnMode);
|
2013-12-02 14:15:19 +00:00
|
|
|
|
2013-10-19 22:34:48 +00:00
|
|
|
reset->OnClick.Handle(this, &TouchControlLayoutScreen::OnReset);
|
2013-10-28 15:04:53 +00:00
|
|
|
back->OnClick.Handle<UIScreen>(this, &UIScreen::OnBack);
|
2013-10-20 15:33:18 +00:00
|
|
|
visibility->OnClick.Handle(this, &TouchControlLayoutScreen::OnVisibility);
|
2013-12-02 14:15:19 +00:00
|
|
|
root_->Add(mode_);
|
2013-10-20 15:33:18 +00:00
|
|
|
root_->Add(visibility);
|
2019-12-18 23:41:32 +00:00
|
|
|
root_->Add(snap);
|
|
|
|
root_->Add(gridSize);
|
2013-10-19 22:34:48 +00:00
|
|
|
root_->Add(reset);
|
2013-10-09 20:15:56 +00:00
|
|
|
root_->Add(back);
|
|
|
|
|
2013-12-02 14:15:19 +00:00
|
|
|
TabHolder *tabHolder = new TabHolder(ORIENT_VERTICAL, leftColumnWidth, new AnchorLayoutParams(10, 0, 10, 0, false));
|
2016-01-23 06:38:21 +00:00
|
|
|
tabHolder->SetTag("TouchControlLayout");
|
2013-10-09 20:15:56 +00:00
|
|
|
root_->Add(tabHolder);
|
|
|
|
|
2020-07-11 22:21:07 +00:00
|
|
|
layoutView_ = root_->Add(new ControlLayoutView(new AnchorLayoutParams(leftColumnWidth + 10, 0.0f, 0.0f, 0.0f, false)));
|
|
|
|
|
2013-10-28 15:04:53 +00:00
|
|
|
// this is more for show than anything else. It's used to provide a boundary
|
|
|
|
// so that buttons like back can be placed within the boundary.
|
|
|
|
// serves no other purpose.
|
2020-07-11 22:21:07 +00:00
|
|
|
// AnchorLayout *controlsHolder = new AnchorLayout(new LayoutParams(FILL_PARENT, FILL_PARENT));
|
2013-10-09 20:15:56 +00:00
|
|
|
|
2020-01-26 18:43:18 +00:00
|
|
|
auto ms = GetI18NCategory("MainSettings");
|
2013-10-20 10:06:01 +00:00
|
|
|
|
2019-12-19 10:56:42 +00:00
|
|
|
//tabHolder->AddTab(ms->T("Controls"), controlsHolder);
|
2013-10-20 10:06:01 +00:00
|
|
|
|
2013-12-02 14:15:19 +00:00
|
|
|
if (!g_Config.bShowTouchControls) {
|
|
|
|
// Shouldn't even be able to get here as the way into this dialog should be closed.
|
2013-10-20 10:06:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-07-11 22:21:07 +00:00
|
|
|
}
|