Merge pull request #12798 from unknownbrackets/ui-display

Cleanup display and touch control layout editors a bit more
This commit is contained in:
Henrik Rydgård authored and GitHub committed 2020-04-05 22:59:26 +02:00
commit 58fa094eaa
3 files changed
+189 -223

No files matched your search

+120 -113
View File
@@ -15,9 +15,11 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include <algorithm>
#include <vector>
#include "base/colorutil.h"
#include "base/display.h"
#include "gfx/texture_atlas.h"
#include "gfx_es2/draw_buffer.h"
#include "i18n/i18n.h"
@@ -34,39 +36,56 @@
static const int leftColumnWidth = 200;
static const float orgRatio = 1.764706f;
// Ugly hackery, need to rework some stuff to get around this
static float local_dp_xres;
static float local_dp_yres;
static const float UI_DISPLAY_SCALE = 8.0f;
static float ScaleSettingToUI() {
float scale = g_Config.fSmallDisplayZoomLevel * UI_DISPLAY_SCALE;
// Account for 1x display doubling dps.
if (g_dpi_scale_x > 1.0f) {
scale *= g_dpi_scale_x;
}
return scale;
}
static void UpdateScaleSetting(float scale) {
// Account for 1x display doubling dps.
if (g_dpi_scale_x > 1.0f) {
scale /= g_dpi_scale_x;
}
g_Config.fSmallDisplayZoomLevel = scale;
}
static void UpdateScaleSettingFromUI(float scale) {
UpdateScaleSetting(scale / UI_DISPLAY_SCALE);
}
class DragDropDisplay : public MultiTouchDisplay {
public:
DragDropDisplay(float &x, float &y, ImageID img, float &scale)
: MultiTouchDisplay(img, scale, new UI::AnchorLayoutParams(x * local_dp_xres, y * local_dp_yres, UI::NONE, UI::NONE, true)),
x_(x), y_(y), theScale_(scale) {
scale_ = theScale_;
DragDropDisplay(float &x, float &y, ImageID img, float scale, const Bounds &screenBounds)
: MultiTouchDisplay(img, scale, new UI::AnchorLayoutParams(x * screenBounds.w, y * screenBounds.h, UI::NONE, UI::NONE, true)),
x_(x), y_(y), screenBounds_(screenBounds) {
UpdateScale(scale);
}
virtual void SaveDisplayPosition() {
x_ = bounds_.centerX() / local_dp_xres;
y_ = bounds_.centerY() / local_dp_yres;
scale_ = theScale_;
void SaveDisplayPosition() {
x_ = bounds_.centerX() / screenBounds_.w;
y_ = bounds_.centerY() / screenBounds_.h;
}
virtual float GetScale() const { return theScale_; }
virtual void SetScale(float s) { theScale_ = s; scale_ = s; }
private:
void UpdateScale(float s) {
scale_ = s;
}
float Scale() {
return scale_;
}
private:
float &x_, &y_;
float &theScale_;
const Bounds &screenBounds_;
};
DisplayLayoutScreen::DisplayLayoutScreen() {
picked_ = 0;
mode_ = nullptr;
};
bool DisplayLayoutScreen::touch(const TouchInput &touch) {
UIScreen::touch(touch);
@@ -78,23 +97,22 @@ bool DisplayLayoutScreen::touch(const TouchInput &touch) {
}
const Bounds &screen_bounds = screenManager()->getUIContext()->GetBounds();
if ((touch.flags & TOUCH_MOVE) && picked_ != 0) {
int touchX = touch.x - offsetTouchX;
int touchY = touch.y - offsetTouchY;
if ((touch.flags & TOUCH_MOVE) != 0 && dragging_) {
int touchX = touch.x - offsetTouchX_;
int touchY = touch.y - offsetTouchY_;
if (mode == 0) {
const Bounds &bounds = picked_->GetBounds();
const auto &prevParams = displayRepresentation_->GetLayoutParams()->As<AnchorLayoutParams>();
Point newPos(prevParams->left, prevParams->top);
int limitX = g_Config.fSmallDisplayZoomLevel * 120;
int limitY = g_Config.fSmallDisplayZoomLevel * 68;
const int quarterResX = local_dp_xres / 4;
const int quarterResY = local_dp_yres / 4;
const int quarterResX = screen_bounds.w / 4;
const int quarterResY = screen_bounds.h / 4;
if (bRotated) {
if (bRotated_) {
//swap X/Y limit for rotated display
int limitTemp = limitX;
limitX = limitY;
limitY = limitTemp;
std::swap(limitX, limitY);
}
// Check where each edge of the screen is
@@ -103,16 +121,17 @@ bool DisplayLayoutScreen::touch(const TouchInput &touch) {
const int windowUpperEdge = quarterResY;
const int windowLowerEdge = windowUpperEdge * 3;
// And stick display when close to any edge
stickToEdgeX = false; stickToEdgeY = false;
if (touchX > windowLeftEdge - 8 + limitX && touchX < windowLeftEdge + 8 + limitX) { touchX = windowLeftEdge + limitX; stickToEdgeX = true; }
if (touchX > windowRightEdge - 8 - limitX && touchX < windowRightEdge + 8 - limitX) { touchX = windowRightEdge - limitX; stickToEdgeX = true; }
if (touchY > windowUpperEdge - 8 + limitY && touchY < windowUpperEdge + 8 + limitY) { touchY = windowUpperEdge + limitY; stickToEdgeY = true; }
if (touchY > windowLowerEdge - 8 - limitY && touchY < windowLowerEdge + 8 - limitY) { touchY = windowLowerEdge - limitY; stickToEdgeY = true; }
stickToEdgeX_ = false;
stickToEdgeY_ = false;
if (touchX > windowLeftEdge - 8 + limitX && touchX < windowLeftEdge + 8 + limitX) { touchX = windowLeftEdge + limitX; stickToEdgeX_ = true; }
if (touchX > windowRightEdge - 8 - limitX && touchX < windowRightEdge + 8 - limitX) { touchX = windowRightEdge - limitX; stickToEdgeX_ = true; }
if (touchY > windowUpperEdge - 8 + limitY && touchY < windowUpperEdge + 8 + limitY) { touchY = windowUpperEdge + limitY; stickToEdgeY_ = true; }
if (touchY > windowLowerEdge - 8 - limitY && touchY < windowLowerEdge + 8 - limitY) { touchY = windowLowerEdge - limitY; stickToEdgeY_ = true; }
const int minX = local_dp_xres / 2;
const int maxX = local_dp_xres + minX;
const int minY = local_dp_yres / 2;
const int maxY = local_dp_yres + minY;
const int minX = screen_bounds.w / 2;
const int maxX = screen_bounds.w + minX;
const int minY = screen_bounds.h / 2;
const int maxY = screen_bounds.h + minY;
// Display visualization disappear outside of those bounds, so we have to limit
if (touchX < -minX) touchX = -minX;
if (touchX > maxX) touchX = maxX;
@@ -123,49 +142,37 @@ bool DisplayLayoutScreen::touch(const TouchInput &touch) {
if (quarterResX > limitX) limitX = quarterResX;
if (quarterResY > limitY) limitY = quarterResY;
int newX = bounds.centerX(), newY = bounds.centerY();
// Allow moving zoomed in display freely as long as at least noticeable portion of the screen is occupied
if (touchX > minX - limitX - 10 && touchX < minX + limitX + 10) {
newX = touchX;
newPos.x = touchX;
}
if (touchY > minY - limitY - 10 && touchY < minY + limitY + 10) {
newY = touchY;
newPos.y = touchY;
}
picked_->ReplaceLayoutParams(new UI::AnchorLayoutParams(newX, newY, NONE, NONE, true));
displayRepresentation_->ReplaceLayoutParams(new AnchorLayoutParams(newPos.x, newPos.y, NONE, NONE, true));
} else if (mode == 1) {
// Resize. Vertical = scaling, horizontal = spacing;
// Up should be bigger so let's negate in that direction
float diffX = (touchX - startX_);
// Resize. Vertical = scaling; Up should be bigger so let's negate in that direction
float diffY = -(touchY - startY_);
float movementScale = 0.5f;
float newScale = startScale_ + diffY * movementScale;
// Desired scale * 8.0 since the visualization is tiny size and multiplied by 8.
if (newScale > 80.0f) newScale = 80.0f;
if (newScale < 8.0f) newScale = 8.0f;
picked_->SetScale(newScale);
scaleUpdate_ = picked_->GetScale();
g_Config.fSmallDisplayZoomLevel = scaleUpdate_ / 8.0f;
newScale = clamp_value(newScale, UI_DISPLAY_SCALE, UI_DISPLAY_SCALE * 10.0f);
displayRepresentation_->UpdateScale(newScale);
UpdateScaleSettingFromUI(newScale);
}
}
if ((touch.flags & TOUCH_DOWN) && picked_ == 0) {
picked_ = displayRepresentation_;
if (picked_) {
const Bounds &bounds = picked_->GetBounds();
startX_ = bounds.centerX();
startY_ = bounds.centerY();
offsetTouchX = touch.x - startX_;
offsetTouchY = touch.y - startY_;
startScale_ = picked_->GetScale();
}
if ((touch.flags & TOUCH_DOWN) != 0 && !dragging_) {
dragging_ = true;
const Bounds &bounds = displayRepresentation_->GetBounds();
startY_ = bounds.centerY();
offsetTouchX_ = touch.x - bounds.centerX();
offsetTouchY_ = touch.y - bounds.centerY();
startScale_ = displayRepresentation_->Scale();
}
if ((touch.flags & TOUCH_UP) && picked_ != 0) {
const Bounds &bounds = picked_->GetBounds();
float saveX_ = touch.x;
float saveY_ = touch.y;
startScale_ = picked_->GetScale();
picked_->SaveDisplayPosition();
picked_ = 0;
if ((touch.flags & TOUCH_UP) != 0 && dragging_) {
displayRepresentation_->SaveDisplayPosition();
dragging_ = false;
}
return true;
}
@@ -179,9 +186,9 @@ void DisplayLayoutScreen::onFinish(DialogResult reason) {
}
UI::EventReturn DisplayLayoutScreen::OnCenter(UI::EventParams &e) {
if (!stickToEdgeX || (stickToEdgeX && stickToEdgeY))
if (!stickToEdgeX_ || (stickToEdgeX_ && stickToEdgeY_))
g_Config.fSmallDisplayOffsetX = 0.5f;
if (!stickToEdgeY || (stickToEdgeX && stickToEdgeY))
if (!stickToEdgeY_ || (stickToEdgeX_ && stickToEdgeY_))
g_Config.fSmallDisplayOffsetY = 0.5f;
RecreateViews();
return UI::EVENT_DONE;
@@ -191,8 +198,8 @@ UI::EventReturn DisplayLayoutScreen::OnZoomTypeChange(UI::EventParams &e) {
if (g_Config.iSmallDisplayZoomType < (int)SmallDisplayZoom::MANUAL) {
const Bounds &bounds = screenManager()->getUIContext()->GetBounds();
float autoBound = bounds.w / 480.0f;
g_Config.fSmallDisplayZoomLevel = autoBound;
displayRepresentationScale_ = g_Config.fSmallDisplayZoomLevel * 8.0f;
UpdateScaleSetting(autoBound);
displayRepresentation_->UpdateScale(ScaleSettingToUI());
g_Config.fSmallDisplayOffsetX = 0.5f;
g_Config.fSmallDisplayOffsetY = 0.5f;
}
@@ -228,9 +235,6 @@ public:
void DisplayLayoutScreen::CreateViews() {
const Bounds &bounds = screenManager()->getUIContext()->GetBounds();
local_dp_xres = bounds.w;
local_dp_yres = bounds.h;
using namespace UI;
auto di = GetI18NCategory("Dialog");
@@ -239,12 +243,12 @@ void DisplayLayoutScreen::CreateViews() {
root_ = new AnchorLayout(new LayoutParams(FILL_PARENT, FILL_PARENT));
const float previewWidth = local_dp_xres / 2.0f;
const float previewHeight = local_dp_yres / 2.0f;
const float previewWidth = bounds.w / 2.0f;
const float previewHeight = bounds.h / 2.0f;
// Just visual boundaries of the screen, should be easier to use than imagination
const float horizPreviewPadding = local_dp_xres / 4.0f;
const float vertPreviewPadding = local_dp_yres / 4.0f;
const float horizPreviewPadding = bounds.w / 4.0f;
const float vertPreviewPadding = bounds.h / 4.0f;
const float horizBoundariesWidth = 4.0f;
// This makes it have at least 10.0f padding below at 1x.
const float vertBoundariesHeight = 52.0f;
@@ -255,64 +259,56 @@ void DisplayLayoutScreen::CreateViews() {
root_->Add(new Boundary(new AnchorLayoutParams(previewWidth, vertBoundariesHeight, horizPreviewPadding, vertPreviewPadding - vertBoundariesHeight, NONE, NONE)));
root_->Add(new Boundary(new AnchorLayoutParams(previewWidth, vertBoundariesHeight, horizPreviewPadding, NONE, NONE, vertPreviewPadding - vertBoundariesHeight)));
static const char *zoomLevels[] = { "Stretching", "Partial Stretch", "Auto Scaling", "Manual Scaling" };
zoom_ = new PopupMultiChoice(&g_Config.iSmallDisplayZoomType, di->T("Options"), zoomLevels, 0, ARRAY_SIZE(zoomLevels), gr->GetName(), screenManager(), new AnchorLayoutParams(400, WRAP_CONTENT, previewWidth - 200.0f, NONE, NONE, 10));
zoom_->OnChoice.Handle(this, &DisplayLayoutScreen::OnZoomTypeChange);
static const char *displayRotation[] = { "Landscape", "Portrait", "Landscape Reversed", "Portrait Reversed" };
rotation_ = new PopupMultiChoice(&g_Config.iInternalScreenRotation, gr->T("Rotation"), displayRotation, 1, ARRAY_SIZE(displayRotation), co->GetName(), screenManager(), new AnchorLayoutParams(400, WRAP_CONTENT, previewWidth - 200.0f, 10, NONE, local_dp_yres - 64 - 10));
rotation_->SetEnabledFunc([] {
return g_Config.iRenderingMode != FB_NON_BUFFERED_MODE;
});
bool displayRotEnable = (g_Config.iRenderingMode != FB_NON_BUFFERED_MODE);
bRotated = false;
bRotated_ = false;
if (displayRotEnable && (g_Config.iInternalScreenRotation == ROTATION_LOCKED_VERTICAL || g_Config.iInternalScreenRotation == ROTATION_LOCKED_VERTICAL180)) {
bRotated = true;
bRotated_ = true;
}
displayRepresentationScale_ = g_Config.fSmallDisplayZoomLevel * 8.0f; // Visual representation image is just icon size and have to be scaled 8 times to match PSP native resolution which is used as 1.0 for zoom
HighlightLabel *label = nullptr;
mode_ = nullptr;
if (g_Config.iSmallDisplayZoomType >= (int)SmallDisplayZoom::AUTO) { // Scaling
if (g_Config.iSmallDisplayZoomType == (int)SmallDisplayZoom::AUTO) {
label = new HighlightLabel(gr->T("Auto Scaling"), new AnchorLayoutParams(WRAP_CONTENT, 64.0f, local_dp_xres / 2.0f, local_dp_yres / 2.0f, NONE, NONE, true));
float autoBound = local_dp_yres / 270.0f;
label = new HighlightLabel(gr->T("Auto Scaling"), new AnchorLayoutParams(WRAP_CONTENT, 64.0f, bounds.w / 2.0f, bounds.h / 2.0f, NONE, NONE, true));
float autoBound = bounds.h / 270.0f;
// Case of screen rotated ~ only works with buffered rendering
if (bRotated) {
autoBound = local_dp_yres / 480.0f;
}
else { // Without rotation in common cases like 1080p we cut off 2 pixels of height, this reflects other cases
if (bRotated_) {
autoBound = bounds.h / 480.0f;
} else { // Without rotation in common cases like 1080p we cut off 2 pixels of height, this reflects other cases
float resCommonWidescreen = autoBound - floor(autoBound);
if (resCommonWidescreen != 0.0f) {
float ratio = local_dp_xres / local_dp_yres;
float ratio = bounds.w / bounds.h;
if (ratio < orgRatio) {
autoBound = local_dp_xres / 480.0f;
autoBound = bounds.w / 480.0f;
}
else {
autoBound = local_dp_yres / 272.0f;
autoBound = bounds.h / 272.0f;
}
}
}
g_Config.fSmallDisplayZoomLevel = autoBound;
displayRepresentationScale_ = g_Config.fSmallDisplayZoomLevel * 8.0f;
UpdateScaleSetting(autoBound);
g_Config.fSmallDisplayOffsetX = 0.5f;
g_Config.fSmallDisplayOffsetY = 0.5f;
} else { // Manual Scaling
Choice *center = new Choice(di->T("Center"), "", false, new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 74));
center->OnClick.Handle(this, &DisplayLayoutScreen::OnCenter);
root_->Add(center);
PopupSliderChoiceFloat *zoomlvl = new PopupSliderChoiceFloat(&g_Config.fSmallDisplayZoomLevel, 1.0f, 10.0f, di->T("Zoom"), 1.0f, screenManager(), di->T("* PSP res"), new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 10 + 64 + 64));
float minZoom = 1.0f;
if (g_dpi_scale_x > 1.0f) {
minZoom /= g_dpi_scale_x;
}
PopupSliderChoiceFloat *zoomlvl = new PopupSliderChoiceFloat(&g_Config.fSmallDisplayZoomLevel, minZoom, 10.0f, di->T("Zoom"), 1.0f, screenManager(), di->T("* PSP res"), new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 10 + 64 + 64));
root_->Add(zoomlvl);
mode_ = new ChoiceStrip(ORIENT_VERTICAL, new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 158 + 64 + 10));
mode_->AddChoice(di->T("Move"));
mode_->AddChoice(di->T("Resize"));
mode_->SetSelection(0);
}
displayRepresentation_ = new DragDropDisplay(g_Config.fSmallDisplayOffsetX, g_Config.fSmallDisplayOffsetY, ImageID("I_PSP_DISPLAY"), displayRepresentationScale_);
displayRepresentation_ = new DragDropDisplay(g_Config.fSmallDisplayOffsetX, g_Config.fSmallDisplayOffsetY, ImageID("I_PSP_DISPLAY"), ScaleSettingToUI(), bounds);
displayRepresentation_->SetVisibility(V_VISIBLE);
} else { // Stretching
label = new HighlightLabel(gr->T("Stretching"), new AnchorLayoutParams(WRAP_CONTENT, 64.0f, local_dp_xres / 2.0f, local_dp_yres / 2.0f, NONE, NONE, true));
displayRepresentation_ = new DragDropDisplay(g_Config.fSmallDisplayOffsetX, g_Config.fSmallDisplayOffsetY, ImageID("I_PSP_DISPLAY"), displayRepresentationScale_);
label = new HighlightLabel(gr->T("Stretching"), new AnchorLayoutParams(WRAP_CONTENT, 64.0f, bounds.w / 2.0f, bounds.h / 2.0f, NONE, NONE, true));
displayRepresentation_ = new DragDropDisplay(g_Config.fSmallDisplayOffsetX, g_Config.fSmallDisplayOffsetY, ImageID("I_PSP_DISPLAY"), ScaleSettingToUI(), bounds);
displayRepresentation_->SetVisibility(V_INVISIBLE);
float width = previewWidth;
float height = previewHeight;
@@ -321,16 +317,16 @@ void DisplayLayoutScreen::CreateViews() {
stretched->SetEnabled(false);
root_->Add(stretched);
} else { // Partially stretched
float origRatio = !bRotated ? 480.0f / 272.0f : 272.0f / 480.0f;
float origRatio = !bRotated_ ? 480.0f / 272.0f : 272.0f / 480.0f;
float frameRatio = width / height;
if (origRatio > frameRatio) {
height = width / origRatio;
if (!bRotated && g_Config.iSmallDisplayZoomType == (int)SmallDisplayZoom::PARTIAL_STRETCH) {
if (!bRotated_ && g_Config.iSmallDisplayZoomType == (int)SmallDisplayZoom::PARTIAL_STRETCH) {
height = (272.0f + height) / 2.0f;
}
} else {
width = height * origRatio;
if (bRotated && g_Config.iSmallDisplayZoomType == (int)SmallDisplayZoom::PARTIAL_STRETCH) {
if (bRotated_ && g_Config.iSmallDisplayZoomType == (int)SmallDisplayZoom::PARTIAL_STRETCH) {
width = (272.0f + height) / 2.0f;
}
}
@@ -339,12 +335,10 @@ void DisplayLayoutScreen::CreateViews() {
root_->Add(stretched);
}
}
if (bRotated) {
if (bRotated_) {
displayRepresentation_->SetAngle(90.0f);
}
Choice *back = new Choice(di->T("Back"), "", false, new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 10));
back->OnClick.Handle<UIScreen>(this, &UIScreen::OnBack);
root_->Add(displayRepresentation_);
if (mode_) {
root_->Add(mode_);
@@ -352,7 +346,20 @@ void DisplayLayoutScreen::CreateViews() {
if (label) {
root_->Add(label);
}
root_->Add(zoom_);
root_->Add(rotation_);
static const char *zoomLevels[] = { "Stretching", "Partial Stretch", "Auto Scaling", "Manual Scaling" };
auto zoom = new PopupMultiChoice(&g_Config.iSmallDisplayZoomType, di->T("Options"), zoomLevels, 0, ARRAY_SIZE(zoomLevels), gr->GetName(), screenManager(), new AnchorLayoutParams(400, WRAP_CONTENT, previewWidth - 200.0f, NONE, NONE, 10));
zoom->OnChoice.Handle(this, &DisplayLayoutScreen::OnZoomTypeChange);
root_->Add(zoom);
static const char *displayRotation[] = { "Landscape", "Portrait", "Landscape Reversed", "Portrait Reversed" };
auto rotation = new PopupMultiChoice(&g_Config.iInternalScreenRotation, gr->T("Rotation"), displayRotation, 1, ARRAY_SIZE(displayRotation), co->GetName(), screenManager(), new AnchorLayoutParams(400, WRAP_CONTENT, previewWidth - 200.0f, 10, NONE, bounds.h - 64 - 10));
rotation->SetEnabledFunc([] {
return g_Config.iRenderingMode != FB_NON_BUFFERED_MODE;
});
root_->Add(rotation);
Choice *back = new Choice(di->T("Back"), "", false, new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 10));
back->OnClick.Handle<UIScreen>(this, &UIScreen::OnBack);
root_->Add(back);
}
+10 -13
View File
@@ -39,19 +39,16 @@ protected:
virtual UI::EventReturn OnZoomTypeChange(UI::EventParams &e);
private:
DragDropDisplay *picked_;
DragDropDisplay *displayRepresentation_;
UI::ChoiceStrip *mode_;
UI::PopupMultiChoice *zoom_;
UI::PopupMultiChoice *rotation_;
bool bRotated;
bool stickToEdgeX;
bool stickToEdgeY;
DragDropDisplay *displayRepresentation_ = nullptr;
UI::ChoiceStrip *mode_ = nullptr;
bool dragging_ = false;
bool bRotated_ = false;
bool stickToEdgeX_ = false;
bool stickToEdgeY_ = false;
// Touch down state for drag to resize etc
float startX_;
float startY_;
float startScale_, scaleUpdate_;
float displayRepresentationScale_;
int offsetTouchX, offsetTouchY;
float startY_ = 0.0f;
float startScale_ = 1.0f;
int offsetTouchX_ = 0;
int offsetTouchY_ = 0;
};
+59 -97
View File
@@ -33,19 +33,15 @@
static const int leftColumnWidth = 140;
// Ugly hackery, need to rework some stuff to get around this
static float local_dp_xres;
static float local_dp_yres;
static u32 GetButtonColor() {
return g_Config.iTouchButtonStyle != 0 ? 0xFFFFFF : 0xc0b080;
}
class DragDropButton : public MultiTouchButton {
public:
DragDropButton(ConfigTouchPos &pos, ImageID bgImg, ImageID img)
: MultiTouchButton(bgImg, bgImg, img, pos.scale, new UI::AnchorLayoutParams(fromFullscreenCoord(pos.x), pos.y * local_dp_yres, UI::NONE, UI::NONE, true)),
x_(pos.x), y_(pos.y), theScale_(pos.scale) {
DragDropButton(ConfigTouchPos &pos, ImageID bgImg, ImageID img, const Bounds &screenBounds)
: MultiTouchButton(bgImg, bgImg, img, pos.scale, new UI::AnchorLayoutParams(fromFullscreenCoord(pos.x, screenBounds), pos.y * screenBounds.h, UI::NONE, UI::NONE, true)),
x_(pos.x), y_(pos.y), theScale_(pos.scale), screenBounds_(screenBounds) {
scale_ = theScale_;
}
@@ -57,7 +53,7 @@ public:
virtual void SavePosition() {
x_ = toFullscreenCoord(bounds_.centerX());
y_ = bounds_.centerY() / local_dp_yres;
y_ = bounds_.centerY() / screenBounds_.h;
scale_ = theScale_;
}
@@ -76,22 +72,23 @@ protected:
private:
// convert from screen coordinates (leftColumnWidth to dp_xres) to actual fullscreen coordinates (0 to 1.0)
inline float toFullscreenCoord(int screenx) {
return (float)(screenx - leftColumnWidth) / (local_dp_xres - leftColumnWidth);
return (float)(screenx - leftColumnWidth) / (screenBounds_.w - leftColumnWidth);
}
// convert from external fullscreen coordinates(0 to 1.0) to the current partial coordinates (leftColumnWidth to dp_xres)
inline int fromFullscreenCoord(float controllerX) {
return leftColumnWidth + (local_dp_xres - leftColumnWidth) * controllerX;
inline int fromFullscreenCoord(float controllerX, const Bounds &screenBounds) {
return leftColumnWidth + (screenBounds.w - leftColumnWidth) * controllerX;
};
float &x_, &y_;
float &theScale_;
const Bounds &screenBounds_;
};
class PSPActionButtons : public DragDropButton {
public:
PSPActionButtons(ConfigTouchPos &pos, float &spacing)
: DragDropButton(pos, ImageID::invalid(), ImageID::invalid()), spacing_(spacing) {
PSPActionButtons(ConfigTouchPos &pos, float &spacing, const Bounds &screenBounds)
: DragDropButton(pos, ImageID::invalid(), ImageID::invalid(), screenBounds), spacing_(spacing) {
using namespace UI;
roundId_ = g_Config.iTouchButtonStyle ? ImageID("I_ROUND_LINE") : ImageID("I_ROUND");
};
@@ -169,8 +166,8 @@ private:
class PSPDPadButtons : public DragDropButton {
public:
PSPDPadButtons(ConfigTouchPos &pos, float &spacing)
: DragDropButton(pos, ImageID::invalid(), ImageID::invalid()), spacing_(spacing) {
PSPDPadButtons(ConfigTouchPos &pos, float &spacing, const Bounds &screenBounds)
: DragDropButton(pos, ImageID::invalid(), ImageID::invalid(), screenBounds), spacing_(spacing) {
}
void Draw(UIContext &dc) override {
@@ -342,9 +339,6 @@ void TouchControlLayoutScreen::CreateViews() {
const Bounds &bounds = screenManager()->getUIContext()->GetBounds();
InitPadLayout(bounds.w, bounds.h);
local_dp_xres = bounds.w;
local_dp_yres = bounds.h;
using namespace UI;
auto co = GetI18NCategory("Controls");
@@ -397,7 +391,7 @@ void TouchControlLayoutScreen::CreateViews() {
controls_.clear();
PSPActionButtons *actionButtons = new PSPActionButtons(g_Config.touchActionButtonCenter, g_Config.fActionButtonSpacing);
PSPActionButtons *actionButtons = new PSPActionButtons(g_Config.touchActionButtonCenter, g_Config.fActionButtonSpacing, bounds);
actionButtons->setCircleVisibility(g_Config.bShowTouchCircle);
actionButtons->setCrossVisibility(g_Config.bShowTouchCross);
actionButtons->setTriangleVisibility(g_Config.bShowTouchTriangle);
@@ -414,86 +408,54 @@ void TouchControlLayoutScreen::CreateViews() {
const ImageID comboKeyImages[5] = { ImageID("I_1"), ImageID("I_2"), ImageID("I_3"), ImageID("I_4"), ImageID("I_5") };
if (g_Config.touchDpad.show) {
controls_.push_back(new PSPDPadButtons(g_Config.touchDpad, g_Config.fDpadSpacing));
}
if (g_Config.touchSelectKey.show) {
controls_.push_back(new DragDropButton(g_Config.touchSelectKey, rectImage, ImageID("I_SELECT")));
}
if (g_Config.touchStartKey.show) {
controls_.push_back(new DragDropButton(g_Config.touchStartKey, rectImage, ImageID("I_START")));
}
if (g_Config.touchUnthrottleKey.show) {
DragDropButton *unthrottle = new DragDropButton(g_Config.touchUnthrottleKey, rectImage, ImageID("I_ARROW"));
unthrottle->SetAngle(180.0f);
controls_.push_back(unthrottle);
}
if (g_Config.touchSpeed1Key.show) {
DragDropButton *speed1 = new DragDropButton(g_Config.touchSpeed1Key, rectImage, ImageID("I_ARROW"));
speed1->SetAngle(170.0f, 180.0f);
controls_.push_back(speed1);
}
if (g_Config.touchSpeed2Key.show) {
DragDropButton *speed2 = new DragDropButton(g_Config.touchSpeed2Key, rectImage, ImageID("I_ARROW"));
speed2->SetAngle(190.0f, 180.0f);
controls_.push_back(speed2);
}
if (g_Config.touchRapidFireKey.show) {
DragDropButton *rapidFire = new DragDropButton(g_Config.touchRapidFireKey, rectImage, ImageID("I_ARROW"));
rapidFire->SetAngle(90.0f, 180.0f);
controls_.push_back(rapidFire);
}
if (g_Config.touchAnalogRotationCWKey.show) {
DragDropButton *analogRotationCW = new DragDropButton(g_Config.touchAnalogRotationCWKey, rectImage, ImageID("I_ARROW"));
analogRotationCW->SetAngle(190.0f, 180.0f);
controls_.push_back(analogRotationCW);
}
if (g_Config.touchAnalogRotationCCWKey.show) {
DragDropButton *analogRotationCCW = new DragDropButton(g_Config.touchAnalogRotationCCWKey, rectImage, ImageID("I_ARROW"));
analogRotationCCW->SetAngle(350.0f, 180.0f);
controls_.push_back(analogRotationCCW);
}
if (g_Config.touchLKey.show) {
controls_.push_back(new DragDropButton(g_Config.touchLKey, shoulderImage, ImageID("I_L")));
}
if (g_Config.touchRKey.show) {
DragDropButton *rbutton = new DragDropButton(g_Config.touchRKey, shoulderImage, ImageID("I_R"));
rbutton->FlipImageH(true);
controls_.push_back(rbutton);
}
if (g_Config.touchAnalogStick.show) {
controls_.push_back(new DragDropButton(g_Config.touchAnalogStick, stickBg, stickImage));
}
if (g_Config.touchRightAnalogStick.show) {
controls_.push_back(new DragDropButton(g_Config.touchRightAnalogStick, stickBg, stickImage));
}
if (g_Config.touchCombo0.show) {
controls_.push_back(new DragDropButton(g_Config.touchCombo0, roundImage, comboKeyImages[0]));
}
if (g_Config.touchCombo1.show) {
controls_.push_back(new DragDropButton(g_Config.touchCombo1, roundImage, comboKeyImages[1]));
}
if (g_Config.touchCombo2.show) {
controls_.push_back(new DragDropButton(g_Config.touchCombo2, roundImage, comboKeyImages[2]));
}
if (g_Config.touchCombo3.show) {
controls_.push_back(new DragDropButton(g_Config.touchCombo3, roundImage, comboKeyImages[3]));
}
if (g_Config.touchCombo4.show) {
controls_.push_back(new DragDropButton(g_Config.touchCombo4, roundImage, comboKeyImages[4]));
auto addDragDropButton = [&](ConfigTouchPos &pos, ImageID bgImg, ImageID img) {
DragDropButton *b = nullptr;
if (pos.show) {
b = new DragDropButton(pos, bgImg, img, bounds);
controls_.push_back(b);
}
return b;
};
if (g_Config.touchDpad.show) {
controls_.push_back(new PSPDPadButtons(g_Config.touchDpad, g_Config.fDpadSpacing, bounds));
}
addDragDropButton(g_Config.touchSelectKey, rectImage, ImageID("I_SELECT"));
addDragDropButton(g_Config.touchStartKey, rectImage, ImageID("I_START"));
if (auto *unthrottle = addDragDropButton(g_Config.touchUnthrottleKey, rectImage, ImageID("I_ARROW"))) {
unthrottle->SetAngle(180.0f);
}
if (auto *speed1 = addDragDropButton(g_Config.touchSpeed1Key, rectImage, ImageID("I_ARROW"))) {
speed1->SetAngle(170.0f, 180.0f);
}
if (auto *speed2 = addDragDropButton(g_Config.touchSpeed2Key, rectImage, ImageID("I_ARROW"))) {
speed2->SetAngle(190.0f, 180.0f);
}
if (auto *rapidFire = addDragDropButton(g_Config.touchRapidFireKey, rectImage, ImageID("I_ARROW"))) {
rapidFire->SetAngle(90.0f, 180.0f);
}
if (auto *analogRotationCW = addDragDropButton(g_Config.touchAnalogRotationCWKey, rectImage, ImageID("I_ARROW"))) {
analogRotationCW->SetAngle(190.0f, 180.0f);
}
if (auto *analogRotationCCW = addDragDropButton(g_Config.touchAnalogRotationCCWKey, rectImage, ImageID("I_ARROW"))) {
analogRotationCCW->SetAngle(350.0f, 180.0f);
}
addDragDropButton(g_Config.touchLKey, shoulderImage, ImageID("I_L"));
if (auto *rbutton = addDragDropButton(g_Config.touchRKey, shoulderImage, ImageID("I_R"))) {
rbutton->FlipImageH(true);
}
addDragDropButton(g_Config.touchAnalogStick, stickBg, stickImage);
addDragDropButton(g_Config.touchRightAnalogStick, stickBg, stickImage);
addDragDropButton(g_Config.touchCombo0, roundImage, comboKeyImages[0]);
addDragDropButton(g_Config.touchCombo1, roundImage, comboKeyImages[1]);
addDragDropButton(g_Config.touchCombo2, roundImage, comboKeyImages[2]);
addDragDropButton(g_Config.touchCombo3, roundImage, comboKeyImages[3]);
addDragDropButton(g_Config.touchCombo4, roundImage, comboKeyImages[4]);
for (size_t i = 0; i < controls_.size(); i++) {
root_->Add(controls_[i]);
}