Skip to content

Commit

Permalink
Merge pull request #14079 from unknownbrackets/ppge-aspect
Browse files Browse the repository at this point in the history
Savedata: Show save icons with proper aspect ratio
  • Loading branch information
hrydgard authored Feb 15, 2021
2 parents a2093da + f798d9f commit 1c3c384
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 20 deletions.
40 changes: 27 additions & 13 deletions Core/Dialog/PSPSaveDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ void PSPSaveDialog::DisplaySaveList(bool canMove) {
imageStyle.color = CalcFadedColor(0xFF777777);

// Calc save image position on screen
float w, h , x, b;
float w, h, x;
float y = 97;
if (displayCount != currentSelectedSave) {
w = 81;
Expand All @@ -362,11 +362,6 @@ void PSPSaveDialog::DisplaySaveList(bool canMove) {
w = 144;
h = 80;
x = 27;
b = 1.2f;
PPGeDrawRect(x-b, y-b, x+w+b, y, CalcFadedColor(0xD0FFFFFF)); // top border
PPGeDrawRect(x-b, y, x, y+h, CalcFadedColor(0xD0FFFFFF)); // left border
PPGeDrawRect(x-b, y+h, x+w+b, y+h+b, CalcFadedColor(0xD0FFFFFF)); //bottom border
PPGeDrawRect(x+w, y, x+w+b, y+h, CalcFadedColor(0xD0FFFFFF)); //right border
}
if (displayCount < currentSelectedSave)
y -= 13 + 45 * (currentSelectedSave - displayCount);
Expand All @@ -377,13 +372,27 @@ void PSPSaveDialog::DisplaySaveList(bool canMove) {
if (y > 472.0f || y < -200.0f)
continue;

int tw = 256;
int th = 256;
if (fileInfo.texture != NULL) {
int pad = 0;
if (fileInfo.texture != nullptr) {
fileInfo.texture->SetTexture();
tw = fileInfo.texture->Width();
th = fileInfo.texture->Height();
PPGeDrawImage(x, y, w, h, 0, 0, 1, 1, tw, th, imageStyle);
int tw = fileInfo.texture->Width();
int th = fileInfo.texture->Height();
float scale = (float)h / (float)th;
int scaledW = (int)(tw * scale);
pad = (w - scaledW) / 2;
w = scaledW;

PPGeDrawImage(x + pad, y, w, h, 0, 0, 1, 1, tw, th, imageStyle);
} else {
PPGeDrawRect(x, y, x + w, y + h, 0x88666666);
}
if (displayCount == currentSelectedSave) {
float b = 1.2f;
uint32_t bc = CalcFadedColor(0xD0FFFFFF);
PPGeDrawRect(x + pad - b, y - b, x + pad + w + b, y, bc); // top border
PPGeDrawRect(x + pad - b, y, x + pad, y + h, bc); // left border
PPGeDrawRect(x + pad - b, y + h, x + pad + w + b, y + h + b, bc); //bottom border
PPGeDrawRect(x + pad + w, y, x + pad + w + b, y + h, bc); //right border
}
PPGeSetDefaultTexture();
}
Expand Down Expand Up @@ -418,6 +427,10 @@ void PSPSaveDialog::DisplaySaveIcon(bool checkExists)
curSave.texture->SetTexture();
tw = curSave.texture->Width();
th = curSave.texture->Height();
float scale = (float)h / (float)th;
int scaledW = (int)(tw * scale);
x += (w - scaledW) / 2;
w = scaledW;
} else {
PPGeDisableTexture();
}
Expand Down Expand Up @@ -467,11 +480,13 @@ static void FormatSaveDate(char *date, size_t sz, const tm &t) {
void PSPSaveDialog::DisplaySaveDataInfo1() {
std::lock_guard<std::mutex> guard(paramLock);
const SaveFileInfo &saveInfo = param.GetFileInfo(currentSelectedSave);
PPGeStyle saveTitleStyle = FadedStyle(PPGeAlign::BOX_LEFT, 0.55f);

if (saveInfo.broken) {
auto di = GetI18NCategory("Dialog");
PPGeStyle textStyle = FadedStyle(PPGeAlign::BOX_VCENTER, 0.6f);
PPGeDrawText(di->T("Corrupted Data"), 180, 136, textStyle);
PPGeDrawText(saveInfo.title, 175, 159, saveTitleStyle);
} else if (saveInfo.size == 0) {
auto di = GetI18NCategory("Dialog");
PPGeStyle textStyle = FadedStyle(PPGeAlign::BOX_VCENTER, 0.6f);
Expand All @@ -492,7 +507,6 @@ void PSPSaveDialog::DisplaySaveDataInfo1() {
std::string saveDetailTxt = saveInfo.saveDetail;

PPGeStyle titleStyle = FadedStyle(PPGeAlign::BOX_BOTTOM, 0.6f);
PPGeStyle saveTitleStyle = FadedStyle(PPGeAlign::BOX_LEFT, 0.55f);
titleStyle.color = CalcFadedColor(0xFFC0C0C0);
PPGeStyle textStyle = FadedStyle(PPGeAlign::BOX_LEFT, 0.5f);

Expand Down
1 change: 1 addition & 0 deletions Core/Dialog/SavedataParam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1578,6 +1578,7 @@ void SavedataParam::SetFileInfo(SaveFileInfo &saveInfo, PSPFileInfo &info, std::
}
} else {
saveInfo.broken = true;
truncate_cpy(saveInfo.title, saveDir.c_str());
}
}

Expand Down
18 changes: 12 additions & 6 deletions Core/Util/PPGeDraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,16 @@ static void EndVertexDataAndDraw(int prim) {

static u32 __PPGeDoAlloc(u32 &size, bool fromTop, const char *name) {
u32 ptr = kernelMemory.Alloc(size, fromTop, name);
// Didn't get it.
if (ptr == (u32)-1)
return 0;
// Didn't get it, try again after decimating images.
if (ptr == (u32)-1) {
PPGeDecimateTextImages(4);
PPGeImage::Decimate(4);

ptr = kernelMemory.Alloc(size, fromTop, name);
if (ptr == (u32)-1) {
return 0;
}
}
return ptr;
}

Expand Down Expand Up @@ -1291,9 +1298,8 @@ void PPGeImage::CompatLoad(u32 texture, int width, int height) {
height_ = height;
}

void PPGeImage::Decimate() {
static const int TOO_OLD_AGE = 30;
int tooOldFrame = gpuStats.numFlips - TOO_OLD_AGE;
void PPGeImage::Decimate(int age) {
int tooOldFrame = gpuStats.numFlips - age;
for (size_t i = 0; i < loadedTextures_.size(); ++i) {
if (loadedTextures_[i]->lastFrame_ < tooOldFrame) {
loadedTextures_[i]->Free();
Expand Down
2 changes: 1 addition & 1 deletion Core/Util/PPGeDraw.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class PPGeImage {
return height_;
}

static void Decimate();
static void Decimate(int age = 30);

private:
static std::vector<PPGeImage *> loadedTextures_;
Expand Down

0 comments on commit 1c3c384

Please sign in to comment.