From 3de48ab3baa671d8d140df1ef24605d18a026917 Mon Sep 17 00:00:00 2001 From: nmlgc Date: Sat, 23 Dec 2023 17:39:30 +0100 Subject: [PATCH] [Effects] [Bug] Music title: Consistently right-align based on rendered width Unfortunately has a significant effect on the animation, especially for shorter titles, but maintains consistency with the obviously whitespace-trimmed title tags in the upcoming BGM mod packs. Let's fix that animation later, in #55. Completes P0272, funded by Ember2528. --- GIAN07/EFFECT.CPP | 10 +++++----- GIAN07/FONTUTY.CPP | 7 +++++-- GIAN07/FONTUTY.H | 2 +- game/bgm.cpp | 34 +++++++++++++++++++++++++++++++++- 4 files changed, 44 insertions(+), 9 deletions(-) diff --git a/GIAN07/EFFECT.CPP b/GIAN07/EFFECT.CPP index b3dd7b1..f7f1a40 100644 --- a/GIAN07/EFFECT.CPP +++ b/GIAN07/EFFECT.CPP @@ -239,17 +239,17 @@ void SetMusicTitle(int y, Narrow::string_view s) } if(n==SEFFECT_MAX) return; + const auto extent = DrawGrdFont(MTitleRect, s); + // 曲のタイトルが長すぎる場合、どうしましょう? // - auto x = (640 - 128 - 16 - (9 * min(s.length(), (23 + 1)))); + auto x = (640 - 128 - 32 - min(extent.w, 216)); SEffect[n].cmd = SEFC_MTITLE1; SEffect[n].x = (x<<6);// + (64*2)*16; SEffect[n].y = y<<6; SEffect[n].time = 64*2; - SEffect[n].vx = (s.length() * 16); - SEffect[n].vy = 16; - - DrawGrdFont(MTitleRect, s); + SEffect[n].vx = extent.w; + SEffect[n].vy = extent.h; } // エフェクトを動かす(仕様変更の可能性があります) // diff --git a/GIAN07/FONTUTY.CPP b/GIAN07/FONTUTY.CPP index 9fe76d4..0399661 100644 --- a/GIAN07/FONTUTY.CPP +++ b/GIAN07/FONTUTY.CPP @@ -254,9 +254,10 @@ TEXTRENDER_GDI TextObj = { DxObj, GrText, GDIFonts.fonts }; -void DrawGrdFont(TEXTRENDER_RECT_ID rect_id, Narrow::string_view str) +PIXEL_SIZE DrawGrdFont(TEXTRENDER_RECT_ID rect_id, Narrow::string_view str) { - TextObj.Prerender(rect_id, [&str](GIAN_TEXTRENDER_SESSION auto& s) { + PIXEL_SIZE extent = { 0, 0 }; + TextObj.Prerender(rect_id, [&](GIAN_TEXTRENDER_SESSION auto& s) { // The MIDI sequence titles passed to this function tend to come with // lots of trailing whitespace. Adding 1 also turns `npos` to 0. str = str.substr(0, (str.find_last_not_of(" ") + 1)); @@ -272,6 +273,7 @@ void DrawGrdFont(TEXTRENDER_RECT_ID rect_id, Narrow::string_view str) s.Put({ 1, 2 }, str, RGBA{ 0, 0, 128 }); s.Put({ 1, 1 }, str, RGBA{ 255, 255, 255 }); s.Put({ 0, 1 }, str, RGBA{ 255, 255, 255 }); + extent += s.Extent(str); constexpr auto FSIZE = 8; const PIXEL_COORD w = (str.size() * 16); @@ -286,4 +288,5 @@ void DrawGrdFont(TEXTRENDER_RECT_ID rect_id, Narrow::string_view str) } } }); + return extent; } diff --git a/GIAN07/FONTUTY.H b/GIAN07/FONTUTY.H index 993415c..ca5bd99 100644 --- a/GIAN07/FONTUTY.H +++ b/GIAN07/FONTUTY.H @@ -51,7 +51,7 @@ extern void GrpPutScore(int x, int y, char *s); // 得点アイテムのスコ extern void GrpPutMidNum(int x, int y, int n); // MIDI 用フォントを描画する // グラデーション付きフォントを描画する -void DrawGrdFont(TEXTRENDER_RECT_ID rect_id, Narrow::string_view str); +PIXEL_SIZE DrawGrdFont(TEXTRENDER_RECT_ID rect_id, Narrow::string_view str); #endif diff --git a/game/bgm.cpp b/game/bgm.cpp index f5ec673..f1ad5ea 100644 --- a/game/bgm.cpp +++ b/game/bgm.cpp @@ -45,7 +45,39 @@ std::chrono::duration BGM_PlayTime(void) Narrow::string_view BGM_Title(void) { - return Mid_GetTitle(); + auto ret = Mid_GetTitle(); + + // pbg bug: Four of the original track titles start with leading fullwidth + // spaces: + // + // #04: "   幻想帝都" + // #07: "  天空アーミー" + // #11: " 魔法少女十字軍" + // #16: "  シルクロードアリス" + // + // This looks like it was done on purpose to center the titles within the + // 216 maximum pixels that the original code designated for the in-game + // animation. However: + // + // • None of those actually has the correct amount of spaces that would + // have been required for exact centering. + // • If pbg intended to center all the tracks, there should have been + // leading whitespace in 14 of the track titles, and not just in 4. + // + // Since the in-game animation code does clearly intend these titles to be + // right-aligned, it makes more sense to just remove all leading + // whitespace. Doing this here will also benefit the Music Room. + const auto trim_leading = [](auto& str, Narrow::string_view prefix) { + const auto ret = str.starts_with(prefix); + if(ret) { + str.remove_prefix(prefix.size()); + } + return ret; + }; + while(trim_leading(ret, " ") || trim_leading(ret, "\x81\x40")) { + }; + + return ret; } bool BGM_ChangeMIDIDevice(int8_t direction)