Permalink
Browse files

Merge pull request #11413 from unknownbrackets/ui-minor

UI: Keep report image at right aspect ratio
  • Loading branch information...
hrydgard committed Sep 22, 2018
2 parents 9fddfff + d1c9da6 commit 26da224763462130f02183f765d0d0adec75684d
Showing with 35 additions and 5 deletions.
  1. +31 −2 UI/PauseScreen.cpp
  2. +1 −1 UI/PauseScreen.h
  3. +1 −1 UI/ReportScreen.cpp
  4. +1 −1 UI/SavedataScreen.cpp
  5. +1 −0 ext/native/ui/view.h
View
@@ -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 @@ class ScreenshotViewScreen : public PopupScreen {
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
@@ -67,7 +67,7 @@ class AsyncImageFileView : public UI::Clickable {
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
@@ -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
@@ -101,7 +101,7 @@ class SavedataPopupScreen : public PopupScreen {
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
@@ -835,6 +835,7 @@ class TextEdit : public View {
enum ImageSizeMode {
IS_DEFAULT,
IS_FIXED,
IS_KEEP_ASPECT,
};
class ImageView : public InertView {

0 comments on commit 26da224

Please sign in to comment.