Merge pull request #11413 from unknownbrackets/ui-minor

UI: Keep report image at right aspect ratio
This commit is contained in:
Henrik Rydgård 2018-09-22 09:53:44 +02:00 committed by GitHub
commit 26da224763
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 5 deletions

View File

@ -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 <algorithm>
#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;
@ -146,7 +175,7 @@ protected:
UI::LinearLayout *content = new UI::LinearLayout(UI::ORIENT_VERTICAL);
parent->Add(content);
UI::Margins contentMargins(10, 0);
content->Add(new AsyncImageFileView(filename_, UI::IS_DEFAULT, nullptr, new UI::LinearLayoutParams(480, 272, contentMargins)))->SetCanBeFocused(false);
content->Add(new AsyncImageFileView(filename_, UI::IS_KEEP_ASPECT, nullptr, new UI::LinearLayoutParams(480, 272, contentMargins)))->SetCanBeFocused(false);
}
private:

View File

@ -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;

View File

@ -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;

View File

@ -101,7 +101,7 @@ public:
std::string image_path = ReplaceAll(savePath_, ".ppst", ".jpg");
if (File::Exists(image_path)) {
PrioritizedWorkQueue *wq = g_gameInfoCache->WorkQueue();
toprow->Add(new AsyncImageFileView(image_path, IS_DEFAULT, wq, new LinearLayoutParams(480, 272, Margins(10, 0))));
toprow->Add(new AsyncImageFileView(image_path, IS_KEEP_ASPECT, wq, new LinearLayoutParams(480, 272, Margins(10, 0))));
} else {
toprow->Add(new TextView(sa->T("No screenshot"), new LinearLayoutParams(Margins(10, 5))))->SetTextColor(textStyle.fgColor);
}

View File

@ -835,6 +835,7 @@ private:
enum ImageSizeMode {
IS_DEFAULT,
IS_FIXED,
IS_KEEP_ASPECT,
};
class ImageView : public InertView {