Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Savedata: Show save icons with proper aspect ratio #14079

Merged
merged 4 commits into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 27 additions & 13 deletions Core/Dialog/PSPSaveDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,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 @@ -358,11 +358,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 @@ -373,13 +368,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 @@ -414,6 +423,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 @@ -463,11 +476,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 @@ -488,7 +503,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 @@ -1576,6 +1576,7 @@ void SavedataParam::SetFileInfo(SaveFileInfo &saveInfo, PSPFileInfo &info, std::
}
} else {
saveInfo.broken = true;
truncate_cpy(saveInfo.title, saveDir.c_str());
}
}

Expand Down
45 changes: 28 additions & 17 deletions Core/Util/PPGeDraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ struct PPGeTextDrawerImage {
TextStringEntry entry;
u32 ptr;
};
std::map<PPGeTextDrawerCacheKey, PPGeTextDrawerImage> textDrawerImages;
static std::map<PPGeTextDrawerCacheKey, PPGeTextDrawerImage> textDrawerImages;

void PPGeSetDrawContext(Draw::DrawContext *draw) {
g_draw = draw;
Expand All @@ -141,6 +141,8 @@ void PPGePrepareText(const char *text, float x, float y, PPGeAlign align, float
// Clears the buffer and state when done.
void PPGeDrawCurrentText(u32 color = 0xFFFFFFFF);

static void PPGeDecimateTextImages(int age = 97);

void PPGeSetTexture(u32 dataAddr, int width, int height);

//only 0xFFFFFF of data is used
Expand Down Expand Up @@ -197,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 @@ -906,6 +915,18 @@ static void PPGeDrawTextImage(PPGeTextDrawerImage im, float x, float y, const PP
PPGeSetDefaultTexture();
}

static void PPGeDecimateTextImages(int age) {
// Do this always, in case the platform has no TextDrawer but save state did.
for (auto it = textDrawerImages.begin(); it != textDrawerImages.end(); ) {
if (gpuStats.numFlips - it->second.entry.lastUsedFrame >= age) {
kernelMemory.Free(it->second.ptr);
it = textDrawerImages.erase(it);
} else {
++it;
}
}
}

void PPGeDrawText(const char *text, float x, float y, const PPGeStyle &style) {
if (!text || !strlen(text)) {
return;
Expand Down Expand Up @@ -1269,9 +1290,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 Expand Up @@ -1300,15 +1320,6 @@ void PPGeNotifyFrame() {
textDrawer->OncePerFrame();
}

// Do this always, in case the platform has no TextDrawer but save state did.
for (auto it = textDrawerImages.begin(); it != textDrawerImages.end(); ) {
if (it->second.entry.lastUsedFrame - gpuStats.numFlips >= 97) {
kernelMemory.Free(it->second.ptr);
it = textDrawerImages.erase(it);
} else {
++it;
}
}

PPGeDecimateTextImages();
PPGeImage::Decimate();
}
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