From ddc85988ab50ddc9f3be54555a11f75c64077e7e Mon Sep 17 00:00:00 2001 From: aquanull Date: Mon, 10 Jun 2013 13:48:35 +0800 Subject: [PATCH] Improve PSP system dialogs' looks. Format date according to configurations. Swap positions of button tips. Fix text wrapping with non-top-left text alignment. --- Core/Dialog/PSPDialog.cpp | 7 +- Core/Dialog/PSPMsgDialog.cpp | 74 ++++++--- Core/Dialog/PSPOskDialog.cpp | 1 + Core/Dialog/PSPSaveDialog.cpp | 227 ++++++++++++++++++++------- Core/Dialog/PSPSaveDialog.h | 9 ++ Core/Dialog/SavedataParam.cpp | 2 +- Core/Dialog/SavedataParam.h | 6 +- Core/Util/PPGeDraw.cpp | 285 +++++++++++++++++++--------------- Core/Util/PPGeDraw.h | 14 ++ lang | 2 +- 10 files changed, 417 insertions(+), 210 deletions(-) diff --git a/Core/Dialog/PSPDialog.cpp b/Core/Dialog/PSPDialog.cpp index 3385f0f200..96761bdb96 100644 --- a/Core/Dialog/PSPDialog.cpp +++ b/Core/Dialog/PSPDialog.cpp @@ -20,6 +20,7 @@ #include "ChunkFile.h" #define FADE_TIME 0.5 +const float FONT_SCALE = 0.53125f; PSPDialog::PSPDialog() : status(SCE_UTILITY_STATUS_SHUTDOWN) , lastButtons(0) @@ -44,8 +45,8 @@ PSPDialog::DialogStatus PSPDialog::GetStatus() void PSPDialog::StartDraw() { PPGeBegin(); - PPGeDrawRect(0, 0, 480, 272, CalcFadedColor(0x70606060)); } + void PSPDialog::EndDraw() { PPGeEnd(); @@ -55,7 +56,7 @@ void PSPDialog::DisplayMessage(std::string text) { PPGeDrawRect(30, 30, 450, 31, CalcFadedColor(0xFFFFFFFF)); PPGeDrawRect(30, 200, 450, 201, CalcFadedColor(0xFFFFFFFF)); - PPGeDrawTextWrapped(text.c_str(), 40, 50, 420, PPGE_ALIGN_LEFT, 0.55f, CalcFadedColor(0xFFFFFFFF)); + PPGeDrawTextWrapped(text.c_str(), 240, 50, 420, PPGE_ALIGN_HCENTER, FONT_SCALE, CalcFadedColor(0xFFFFFFFF)); } int PSPDialog::Shutdown(bool force) @@ -75,7 +76,7 @@ void PSPDialog::UpdateFade() { if(isFading) { - fadeTimer += 1.0f/30; // Probably need a more real value of delta time + fadeTimer += 1.0f/30.0f; // Probably need a more real value of delta time if(fadeTimer < FADE_TIME) { if(fadeIn) diff --git a/Core/Dialog/PSPMsgDialog.cpp b/Core/Dialog/PSPMsgDialog.cpp index d763a3ee9a..ccc0ec6775 100755 --- a/Core/Dialog/PSPMsgDialog.cpp +++ b/Core/Dialog/PSPMsgDialog.cpp @@ -23,6 +23,8 @@ #include "ChunkFile.h" #include "i18n/i18n.h" +const float FONT_SCALE = 0.53125f; + PSPMsgDialog::PSPMsgDialog() : PSPDialog() , flag(0) @@ -128,19 +130,53 @@ int PSPMsgDialog::Init(unsigned int paramAddr) return 0; } +void PSPMsgDialog::DisplayOk() +{ + I18NCategory *d = GetI18NCategory("Dialog"); + float x = 262.0f; + if (messageDialog.common.buttonSwap == 1) { + x = 172.0f; + } + PPGeDrawImage(okButtonImg, x, 220, 12, 12, 0, CalcFadedColor(0xFFFFFFFF)); + PPGeDrawText(d->T("Enter"), x + 20.0f, 216, PPGE_ALIGN_LEFT, FONT_SCALE, CalcFadedColor(0xFFFFFFFF)); +} + void PSPMsgDialog::DisplayBack() { I18NCategory *d = GetI18NCategory("Dialog"); - PPGeDrawImage(cancelButtonImg, 290, 220, 12, 12, 0, CalcFadedColor(0xFFFFFFFF)); - PPGeDrawText(d->T("Back"), 310, 218, PPGE_ALIGN_LEFT, 0.5f, CalcFadedColor(0xFFFFFFFF)); + float x = 172.0f; + if (messageDialog.common.buttonSwap == 1) { + x = 262.0f; + } + PPGeDrawImage(cancelButtonImg, x, 220, 12, 12, 0, CalcFadedColor(0xFFFFFFFF)); + PPGeDrawText(d->T("Back"), x + 20.0f, 216, PPGE_ALIGN_LEFT, FONT_SCALE, CalcFadedColor(0xFFFFFFFF)); } void PSPMsgDialog::DisplayYesNo() { I18NCategory *d = GetI18NCategory("Dialog"); - PPGeDrawText(d->T("Yes"), 200, 150, PPGE_ALIGN_LEFT, 0.55f, CalcFadedColor(yesnoChoice == 1?0xFF0000FF:0xFFFFFFFF)); - PPGeDrawText(d->T("No"), 320, 150, PPGE_ALIGN_LEFT, 0.55f, CalcFadedColor(yesnoChoice == 0?0xFF0000FF:0xFFFFFFFF)); - + const char *choiceText; + float x; + u32 yesColor, noColor; + if (yesnoChoice == 1) { + choiceText = d->T("Yes"); + x = 200.0f; + yesColor = 0xFF0FFFFF; + noColor = 0xFFFFFFFF; + } + else { + choiceText = d->T("No"); + x = 280.0f; + yesColor = 0xFFFFFFFF; + noColor = 0xFF0FFFFF; + } + float w, h; + PPGeMeasureText(choiceText, FONT_SCALE, &w, &h); + w = w / 2.0f + 5.0f; + h = h / 2.0f; + PPGeDrawRect(x - w, 160.0f - h, x + w, 160.0f + h, CalcFadedColor(0x6DCFCFCF)); + PPGeDrawText(d->T("Yes"), 200, 160, PPGE_ALIGN_CENTER, FONT_SCALE, CalcFadedColor(yesColor)); + PPGeDrawText(d->T("No"), 280, 160, PPGE_ALIGN_CENTER, FONT_SCALE, CalcFadedColor(noColor)); if (IsButtonPressed(CTRL_LEFT) && yesnoChoice == 0) { yesnoChoice = 1; @@ -151,22 +187,14 @@ void PSPMsgDialog::DisplayYesNo() } } -void PSPMsgDialog::DisplayOk() -{ - I18NCategory *d = GetI18NCategory("Dialog"); - PPGeDrawImage(okButtonImg, 200, 220, 12, 12, 0, CalcFadedColor(0xFFFFFFFF)); - PPGeDrawText(d->T("Enter"), 220, 218, PPGE_ALIGN_LEFT, 0.5f, CalcFadedColor(0xFFFFFFFF)); -} - int PSPMsgDialog::Update() { - if (status != SCE_UTILITY_STATUS_RUNNING) { return 0; } - if((flag & DS_ERROR)) + if ((flag & DS_ERROR)) { status = SCE_UTILITY_STATUS_FINISHED; } @@ -180,7 +208,7 @@ int PSPMsgDialog::Update() cancelButtonImg = I_CROSS; okButtonFlag = CTRL_CIRCLE; cancelButtonFlag = CTRL_CROSS; - if(messageDialog.common.buttonSwap == 1) + if (messageDialog.common.buttonSwap == 1) { okButtonImg = I_CROSS; cancelButtonImg = I_CIRCLE; @@ -189,16 +217,22 @@ int PSPMsgDialog::Update() } StartDraw(); + // white -> RGB(168,173,189), black -> RGB(129,134,150) + // (255 - a) + (x * a / 255) = 173, x * a / 255 = 134 + // a = 255 - w + b = 158, x = b * 255 / a = ? + // but is not drawn using x * a + y * (255 - a) here? + //PPGeDrawRect(0, 0, 480, 272, CalcFadedColor(0x9EF2D8D0)); + PPGeDrawRect(0, 0, 480, 272, CalcFadedColor(0xC0C8B2AC)); - if((flag & DS_MSG) || (flag & DS_ERRORMSG)) + if ((flag & DS_MSG) || (flag & DS_ERRORMSG)) DisplayMessage(msgText); - if(flag & DS_YESNO) + if (flag & DS_YESNO) DisplayYesNo(); if (flag & (DS_OK | DS_VALIDBUTTON)) DisplayOk(); - if(flag & DS_CANCELBUTTON) + if (flag & DS_CANCELBUTTON) DisplayBack(); if (IsButtonPressed(cancelButtonFlag) && (flag & DS_CANCELBUTTON)) @@ -210,9 +244,9 @@ int PSPMsgDialog::Update() messageDialog.buttonPressed = 0; StartFade(false); } - else if(IsButtonPressed(okButtonFlag) && (flag & DS_VALIDBUTTON)) + else if (IsButtonPressed(okButtonFlag) && (flag & DS_VALIDBUTTON)) { - if(yesnoChoice == 0) + if (yesnoChoice == 0) { messageDialog.buttonPressed = 2; } diff --git a/Core/Dialog/PSPOskDialog.cpp b/Core/Dialog/PSPOskDialog.cpp index c2cce814e8..d639a73d4f 100755 --- a/Core/Dialog/PSPOskDialog.cpp +++ b/Core/Dialog/PSPOskDialog.cpp @@ -747,6 +747,7 @@ int PSPOskDialog::Update() UpdateFade(); StartDraw(); + PPGeDrawRect(0, 0, 480, 272, CalcFadedColor(0x63636363)); RenderKeyboard(); PPGeDrawImage(I_CROSS, 30, 220, 20, 20, 0, CalcFadedColor(0xFFFFFFFF)); PPGeDrawImage(I_CIRCLE, 150, 220, 20, 20, 0, CalcFadedColor(0xFFFFFFFF)); diff --git a/Core/Dialog/PSPSaveDialog.cpp b/Core/Dialog/PSPSaveDialog.cpp index a054ca83e5..e0723d9d7a 100755 --- a/Core/Dialog/PSPSaveDialog.cpp +++ b/Core/Dialog/PSPSaveDialog.cpp @@ -18,12 +18,15 @@ #include "PSPSaveDialog.h" #include "../Util/PPGeDraw.h" #include "../HLE/sceCtrl.h" +#include "../HLE/sceUtility.h" #include "../Core/MemMap.h" #include "../Config.h" #include "Core/Reporting.h" #include "Core/HW/MemoryStick.h" #include "i18n/i18n.h" +const float FONT_SCALE = 0.53125f; + PSPSaveDialog::PSPSaveDialog() : PSPDialog() , display(DS_NONE) @@ -242,6 +245,36 @@ const std::string PSPSaveDialog::GetSelectedSaveDirName() } } +void PSPSaveDialog::DisplayBanner(int which) +{ + I18NCategory *d = GetI18NCategory("Dialog"); + PPGeDrawRect(0, 0, 480, 23, CalcFadedColor(0x65636358)); + //PPGeDrawImage(I_HEXAGON, 0, 11, PPGE_ALIGN_CENTER, CalcFadedColor(0xFFFFFFFF)); + const char *icon = "\xE3\x80\x84"; // jp industrial + const char *title = ""; + switch (which) + { + case DB_SAVE: + icon = "\xE2\x99\xA8"; // hot spring + title = d->T("Save"); + break; + case DB_LOAD: + icon = "\xE2\x98\x82"; // umbrella + //icon = "\xE2\x99\xA8"; // 8th note + //icon = "\xE2\x99\xAC"; // two 16th notes + title = d->T("Load"); + break; + case DB_DELETE: + icon = "\xE2\x98\x83"; // snowman + title = d->T("Delete"); + break; + default: + break; + } + PPGeDrawText(icon, 15, 11, PPGE_ALIGN_CENTER, 0.6f, CalcFadedColor(0xFFFFFFFF)); + PPGeDrawText(title, 30, 11, PPGE_ALIGN_VCENTER, 0.6f, CalcFadedColor(0xFFFFFFFF)); +} + void PSPSaveDialog::DisplaySaveList(bool canMove) { int displayCount = 0; @@ -261,7 +294,7 @@ void PSPSaveDialog::DisplaySaveList(bool canMove) h = 40; x = 55; } - float y = 96; + float y = 97; if(displayCount < currentSelectedSave) y -= 10 + 40 * (currentSelectedSave - displayCount ); else if(displayCount > currentSelectedSave) @@ -299,7 +332,7 @@ void PSPSaveDialog::DisplaySaveIcon() float w = 150; float h = 80; float x = 20; - float y = 80; + float y = 97; int tw = 256; int th = 256; @@ -316,9 +349,9 @@ void PSPSaveDialog::DisplaySaveIcon() void PSPSaveDialog::DisplaySaveDataInfo1() { - if(param.GetFileInfo(currentSelectedSave).size == 0) { + if (param.GetFileInfo(currentSelectedSave).size == 0) { I18NCategory *d = GetI18NCategory("Dialog"); - PPGeDrawText(d->T("New Save"), 180, 100, PPGE_ALIGN_LEFT, 0.5f, CalcFadedColor(0xFFFFFFFF)); + PPGeDrawText(d->T("New Save"), 180, 100, PPGE_ALIGN_LEFT, FONT_SCALE, CalcFadedColor(0xFFFFFFFF)); } else { char title[512]; char time[512]; @@ -327,10 +360,10 @@ void PSPSaveDialog::DisplaySaveDataInfo1() char am_pm[] = "AM"; char hour_time[10] ; - int hour = param.GetFileInfo(currentSelectedSave).modif_time.tm_hour ; - int min = param.GetFileInfo(currentSelectedSave).modif_time.tm_min ; - if (g_Config.itimeformat) { - if( hour > 12 ) { + int hour = param.GetFileInfo(currentSelectedSave).modif_time.tm_hour; + int min = param.GetFileInfo(currentSelectedSave).modif_time.tm_min; + if (g_Config.itimeformat == PSP_SYSTEMPARAM_TIME_FORMAT_12HR) { + if (hour > 12) { strcpy(am_pm, "PM"); hour -= 12; } @@ -338,19 +371,27 @@ void PSPSaveDialog::DisplaySaveDataInfo1() } else snprintf(hour_time,10,"%02d:%02d", hour, min); - snprintf(title,512,"%s", param.GetFileInfo(currentSelectedSave).title); - snprintf(time,512,"%02d/%02d/%d %s %lld KB" - , param.GetFileInfo(currentSelectedSave).modif_time.tm_mday - , param.GetFileInfo(currentSelectedSave).modif_time.tm_mon + 1 - , param.GetFileInfo(currentSelectedSave).modif_time.tm_year + 1900 - , hour_time - , param.GetFileInfo(currentSelectedSave).size / 1024 - ); - snprintf(saveTitle,512,"%s", param.GetFileInfo(currentSelectedSave).saveTitle); - snprintf(saveDetail,512,"%s", param.GetFileInfo(currentSelectedSave).saveDetail); - + snprintf(title, 512, "%s", param.GetFileInfo(currentSelectedSave).title); + int day = param.GetFileInfo(currentSelectedSave).modif_time.tm_mday; + int month = param.GetFileInfo(currentSelectedSave).modif_time.tm_mon + 1; + int year = param.GetFileInfo(currentSelectedSave).modif_time.tm_year + 1900; + s64 sizeK = param.GetFileInfo(currentSelectedSave).size / 1024; + switch (g_Config.iDateFormat) { + case PSP_SYSTEMPARAM_DATE_FORMAT_DDMMYYYY: + snprintf(time, 512, "%02d/%02d/%d %s %lld KB", day, month, year, hour_time, sizeK); + break; + case PSP_SYSTEMPARAM_DATE_FORMAT_MMDDYYYY: + snprintf(time, 512, "%02d/%02d/%d %s %lld KB", month, day, year, hour_time, sizeK); + break; + case PSP_SYSTEMPARAM_DATE_FORMAT_YYYYMMDD: + // fall through + default: + snprintf(time, 512, "%d/%02d/%02d %s %lld KB", year, month, day, hour_time, sizeK); + } + snprintf(saveTitle, 512, "%s", param.GetFileInfo(currentSelectedSave).saveTitle); + snprintf(saveDetail, 512, "%s", param.GetFileInfo(currentSelectedSave).saveDetail); - PPGeDrawRect(180, 139, 980, 140, CalcFadedColor(0xFFFFFFFF)); + PPGeDrawRect(180, 140, 980, 141, CalcFadedColor(0xFFFFFFFF)); std::string titleTxt = title; std::string timeTxt = time; std::string saveTitleTxt = saveTitle; @@ -365,15 +406,16 @@ void PSPSaveDialog::DisplaySaveDataInfo1() void PSPSaveDialog::DisplaySaveDataInfo2() { - if(param.GetFileInfo(currentSelectedSave).size == 0) { + if (param.GetFileInfo(currentSelectedSave).size == 0) { } else { char txt[1024]; + char date[256]; char am_pm[] = "AM"; char hour_time[10] ; - int hour = param.GetFileInfo(currentSelectedSave).modif_time.tm_hour ; - int min = param.GetFileInfo(currentSelectedSave).modif_time.tm_min ; - if (g_Config.itimeformat) { - if( hour > 12 ) { + int hour = param.GetFileInfo(currentSelectedSave).modif_time.tm_hour; + int min = param.GetFileInfo(currentSelectedSave).modif_time.tm_min; + if (g_Config.itimeformat == PSP_SYSTEMPARAM_TIME_FORMAT_12HR) { + if (hour > 12) { strcpy(am_pm, "PM"); hour -= 12; } @@ -381,27 +423,60 @@ void PSPSaveDialog::DisplaySaveDataInfo2() } else snprintf(hour_time,10,"%02d:%02d", hour, min); - snprintf(txt,1024,"%s\n%02d/%02d/%d %s\n%lld KB" - , param.GetFileInfo(currentSelectedSave).saveTitle - , param.GetFileInfo(currentSelectedSave).modif_time.tm_mday - , param.GetFileInfo(currentSelectedSave).modif_time.tm_mon + 1 - , param.GetFileInfo(currentSelectedSave).modif_time.tm_year + 1900 - , hour_time - , param.GetFileInfo(currentSelectedSave).size / 1024 - ); + const char *saveTitle = param.GetFileInfo(currentSelectedSave).saveTitle; + int day = param.GetFileInfo(currentSelectedSave).modif_time.tm_mday; + int month = param.GetFileInfo(currentSelectedSave).modif_time.tm_mon + 1; + int year = param.GetFileInfo(currentSelectedSave).modif_time.tm_year + 1900; + s64 sizeK = param.GetFileInfo(currentSelectedSave).size / 1024; + switch (g_Config.iDateFormat) { + case PSP_SYSTEMPARAM_DATE_FORMAT_DDMMYYYY: + snprintf(date, 256, "%02d/%02d/%d", day, month, year); + break; + case PSP_SYSTEMPARAM_DATE_FORMAT_MMDDYYYY: + snprintf(date, 256, "%02d/%02d/%d", month, day, year); + break; + case PSP_SYSTEMPARAM_DATE_FORMAT_YYYYMMDD: + // fall through + default: + snprintf(date, 256, "%d/%02d/%02d", year, month, day); + } + snprintf(txt, 1024, "%s\n%s %s\n%lld KB", saveTitle, date, hour_time, sizeK); std::string saveinfoTxt = txt; - PPGeDrawText(saveinfoTxt.c_str(), 10, 180, PPGE_ALIGN_LEFT, 0.45f, CalcFadedColor(0xFFFFFFFF)); + PPGeDrawText(saveinfoTxt.c_str(), 8, 200, PPGE_ALIGN_LEFT, 0.45f, CalcFadedColor(0xFFFFFFFF)); } } void PSPSaveDialog::DisplayConfirmationYesNo(std::string text) { I18NCategory *d = GetI18NCategory("Dialog"); - PPGeDrawRect(200, 85, 460, 86, CalcFadedColor(0xFFFFFFFF)); - PPGeDrawRect(200, 160, 460, 161, CalcFadedColor(0xFFFFFFFF)); - PPGeDrawText(text.c_str(), 320, 100, PPGE_ALIGN_HCENTER, 0.5f, 0xFFFFFFFF); - PPGeDrawText(d->T("Yes"), 275, 130, PPGE_ALIGN_LEFT, 0.5f, CalcFadedColor(yesnoChoice == 1?0xFF0000FF:0xFFFFFFFF)); - PPGeDrawText(d->T("No"), 340, 130, PPGE_ALIGN_LEFT, 0.5f, CalcFadedColor(yesnoChoice == 0?0xFF0000FF:0xFFFFFFFF)); + PPGeDrawRect(202, 88, 466, 89, CalcFadedColor(0xFFFFFFFF)); + PPGeDrawRect(202, 186, 466, 187, CalcFadedColor(0xFFFFFFFF)); + + PPGeDrawTextWrapped(text.c_str(), 332, 124, 250, PPGE_ALIGN_CENTER, FONT_SCALE, 0xFFFFFFFF); + + const char *choiceText; + float x; + u32 yesColor, noColor; + if (yesnoChoice == 1) { + choiceText = d->T("Yes"); + x = 300.0f; + yesColor = 0xFF0FFFFF; + noColor = 0xFFFFFFFF; + } + else { + choiceText = d->T("No"); + x = 364.0f; + yesColor = 0xFFFFFFFF; + noColor = 0xFF0FFFFF; + } + float w, h; + PPGeMeasureText(choiceText, FONT_SCALE, &w, &h); + w = w / 2.0f + 6.0f; + h = h / 2.0f; + PPGeDrawRect(x - w, 164.0f - h, x + w, 164.0f + h, CalcFadedColor(0x6DCFCFCF)); + PPGeDrawText(d->T("Yes"), 300, 164, PPGE_ALIGN_CENTER, FONT_SCALE, CalcFadedColor(yesColor)); + PPGeDrawText(d->T("No"), 364, 164, PPGE_ALIGN_CENTER, FONT_SCALE, CalcFadedColor(noColor)); + if (IsButtonPressed(CTRL_LEFT) && yesnoChoice == 0) yesnoChoice = 1; else if (IsButtonPressed(CTRL_RIGHT) && yesnoChoice == 1) @@ -410,9 +485,9 @@ void PSPSaveDialog::DisplayConfirmationYesNo(std::string text) void PSPSaveDialog::DisplayInfo(std::string text) { - PPGeDrawRect(200, 100, 460, 101, CalcFadedColor(0xFFFFFFFF)); - PPGeDrawRect(200, 140, 460, 141, CalcFadedColor(0xFFFFFFFF)); - PPGeDrawText(text.c_str(), 320, 110, PPGE_ALIGN_HCENTER, 0.5f, CalcFadedColor(0xFFFFFFFF)); + PPGeDrawRect(202, 115, 466, 116, CalcFadedColor(0xFFFFFFFF)); + PPGeDrawRect(202, 158, 466, 159, CalcFadedColor(0xFFFFFFFF)); + PPGeDrawText(text.c_str(), 331, 138, PPGE_ALIGN_CENTER, FONT_SCALE, CalcFadedColor(0xFFFFFFFF)); } void PSPSaveDialog::DisplayTitle(std::string name) @@ -423,17 +498,26 @@ void PSPSaveDialog::DisplayTitle(std::string name) void PSPSaveDialog::DisplayEnterBack() { I18NCategory *d = GetI18NCategory("Dialog"); - PPGeDrawImage(cancelButtonImg, 180, 257, 11, 11, 0, CalcFadedColor(0xFFFFFFFF)); - PPGeDrawImage(okButtonImg, 270, 257, 11, 11, 0, CalcFadedColor(0xFFFFFFFF)); - PPGeDrawText(d->T("Back"), 195, 255, PPGE_ALIGN_LEFT, 0.45f, CalcFadedColor(0xFFFFFFFF)); - PPGeDrawText(d->T("Enter"), 285, 255, PPGE_ALIGN_LEFT, 0.45f, CalcFadedColor(0xFFFFFFFF)); + float x1 = 180.0f, x2 = 270.0f; + if (param.GetPspParam()->buttonSwap == 1) { + x1 = 270.0f; + x2 = 180.0f; + } + PPGeDrawImage(cancelButtonImg, x1, 257, 11, 11, 0, CalcFadedColor(0xFFFFFFFF)); + PPGeDrawImage(okButtonImg, x2, 257, 11, 11, 0, CalcFadedColor(0xFFFFFFFF)); + PPGeDrawText(d->T("Back"), x1 + 15.0f, 253, PPGE_ALIGN_LEFT, FONT_SCALE, CalcFadedColor(0xFFFFFFFF)); + PPGeDrawText(d->T("Enter"), x2 + 15.0f, 253, PPGE_ALIGN_LEFT, FONT_SCALE, CalcFadedColor(0xFFFFFFFF)); } void PSPSaveDialog::DisplayBack() { I18NCategory *d = GetI18NCategory("Dialog"); - PPGeDrawImage(cancelButtonImg, 180, 257, 11, 11, 0, CalcFadedColor(0xFFFFFFFF)); - PPGeDrawText(d->T("Back"), 195, 255, PPGE_ALIGN_LEFT, 0.45f, CalcFadedColor(0xFFFFFFFF)); + float x = 180.0f; + if (param.GetPspParam()->buttonSwap == 1) { + x = 270.0f; + } + PPGeDrawImage(cancelButtonImg, x, 257, 11, 11, 0, CalcFadedColor(0xFFFFFFFF)); + PPGeDrawText(d->T("Back"), x + 15.0f, 253, PPGE_ALIGN_LEFT, FONT_SCALE, CalcFadedColor(0xFFFFFFFF)); } int PSPSaveDialog::Update() @@ -474,12 +558,12 @@ int PSPSaveDialog::Update() { case DS_SAVE_LIST_CHOICE: StartDraw(); - - // TODO : use focus param for selected save by default + DisplaySaveList(); DisplaySaveDataInfo1(); DisplayEnterBack(); + DisplayBanner(DB_SAVE); if (IsButtonPressed(cancelButtonFlag)) { param.GetPspParam()->result = SCE_UTILITY_DIALOG_RESULT_CANCEL; @@ -509,6 +593,8 @@ int PSPSaveDialog::Update() DisplayConfirmationYesNo(d->T("Confirm Save", "Do you want to save this data?")); DisplayEnterBack(); + DisplayBanner(DB_SAVE); + if (IsButtonPressed(cancelButtonFlag) || (IsButtonPressed(okButtonFlag) && yesnoChoice == 0)) { param.GetPspParam()->result = SCE_UTILITY_DIALOG_RESULT_CANCEL; StartFade(false); @@ -534,6 +620,8 @@ int PSPSaveDialog::Update() DisplayConfirmationYesNo(d->T("Do you want to overwrite the data?")); DisplayEnterBack(); + DisplayBanner(DB_SAVE); + if (IsButtonPressed(cancelButtonFlag) || (IsButtonPressed(okButtonFlag) && yesnoChoice == 0)) { if (param.GetPspParam()->mode != SCE_UTILITY_SAVEDATA_TYPE_SAVE) display = DS_SAVE_LIST_CHOICE; @@ -565,6 +653,8 @@ int PSPSaveDialog::Update() DisplayInfo(d->T("Saving","Saving\nPlease Wait...")); + DisplayBanner(DB_SAVE); + EndDraw(); break; case DS_SAVE_DONE: @@ -572,10 +662,12 @@ int PSPSaveDialog::Update() DisplaySaveIcon(); DisplaySaveDataInfo2(); - DisplayBack(); DisplayInfo(d->T("Save completed")); + DisplayBack(); + DisplayBanner(DB_SAVE); + if (IsButtonPressed(cancelButtonFlag)) { param.GetPspParam()->result = SCE_UTILITY_DIALOG_RESULT_SUCCESS; // Set the save to use for autosave and autoload @@ -593,6 +685,8 @@ int PSPSaveDialog::Update() DisplaySaveDataInfo1(); DisplayEnterBack(); + DisplayBanner(DB_LOAD); + if (IsButtonPressed(cancelButtonFlag)) { param.GetPspParam()->result = SCE_UTILITY_DIALOG_RESULT_CANCEL; StartFade(false); @@ -613,6 +707,8 @@ int PSPSaveDialog::Update() DisplayConfirmationYesNo(d->T("ConfirmLoad", "Load this data?")); DisplayEnterBack(); + DisplayBanner(DB_LOAD); + if (IsButtonPressed(cancelButtonFlag) || (IsButtonPressed(okButtonFlag) && yesnoChoice == 0)) { param.GetPspParam()->result = SCE_UTILITY_DIALOG_RESULT_CANCEL; StartFade(false); @@ -636,6 +732,8 @@ int PSPSaveDialog::Update() DisplayInfo(d->T("Loading","Loading\nPlease Wait...")); + DisplayBanner(DB_LOAD); + EndDraw(); break; case DS_LOAD_DONE: @@ -643,10 +741,12 @@ int PSPSaveDialog::Update() DisplaySaveIcon(); DisplaySaveDataInfo2(); - DisplayBack(); DisplayInfo(d->T("Load completed")); + DisplayBack(); + DisplayBanner(DB_LOAD); + if (IsButtonPressed(cancelButtonFlag)) { param.GetPspParam()->result = SCE_UTILITY_DIALOG_RESULT_SUCCESS; // Set the save to use for autosave and autoload @@ -659,10 +759,11 @@ int PSPSaveDialog::Update() case DS_LOAD_NODATA: StartDraw(); - DisplayBack(); - DisplayInfo(d->T("There is no data")); + DisplayBack(); + DisplayBanner(DB_LOAD); + if (IsButtonPressed(cancelButtonFlag)) { param.GetPspParam()->result = SCE_UTILITY_SAVEDATA_ERROR_LOAD_NO_DATA; StartFade(false); @@ -678,6 +779,8 @@ int PSPSaveDialog::Update() DisplaySaveDataInfo1(); DisplayEnterBack(); + DisplayBanner(DB_DELETE); + if (IsButtonPressed(cancelButtonFlag)) { param.GetPspParam()->result = SCE_UTILITY_DIALOG_RESULT_CANCEL; StartFade(false); @@ -694,9 +797,11 @@ int PSPSaveDialog::Update() DisplaySaveIcon(); DisplaySaveDataInfo2(); - DisplayConfirmationYesNo(d->T("DeleteConfirm", " This save data will be deleted.\nAre you sure you want to continue?")); + DisplayConfirmationYesNo(d->T("DeleteConfirm", "This save data will be deleted.\nAre you sure you want to continue?")); DisplayEnterBack(); + DisplayBanner(DB_DELETE); + if (IsButtonPressed(cancelButtonFlag)) display = DS_DELETE_LIST_CHOICE; else if (IsButtonPressed(okButtonFlag)) { @@ -719,15 +824,18 @@ int PSPSaveDialog::Update() DisplayInfo(d->T("Deleting","Deleting\nPlease Wait...")); + DisplayBanner(DB_DELETE); + EndDraw(); break; case DS_DELETE_DONE: StartDraw(); - DisplayBack(); - DisplayInfo(d->T("Delete completed")); + DisplayBack(); + DisplayBanner(DB_DELETE); + if (IsButtonPressed(cancelButtonFlag)) { if (param.GetFilenameCount() == 0) display = DS_DELETE_NODATA; @@ -740,10 +848,11 @@ int PSPSaveDialog::Update() case DS_DELETE_NODATA: StartDraw(); - DisplayBack(); - DisplayInfo(d->T("There is no data")); + DisplayBack(); + DisplayBanner(DB_DELETE); + if (IsButtonPressed(cancelButtonFlag)) { param.GetPspParam()->result = SCE_UTILITY_SAVEDATA_ERROR_DELETE_NO_DATA; StartFade(false); diff --git a/Core/Dialog/PSPSaveDialog.h b/Core/Dialog/PSPSaveDialog.h index 2544385127..c18b752996 100644 --- a/Core/Dialog/PSPSaveDialog.h +++ b/Core/Dialog/PSPSaveDialog.h @@ -74,6 +74,7 @@ public: private : + void DisplayBanner(int which); void DisplaySaveList(bool canMove = true); void DisplaySaveIcon(); void DisplayTitle(std::string name); @@ -108,6 +109,14 @@ private : DS_DELETE_NODATA }; + enum DialogBanner + { + DB_NONE, + DB_SAVE, + DB_LOAD, + DB_DELETE + }; + DisplayState display; SavedataParam param; diff --git a/Core/Dialog/SavedataParam.cpp b/Core/Dialog/SavedataParam.cpp index 97a2e12dc1..02693a1e33 100644 --- a/Core/Dialog/SavedataParam.cpp +++ b/Core/Dialog/SavedataParam.cpp @@ -1305,7 +1305,7 @@ int SavedataParam::GetFirstDataSave() { if (saveDataList[i].size != 0) { - idx = i;; + idx = i; break; } } diff --git a/Core/Dialog/SavedataParam.h b/Core/Dialog/SavedataParam.h index 33d5e3978d..7d418dda9b 100644 --- a/Core/Dialog/SavedataParam.h +++ b/Core/Dialog/SavedataParam.h @@ -54,10 +54,10 @@ enum SceUtilitySavedataType enum SceUtilitySavedataFocus { SCE_UTILITY_SAVEDATA_FOCUS_NAME = 0, // specified by saveName[] - SCE_UTILITY_SAVEDATA_FOCUS_FIRSTLIST = 1, // first listed (on screen or of all)? - SCE_UTILITY_SAVEDATA_FOCUS_LASTLIST = 2, // last listed (on screen or of all)? + SCE_UTILITY_SAVEDATA_FOCUS_FIRSTLIST = 1, // first listed (on screen or of all?) + SCE_UTILITY_SAVEDATA_FOCUS_LASTLIST = 2, // last listed (on screen or of all?) SCE_UTILITY_SAVEDATA_FOCUS_LATEST = 3, // latest by modification date (first if none) - SCE_UTILITY_SAVEDATA_FOCUS_OLDEST = 4, // doldest by modification date (first if none) + SCE_UTILITY_SAVEDATA_FOCUS_OLDEST = 4, // oldest by modification date (first if none) SCE_UTILITY_SAVEDATA_FOCUS_FIRSTDATA = 5, // first non-empty (first if none) SCE_UTILITY_SAVEDATA_FOCUS_LASTDATA = 6, // last non-empty (first if none) SCE_UTILITY_SAVEDATA_FOCUS_FIRSTEMPTY = 7, // first empty (what if no empty?) diff --git a/Core/Util/PPGeDraw.cpp b/Core/Util/PPGeDraw.cpp index 69e5acf621..87b8f5425a 100644 --- a/Core/Util/PPGeDraw.cpp +++ b/Core/Util/PPGeDraw.cpp @@ -55,11 +55,23 @@ static u32 dataSize = 0x10000; // should be enough for a frame of gui... static u32 palettePtr; static u32 paletteSize = 2 * 16; - // Vertex collector static u32 vertexStart; static u32 vertexCount; +// Used for formating text +struct AtlasCharVertex +{ + float x; + float y; + const AtlasChar *c; +}; + +typedef std::vector AtlasCharLine; +typedef std::vector AtlasLineArray; + +static AtlasLineArray char_lines; + //only 0xFFFFFF of data is used static void WriteCmd(u8 cmd, u32 data) { Memory::Write_U32((cmd << 24) | (data & 0xFFFFFF), dlWritePtr); @@ -184,6 +196,8 @@ void __PPGeDoState(PointerWrap &p) p.Do(vertexStart); p.Do(vertexCount); + p.Do(char_lines); + p.DoMarker("PPGeDraw"); } @@ -298,80 +312,6 @@ static const AtlasChar *PPGeGetChar(const AtlasFont &atlasfont, unsigned int cva return c; } -static void PPGeMeasureText(const char *text, float scale, float *w, float *h) { - const AtlasFont &atlasfont = *ppge_atlas.fonts[0]; - unsigned int cval; - float wacc = 0; - float maxw = 0; - int lines = 1; - UTF8 utf(text); - while (true) { - if (utf.end()) - break; - cval = utf.next(); - if (cval == '\n') { - if (wacc > maxw) maxw = wacc; - wacc = 0; - lines++; - } - const AtlasChar *c = PPGeGetChar(atlasfont, cval); - if (c) { - wacc += c->wx * scale; - } - } - if (wacc > maxw) maxw = wacc; - if (w) *w = maxw; - if (h) *h = atlasfont.height * scale * lines; -} - -static void PPGeDoAlign(int flags, float *x, float *y, float *w, float *h) { - if (flags & PPGE_ALIGN_HCENTER) *x -= *w / 2; - if (flags & PPGE_ALIGN_RIGHT) *x -= *w; - if (flags & PPGE_ALIGN_VCENTER) *y -= *h / 2; - if (flags & PPGE_ALIGN_BOTTOM) *y -= *h; -} - -// Draws some text using the one font we have. -// Mostly stolen from DrawBuffer. -void PPGeDrawText(const char *text, float x, float y, int align, float scale, u32 color) { - if (!dlPtr) - return; - const AtlasFont &atlasfont = *ppge_atlas.fonts[0]; - unsigned int cval; - float w, h; - PPGeMeasureText(text, scale, &w, &h); - if (align) { - PPGeDoAlign(align, &x, &y, &w, &h); - } - BeginVertexData(); - y += atlasfont.ascend*scale; - float sx = x; - UTF8 utf(text); - while (true) { - if (utf.end()) - break; - cval = utf.next(); - if (cval == '\n') { - // This is not correct when centering or right-justifying, need to set x depending on line width (tricky) - y += atlasfont.height * scale; - x = sx; - continue; - } - const AtlasChar *ch = PPGeGetChar(atlasfont, cval); - if (ch) { - const AtlasChar &c = *ch; - float cx1 = x + c.ox * scale; - float cy1 = y + c.oy * scale; - float cx2 = x + (c.ox + c.pw) * scale; - float cy2 = y + (c.oy + c.ph) * scale; - Vertex(cx1, cy1, c.sx, c.sy, atlasWidth, atlasHeight, color); - Vertex(cx2, cy2, c.ex, c.ey, atlasWidth, atlasHeight, color); - x += c.wx * scale; - } - } - EndVertexDataAndDraw(GE_PRIM_RECTANGLES); -} - static float NextWordWidth(UTF8 utf, const AtlasFont &atlasfont, float scale) { float w = 0.0; bool finished = false; @@ -418,64 +358,163 @@ static float NextWordWidth(UTF8 utf, const AtlasFont &atlasfont, float scale) { return w; } +// Break a single text string into mutiple lines. +static void BreakLines(const char *text, const AtlasFont &atlasfont, float x, float y, int align, float scale, int wrapType, float wrapWidth) +{ + float sx = x; + y += atlasfont.ascend * scale; + + // used for replacing with ellipsis + float wrapCutoff = 8.0f; + const AtlasChar *dot = PPGeGetChar(atlasfont, '.'); + if (dot) { + wrapCutoff = dot->wx * scale * 3.0f; + } + //const float wrapGreyZone = 2.0f; // Grey zone for punctuations at line ends + + float maxw = 0; + for (UTF8 utf(text); !utf.end(); ) + { + AtlasCharLine line; + float lineWidth = 0; + while (!utf.end()) + { + uint32_t cval = utf.next(); + if (cval == '\n') { + break; + } + if (cval == '\r') { + // We simply ignore this. + continue; + } + const AtlasChar *c = PPGeGetChar(atlasfont, cval); + if (c) + { + if (wrapType > 0) + { + float nextWidth = NextWordWidth(utf, atlasfont, scale); + if (lineWidth + nextWidth > wrapWidth) { + if (wrapType & PPGE_LINE_WRAP_WORD) { + if (lineWidth > 0) { + // TODO: Should check if we have had at least one other word instead. + break; + } + } + if (wrapType & PPGE_LINE_USE_ELLIPSIS) { + if (nextWidth >= wrapCutoff) { + // TODO: Truncate the word with an ellipsis. + // The word is not too short. + } + } + } + } + AtlasCharVertex cv; + cv.x = x + c->ox * scale; + cv.y = y + c->oy * scale; + cv.c = c; + line.push_back(cv); + + float ww = c->wx * scale; + lineWidth += ww; + x += ww; + } + } + y += atlasfont.height * scale; + x = sx; + if (lineWidth > maxw) + maxw = lineWidth; + char_lines.push_back(line); + } + + if (align) + { + float w = maxw; + float h = atlasfont.height * scale * char_lines.size(); + for (auto i = char_lines.begin(); i != char_lines.end(); ++i) + { + for (auto j = i->begin(); j != i->end(); ++j) + { + if (align & PPGE_ALIGN_HCENTER) j->x -= w / 2.0f; + else if (align & PPGE_ALIGN_RIGHT) j->x -= w; + + if (align & PPGE_ALIGN_VCENTER) j->y -= h / 2.0f; + else if (align & PPGE_ALIGN_BOTTOM) j->y -= h; + } + } + } +} + +void PPGeMeasureText(const char *text, float scale, float *w, float *h) { + const AtlasFont &atlasfont = *ppge_atlas.fonts[0]; + unsigned int cval; + float wacc = 0; + float maxw = 0; + int lines = 1; + UTF8 utf(text); + while (!utf.end()) + { + cval = utf.next(); + if (cval == '\n') { + if (wacc > maxw) maxw = wacc; + wacc = 0; + lines++; + } + const AtlasChar *c = PPGeGetChar(atlasfont, cval); + if (c) { + wacc += c->wx * scale; + } + } + if (wacc > maxw) maxw = wacc; + if (w) *w = maxw; + if (h) *h = atlasfont.height * scale * lines; +} + +// Draws some text using the one font we have. +// Mostly rewritten. +void PPGeDrawText(const char *text, float x, float y, int align, float scale, u32 color) { + if (!dlPtr) + return; + const AtlasFont &atlasfont = *ppge_atlas.fonts[0]; + BreakLines(text, atlasfont, x, y, align, scale, PPGE_LINE_USE_ELLIPSIS, 0); + BeginVertexData(); + for (auto i = char_lines.cbegin(); i != char_lines.cend(); ++i) + { + for (auto j = i->cbegin(); j != i->cend(); ++j) + { + float cx1 = j->x; + float cy1 = j->y; + const AtlasChar &c = *j->c; + float cx2 = cx1 + c.pw * scale; + float cy2 = cy1 + c.ph * scale; + Vertex(cx1, cy1, c.sx, c.sy, atlasWidth, atlasHeight, color); + Vertex(cx2, cy2, c.ex, c.ey, atlasWidth, atlasHeight, color); + } + } + EndVertexDataAndDraw(GE_PRIM_RECTANGLES); + char_lines.clear(); +} + void PPGeDrawTextWrapped(const char *text, float x, float y, float wrapWidth, int align, float scale, u32 color) { if (!dlPtr) return; const AtlasFont &atlasfont = *ppge_atlas.fonts[0]; - unsigned int cval; - float w, h; - // TODO: Could ideally try to handle center, right align better. - PPGeMeasureText(text, scale, &w, &h); - if (align && w < wrapWidth) { - PPGeDoAlign(align, &x, &y, &w, &h); - } + BreakLines(text, atlasfont, x, y, align, scale, PPGE_LINE_USE_ELLIPSIS | PPGE_LINE_WRAP_WORD, wrapWidth); BeginVertexData(); - y += atlasfont.ascend*scale; - float sx = x; - bool skipWrap = false; - const float wrapCutoff = wrapWidth * 0.8f; - UTF8 utf(text); - while (true) { - if (utf.end()) - break; - cval = utf.next(); - if (cval == '\n') { - // This is not correct when centering or right-justifying, need to set x depending on line width (tricky) - y += atlasfont.height * scale; - x = sx; - skipWrap = false; - continue; - } - const AtlasChar *ch = PPGeGetChar(atlasfont, cval); - if (ch) { - const AtlasChar &c = *ch; - float cx1 = x + c.ox * scale; - float cy1 = y + c.oy * scale; - float cx2 = x + (c.ox + c.pw) * scale; - float cy2 = y + (c.oy + c.ph) * scale; + for (auto i = char_lines.cbegin(); i != char_lines.cend(); ++i) + { + for (auto j = i->cbegin(); j != i->cend(); ++j) + { + float cx1 = j->x; + float cy1 = j->y; + const AtlasChar &c = *j->c; + float cx2 = cx1 + c.pw * scale; + float cy2 = cy1 + c.ph * scale; Vertex(cx1, cy1, c.sx, c.sy, atlasWidth, atlasHeight, color); Vertex(cx2, cy2, c.ex, c.ey, atlasWidth, atlasHeight, color); - x += c.wx * scale; - - float nextWidth = NextWordWidth(utf, atlasfont, scale); - // This word is too long, and we're not near the end of the line. - if (nextWidth > wrapCutoff && wrapWidth + sx - x > wrapCutoff) { - skipWrap = true; - } - // Pretend the word is only a single character long. - if (skipWrap) { - nextWidth = c.wx * scale; - } - - if (x + nextWidth > wrapWidth) { - // This is not correct when centering or right-justifying, need to set x depending on line width (tricky) - y += atlasfont.height * scale; - x = sx; - skipWrap = false; - } } } EndVertexDataAndDraw(GE_PRIM_RECTANGLES); + char_lines.clear(); } // Draws a "4-patch" for button-like things that can be resized diff --git a/Core/Util/PPGeDraw.h b/Core/Util/PPGeDraw.h index cd0531e13b..f3a6bd72b7 100644 --- a/Core/Util/PPGeDraw.h +++ b/Core/Util/PPGeDraw.h @@ -41,6 +41,8 @@ void __PPGeShutdown(); void PPGeBegin(); void PPGeEnd(); +// Get the metrics of the bounding box of unwrapped text. +void PPGeMeasureText(const char *text, float scale, float *w, float *h); // If you want to draw using this texture but not go through the PSP GE emulation, // jsut call this. Will bind the texture to unit 0. @@ -62,6 +64,18 @@ enum { PPGE_ALIGN_BOTTOMRIGHT = PPGE_ALIGN_BOTTOM | PPGE_ALIGN_RIGHT, }; +enum { + PPGE_ESCAPE_NONE, + PPGE_ESCAPE_BACKSLASHED, +}; + +enum { + PPGE_LINE_NONE = 0, + PPGE_LINE_USE_ELLIPSIS = 1, // use ellipses in too long words + PPGE_LINE_WRAP_WORD = 2, + PPGE_LINE_WRAP_ANYWHERE = 4, +}; + // These functions must be called between PPGeBegin and PPGeEnd. // Draws some text using the one font we have. diff --git a/lang b/lang index a2f8b62322..bbadce3313 160000 --- a/lang +++ b/lang @@ -1 +1 @@ -Subproject commit a2f8b62322a1d0551d965f22ca6dab7d8dab8a27 +Subproject commit bbadce3313a26df53366019e9b7b9bf9b38fd7b7