From 3bba9df133fa60f54e20e39c1a0a4c34380a9c53 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Fri, 21 Sep 2018 23:24:36 -0700 Subject: [PATCH] UI: Keep report image at right aspect ratio. --- UI/PauseScreen.cpp | 31 ++++++++++++++++++++++++++++++- UI/PauseScreen.h | 2 +- UI/ReportScreen.cpp | 2 +- ext/native/ui/view.h | 1 + 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/UI/PauseScreen.cpp b/UI/PauseScreen.cpp index c046a11623..c37f79fb32 100644 --- a/UI/PauseScreen.cpp +++ b/UI/PauseScreen.cpp @@ -15,6 +15,7 @@ // Official git repository and contact information can be found at // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. +#include #include "i18n/i18n.h" #include "gfx_es2/draw_buffer.h" #include "ui/view.h" @@ -48,15 +49,43 @@ AsyncImageFileView::AsyncImageFileView(const std::string &filename, UI::ImageSiz AsyncImageFileView::~AsyncImageFileView() {} -void AsyncImageFileView::GetContentDimensions(const UIContext &dc, float &w, float &h) const { +static float DesiredSize(float sz, float contentSize, UI::MeasureSpec spec) { + float measured; + UI::MeasureBySpec(sz, contentSize, spec, &measured); + return measured; +} + +void AsyncImageFileView::GetContentDimensionsBySpec(const UIContext &dc, UI::MeasureSpec horiz, UI::MeasureSpec vert, float &w, float &h) const { if (texture_ && texture_->GetTexture()) { float texw = (float)texture_->Width(); float texh = (float)texture_->Height(); + float desiredW = DesiredSize(layoutParams_->width, w, horiz); + float desiredH = DesiredSize(layoutParams_->height, h, vert); switch (sizeMode_) { case UI::IS_FIXED: w = fixedSizeW_; h = fixedSizeH_; break; + case UI::IS_KEEP_ASPECT: + w = texw; + h = texh; + if (desiredW != w || desiredH != h) { + float aspect = w / h; + // We need the other dimension based on the desired scale to find the best aspect. + float desiredWOther = DesiredSize(layoutParams_->height, h * (desiredW / w), vert); + float desiredHOther = DesiredSize(layoutParams_->width, w * (desiredH / h), horiz); + + float diffW = fabsf(aspect - desiredW / desiredWOther); + float diffH = fabsf(aspect - desiredH / desiredHOther); + if (diffW < diffH) { + w = desiredW; + h = desiredWOther; + } else { + w = desiredHOther; + h = desiredH; + } + } + break; case UI::IS_DEFAULT: default: w = texw; diff --git a/UI/PauseScreen.h b/UI/PauseScreen.h index c6ffd88b0b..8e951ffaf0 100644 --- a/UI/PauseScreen.h +++ b/UI/PauseScreen.h @@ -67,7 +67,7 @@ public: AsyncImageFileView(const std::string &filename, UI::ImageSizeMode sizeMode, PrioritizedWorkQueue *wq, UI::LayoutParams *layoutParams = 0); ~AsyncImageFileView(); - void GetContentDimensions(const UIContext &dc, float &w, float &h) const override; + void GetContentDimensionsBySpec(const UIContext &dc, UI::MeasureSpec horiz, UI::MeasureSpec vert, float &w, float &h) const override; void Draw(UIContext &dc) override; void DeviceLost() override; diff --git a/UI/ReportScreen.cpp b/UI/ReportScreen.cpp index 8d8fb86100..ae10ed1660 100644 --- a/UI/ReportScreen.cpp +++ b/UI/ReportScreen.cpp @@ -261,7 +261,7 @@ void ReportScreen::CreateViews() { if (TakeGameScreenshot(screenshotFilename_.c_str(), ScreenshotFormat::JPG, SCREENSHOT_DISPLAY, &shotWidth, &shotHeight, 4)) { float scale = 340.0f * (1.0f / g_dpi_scale_y) * (1.0f / shotHeight); leftColumnItems->Add(new CheckBox(&includeScreenshot_, rp->T("FeedbackIncludeScreen", "Include a screenshot")))->SetEnabledPtr(&enableReporting_); - screenshot_ = leftColumnItems->Add(new AsyncImageFileView(screenshotFilename_, IS_DEFAULT, nullptr, new LinearLayoutParams(shotWidth * scale, shotHeight * scale, Margins(12, 0)))); + screenshot_ = leftColumnItems->Add(new AsyncImageFileView(screenshotFilename_, IS_KEEP_ASPECT, nullptr, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT, Margins(12, 0)))); } else { includeScreenshot_ = false; screenshot_ = nullptr; diff --git a/ext/native/ui/view.h b/ext/native/ui/view.h index 8c24b2fadb..3d89ea4d65 100644 --- a/ext/native/ui/view.h +++ b/ext/native/ui/view.h @@ -835,6 +835,7 @@ private: enum ImageSizeMode { IS_DEFAULT, IS_FIXED, + IS_KEEP_ASPECT, }; class ImageView : public InertView {