diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index f033b153a2..4c1ab9c18b 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -665,7 +665,7 @@ void EmuScreen::sendMessage(UIMessage message, const char *value) { // temporary workaround for hotkey its freeze the ui when open chat screen using hotkey and native keyboard is enable if (g_Config.bBypassOSKWithKeyboard) { // TODO: Make translatable. - g_OSD.Show(OSDType::MESSAGE_INFO, "Disable \"Use system native keyboard\" to use chat hotkey", 2.0f); + g_OSD.Show(OSDType::MESSAGE_INFO, "Disable \"Use system native keyboard\" to use chat hotkey", 2.0f, "chatHotKey"); } else { OpenChat(true); } @@ -943,7 +943,7 @@ void EmuScreen::ProcessVKey(VirtKey virtKey, bool down) { if (SaveState::CanRewind()) { SaveState::Rewind(&ShowMessageAfterSaveStateAction); } else { - g_OSD.Show(OSDType::MESSAGE_WARNING, sc->T("norewind", "No rewind save states available"), 2.0); + g_OSD.Show(OSDType::MESSAGE_WARNING, sc->T("norewind", "No rewind save states available"), 2.0, "norewind"); } } } diff --git a/UI/GameBrowser.cpp b/UI/GameBrowser.cpp index 4636427c35..d6b3c6cd07 100644 --- a/UI/GameBrowser.cpp +++ b/UI/GameBrowser.cpp @@ -78,75 +78,6 @@ static float ListTextRightMargin(GameBrowserViewMode viewMode) { return 0.0f; } -// In the list views, rightText (like a game ID) goes at the right edge, as for a game with a picture. -static void DrawIconWithText(UIContext &dc, ImageID image, std::string_view text, const Bounds &bounds, GameBrowserViewMode viewMode, const UI::Style &style, std::string_view rightText = {}) { - if (viewMode == GameBrowserViewMode::GRID) { - float tw, th; - dc.MeasureText(dc.GetFontStyle(), g_Config.fGameGridScale, g_Config.fGameGridScale, text, &tw, &th, 0); - dc.PushScissor(bounds); - const FontStyle *fontStyle = GetTextStyle(dc, UI::TextSize::Small); - dc.SetFontStyle(*GetTextStyle(dc, UI::TextSize::Small)); - - int iconSize = image == ImageID("I_UP_DIRECTORY") ? (float)dc.Draw()->GetAtlas()->getImage(image)->h : bounds.h * 0.3f; - float textWidth = 0.0f; - float textHeight = 0; - dc.MeasureTextRect(*fontStyle, 1.0f, 1.0f, text, bounds.w - 10, &textWidth, &textHeight, ALIGN_HCENTER | FLAG_WRAP_TEXT); - - int totalHeight = iconSize + (int)textHeight; - - const float y = std::max(0.0f, bounds.h / 2.0f - totalHeight / 2.0f); - - if (image.isValid()) { - const AtlasImage *img = dc.Draw()->GetAtlas()->getImage(image); - if (img && img->h > 0) { - dc.RebindTexture(); - dc.Draw()->DrawImage(image, bounds.centerX(), bounds.y + y + 2, iconSize / (float)img->h, style.fgColor, ALIGN_TOP | ALIGN_HCENTER); - } - } - - if (image != ImageID("I_UP_DIRECTORY") && image != ImageID("I_PIN") && image != ImageID("I_UNPIN")) { - dc.DrawTextRect(text, bounds.Inset(5, y + iconSize + 4, 5, 2), style.fgColor, ALIGN_HCENTER | FLAG_WRAP_TEXT); - } - dc.SetFontStyle(dc.GetTheme().uiFont); - dc.PopScissor(); - } else { - float tw, th; - // List, large list - dc.MeasureText(dc.GetFontStyle(), 1.0f, 1.0f, text, &tw, &th, 0); - - const float textX = ListTextX(viewMode); - if (viewMode == GameBrowserViewMode::LARGE_LIST) { - const float scale = g_Config.fGameGridScale; - dc.Draw()->DrawImage(image, bounds.x + LARGE_LIST_LEFT_PAD + LARGE_LIST_ICON_W * 0.5f * scale, bounds.centerY(), 0.88f * scale, style.fgColor, ALIGN_CENTER); - } else { - dc.Draw()->DrawImage(image, bounds.x + 72, bounds.centerY(), 0.88f, style.fgColor, ALIGN_CENTER); - } - - float tx = textX; - int availableWidth = bounds.w - textX - ListTextRightMargin(viewMode); - if (!rightText.empty()) { - float vw, vh; - dc.MeasureText(dc.GetFontStyle(), 0.7f, 0.7f, rightText, &vw, &vh, 0); - availableWidth -= vw + 20; - dc.SetFontScale(0.7f, 0.7f); - dc.DrawText(rightText, bounds.x + availableWidth + textX + 10, bounds.centerY(), style.fgColor, ALIGN_VCENTER); - dc.SetFontScale(1.0f, 1.0f); - } - float sineWidth = std::max(0.0f, (tw - availableWidth)) / 2.0f; - if (availableWidth < tw) { - tx -= (1.0f + sin(time_now_d() * 1.5f)) * sineWidth; - Bounds tb = bounds; - tb.x = bounds.x + textX; - tb.w = availableWidth; - dc.PushScissor(tb); - } - dc.DrawText(text, bounds.x + tx, bounds.centerY(), style.fgColor, ALIGN_VCENTER | FLAG_WRAP_TEXT); - if (availableWidth < tw) { - dc.PopScissor(); - } - } -} - class GameButton : public UI::Clickable { public: GameButton(const Path &gamePath, GameBrowserViewMode viewMode, UI::LayoutParams *layoutParams = nullptr) @@ -421,6 +352,76 @@ static ImageID ChooseGameIcon(const std::shared_ptr &ginfo) { } } +// Grid style. Fallback +static void DrawIconWithTextGrid(UIContext &dc, ImageID image, std::string_view text, const Bounds &bounds, const UI::Style &style) { + float tw, th; + dc.MeasureText(dc.GetFontStyle(), g_Config.fGameGridScale, g_Config.fGameGridScale, text, &tw, &th, 0); + dc.PushScissor(bounds); + const FontStyle *fontStyle = GetTextStyle(dc, UI::TextSize::Small); + dc.SetFontStyle(*GetTextStyle(dc, UI::TextSize::Small)); + + int iconSize = image == ImageID("I_UP_DIRECTORY") ? (float)dc.Draw()->GetAtlas()->getImage(image)->h : bounds.h * 0.3f; + float textWidth = 0.0f; + float textHeight = 0; + dc.MeasureTextRect(*fontStyle, 1.0f, 1.0f, text, bounds.w - 10, &textWidth, &textHeight, ALIGN_HCENTER | FLAG_WRAP_TEXT); + + int totalHeight = iconSize + (int)textHeight; + + const float y = std::max(0.0f, bounds.h / 2.0f - totalHeight / 2.0f); + + if (image.isValid()) { + const AtlasImage *img = dc.Draw()->GetAtlas()->getImage(image); + if (img && img->h > 0) { + dc.RebindTexture(); + dc.Draw()->DrawImage(image, bounds.centerX(), bounds.y + y + 2, iconSize / (float)img->h, style.fgColor, ALIGN_TOP | ALIGN_HCENTER); + } + } + + if (image != ImageID("I_UP_DIRECTORY") && image != ImageID("I_PIN") && image != ImageID("I_UNPIN")) { + dc.DrawTextRect(text, bounds.Inset(5, y + iconSize + 4, 5, 2), style.fgColor, ALIGN_HCENTER | FLAG_WRAP_TEXT); + } + dc.SetFontStyle(dc.GetTheme().uiFont); + dc.PopScissor(); +} + +// List, large list +// In the list views, rightText (like a game ID) goes at the right edge, as for a game with a picture. +static void DrawIconWithTextList(UIContext &dc, ImageID image, std::string_view text, const Bounds &bounds, GameBrowserViewMode viewMode, const UI::Style &style, std::string_view rightText = {}) { + float tw, th; + dc.MeasureText(dc.GetFontStyle(), 1.0f, 1.0f, text, &tw, &th, 0); + + const float textX = ListTextX(viewMode); + if (viewMode == GameBrowserViewMode::LARGE_LIST) { + const float scale = g_Config.fGameGridScale; + dc.Draw()->DrawImage(image, bounds.x + LARGE_LIST_LEFT_PAD + LARGE_LIST_ICON_W * 0.5f * scale, bounds.centerY(), 0.88f * scale, style.fgColor, ALIGN_CENTER); + } else { + dc.Draw()->DrawImage(image, bounds.x + 72, bounds.centerY(), 0.88f, style.fgColor, ALIGN_CENTER); + } + + float tx = textX; + int availableWidth = bounds.w - textX - ListTextRightMargin(viewMode); + if (!rightText.empty()) { + float vw, vh; + dc.MeasureText(dc.GetFontStyle(), 0.7f, 0.7f, rightText, &vw, &vh, 0); + availableWidth -= vw + 20; + dc.SetFontScale(0.7f, 0.7f); + dc.DrawText(rightText, bounds.x + availableWidth + textX + 10, bounds.centerY(), style.fgColor, ALIGN_VCENTER); + dc.SetFontScale(1.0f, 1.0f); + } + float sineWidth = std::max(0.0f, (tw - availableWidth)) / 2.0f; + if (availableWidth < tw) { + tx -= (1.0f + sin(time_now_d() * 1.5f)) * sineWidth; + Bounds tb = bounds; + tb.x = bounds.x + textX; + tb.w = availableWidth; + dc.PushScissor(tb); + } + dc.DrawText(text, bounds.x + tx, bounds.centerY(), style.fgColor, ALIGN_VCENTER | FLAG_WRAP_TEXT); + if (availableWidth < tw) { + dc.PopScissor(); + } +} + void GameButton::Draw(UIContext &dc) { // Like the XMB, only the selected game plays its video. Only keyboard/gamepad focus selects, since with // touch or the mouse, getting a video to play without launching the game was too fiddly. @@ -574,7 +575,11 @@ void GameButton::Draw(UIContext &dc) { if (down_) style = dc.GetTheme().itemDownStyle; if (!IsEnabled()) style = dc.GetTheme().itemDisabledStyle; - DrawIconWithText(dc, imageIcon, ginfo->GetTitle(), bounds_, viewMode_, style, g_Config.bShowIDOnGameIcon ? std::string_view(ginfo->id_version) : std::string_view()); + if (viewMode_ == GameBrowserViewMode::GRID) { + DrawIconWithTextGrid(dc, imageIcon, ginfo->GetTitle(), bounds_, style); + } else { + DrawIconWithTextList(dc, imageIcon, ginfo->GetTitle(), bounds_, viewMode_, style, g_Config.bShowIDOnGameIcon ? std::string_view(ginfo->id_version) : std::string_view()); + } } else { char discNumInfo[8]; if (ginfo->disc_total > 1) @@ -768,7 +773,11 @@ void DirButton::Draw(UIContext &dc) { if (!IsEnabled()) style = dc.GetTheme().itemDisabledStyle; dc.FillRect(style.background, bounds_); - DrawIconWithText(dc, image, text, bounds_, viewMode_, style); + if (viewMode_ == GameBrowserViewMode::GRID) { + DrawIconWithTextGrid(dc, image, text, bounds_, style); + } else { + DrawIconWithTextList(dc, image, text, bounds_, viewMode_, style); + } } GameBrowser::GameBrowser(int token, const Path &path, BrowseFlags browseFlags, bool portrait, int *viewMode, ScreenManager *screenManager, std::string_view lastText, std::string_view lastLink, UI::LayoutParams *layoutParams) diff --git a/UI/PauseScreen.cpp b/UI/PauseScreen.cpp index f83c6cbc67..5208b93a8d 100644 --- a/UI/PauseScreen.cpp +++ b/UI/PauseScreen.cpp @@ -83,7 +83,7 @@ void copyDeepLinkForPath(std::string_view filePath); void ShowMessageAfterSaveStateAction(SaveState::Status status, std::string_view message, std::string_view metadata) { if (!message.empty()) { g_OSD.Show(status == SaveState::Status::SUCCESS ? OSDType::MESSAGE_SUCCESS : OSDType::MESSAGE_ERROR, - message, metadata, status == SaveState::Status::SUCCESS ? 2.0 : 5.0); + message, metadata, status == SaveState::Status::SUCCESS ? 2.0 : 5.0, "savestateaction"); } }