mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-09-11 07:03:33 +02:00
Improve touch control layout screen
This commit is contained in:
@@ -50,6 +50,12 @@ public:
|
||||
return false;
|
||||
};
|
||||
|
||||
void Draw(UIContext &dc) override {
|
||||
dc.PushScissor(screenBounds_);
|
||||
MultiTouchButton::Draw(dc);
|
||||
dc.PopScissor();
|
||||
}
|
||||
|
||||
virtual void SavePosition() {
|
||||
x_ = (bounds_.centerX() - screenBounds_.x) / screenBounds_.w;
|
||||
y_ = (bounds_.centerY() - screenBounds_.y) / screenBounds_.h;
|
||||
@@ -67,11 +73,11 @@ protected:
|
||||
float opacity = g_Config.iTouchButtonOpacity / 100.0f;
|
||||
return std::max(0.5f, opacity);
|
||||
}
|
||||
const Bounds &screenBounds_;
|
||||
|
||||
private:
|
||||
float &x_, &y_;
|
||||
float &theScale_;
|
||||
const Bounds &screenBounds_;
|
||||
};
|
||||
|
||||
class PSPActionButtons : public DragDropButton {
|
||||
@@ -99,6 +105,7 @@ public:
|
||||
}
|
||||
|
||||
void Draw(UIContext &dc) override {
|
||||
dc.PushScissor(screenBounds_);
|
||||
uint32_t colorBg = colorAlpha(GetButtonColor(), GetButtonOpacity());
|
||||
uint32_t color = colorAlpha(0xFFFFFF, GetButtonOpacity());
|
||||
|
||||
@@ -127,6 +134,7 @@ public:
|
||||
dc.Draw()->DrawImageRotated(roundId_, centerX - spacing, centerY, scale_, 0, colorBg, false);
|
||||
dc.Draw()->DrawImageRotated(squareId_, centerX - spacing, centerY, scale_, 0, color, false);
|
||||
}
|
||||
dc.PopScissor();
|
||||
};
|
||||
|
||||
void GetContentDimensions(const UIContext &dc, float &w, float &h) const override {
|
||||
@@ -158,6 +166,7 @@ public:
|
||||
}
|
||||
|
||||
void Draw(UIContext &dc) override {
|
||||
dc.PushScissor(screenBounds_);
|
||||
uint32_t colorBg = colorAlpha(GetButtonColor(), GetButtonOpacity());
|
||||
uint32_t color = colorAlpha(0xFFFFFF, GetButtonOpacity());
|
||||
|
||||
@@ -177,9 +186,11 @@ public:
|
||||
dc.Draw()->DrawImageRotated(dirImage, x, y, scale_, angle + PI, colorBg, false);
|
||||
dc.Draw()->DrawImageRotated(ImageID("I_ARROW"), x2, y2, scale_, angle + PI, color);
|
||||
}
|
||||
dc.PopScissor();
|
||||
}
|
||||
|
||||
void GetContentDimensions(const UIContext &dc, float &w, float &h) const override {
|
||||
// TODO: if not all button are visible this dimension is off
|
||||
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_;
|
||||
@@ -272,10 +283,11 @@ void ControlLayoutView::Touch(const TouchInput &touch) {
|
||||
validRange.x = 0.0f;
|
||||
validRange.y = 0.0f;
|
||||
|
||||
validRange.x += controlBounds.w * 0.5f;
|
||||
validRange.w -= controlBounds.w;
|
||||
validRange.y += controlBounds.h * 0.5f;
|
||||
validRange.h -= controlBounds.h;
|
||||
// This make cure the controll is all inside the screen (commended out only half)
|
||||
//validRange.x += controlBounds.w * 0.5f;
|
||||
//validRange.w -= controlBounds.w;
|
||||
//validRange.y += controlBounds.h * 0.5f;
|
||||
//validRange.h -= controlBounds.h;
|
||||
|
||||
Point newPos;
|
||||
newPos.x = startObjectX_ + (touch.x - startDragX_);
|
||||
@@ -339,13 +351,14 @@ void ControlLayoutView::CreateViews() {
|
||||
|
||||
// Create all the views.
|
||||
|
||||
PSPActionButtons *actionButtons = new PSPActionButtons(g_Config.touchActionButtonCenter, "Action buttons", g_Config.fActionButtonSpacing, bounds);
|
||||
actionButtons->setCircleVisibility(g_Config.bShowTouchCircle);
|
||||
actionButtons->setCrossVisibility(g_Config.bShowTouchCross);
|
||||
actionButtons->setTriangleVisibility(g_Config.bShowTouchTriangle);
|
||||
actionButtons->setSquareVisibility(g_Config.bShowTouchSquare);
|
||||
|
||||
controls_.push_back(actionButtons);
|
||||
if (g_Config.bShowTouchCircle || g_Config.bShowTouchCross || g_Config.bShowTouchTriangle || g_Config.bShowTouchSquare) {
|
||||
PSPActionButtons *actionButtons = new PSPActionButtons(g_Config.touchActionButtonCenter, "Action buttons", g_Config.fActionButtonSpacing, bounds);
|
||||
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");
|
||||
@@ -415,6 +428,8 @@ DragDropButton *ControlLayoutView::getPickedControl(const int x, const int y) {
|
||||
return pickedControl_;
|
||||
}
|
||||
|
||||
DragDropButton *bestMatch = nullptr;
|
||||
float bestDistance;
|
||||
for (size_t i = 0; i < controls_.size(); i++) {
|
||||
DragDropButton *control = controls_[i];
|
||||
const Bounds &bounds = control->GetBounds();
|
||||
@@ -424,11 +439,15 @@ DragDropButton *ControlLayoutView::getPickedControl(const int x, const int y) {
|
||||
|
||||
Bounds tolerantBounds(bounds.x - thresholdW * 0.5, bounds.y - thresholdH * 0.5 , bounds.w + thresholdW, bounds.h + thresholdH);
|
||||
if (tolerantBounds.Contains(x, y)) {
|
||||
return control;
|
||||
float distance = (bounds.centerX()-x)*(bounds.centerX()-x)+(bounds.centerY()-y)*(bounds.centerY()-y);
|
||||
if (!bestMatch || distance < bestDistance) {
|
||||
bestDistance = distance;
|
||||
bestMatch = control;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return bestMatch;
|
||||
}
|
||||
|
||||
TouchControlLayoutScreen::TouchControlLayoutScreen() {}
|
||||
@@ -533,9 +552,4 @@ void TouchControlLayoutScreen::CreateViews() {
|
||||
auto ms = GetI18NCategory("MainSettings");
|
||||
|
||||
//tabHolder->AddTab(ms->T("Controls"), controlsHolder);
|
||||
|
||||
if (!g_Config.bShowTouchControls) {
|
||||
// Shouldn't even be able to get here as the way into this dialog should be closed.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user