Only use JIS->UTF8 conversion with new overlay.

Fix pixel font display.
This commit is contained in:
BearOso 2023-05-08 13:55:54 -05:00
parent ff35034cf7
commit 8719a4761e
3 changed files with 34 additions and 31 deletions

View File

@ -140,6 +140,30 @@ static void ImGui_DrawTextOverlay(const char *text,
draw_list->AddText(nullptr, 0.0f, ImVec2(x + padding, y + padding), settings.text_color, text, nullptr, wrap_at); draw_list->AddText(nullptr, 0.0f, ImVec2(x + padding, y + padding), settings.text_color, text, nullptr, wrap_at);
} }
static std::string sjis_to_utf8(std::string in)
{
std::string out;
for (const auto &i : in)
{
unsigned char c = i;
if (c > 160 && c < 192)
{
out += "\357\275";
out += c;
}
else if (c >= 192)
{
out += "\357\276";
c -= 0x40;
out += c;
}
else
out += c;
}
return out;
}
bool S9xImGuiDraw(int width, int height) bool S9xImGuiDraw(int width, int height)
{ {
if (Memory.ROMFilename.empty()) if (Memory.ROMFilename.empty())
@ -223,13 +247,16 @@ bool S9xImGuiDraw(int width, int height)
} }
if (!GFX.InfoString.empty()) if (!GFX.InfoString.empty())
ImGui_DrawTextOverlay(GFX.InfoString.c_str(), {
auto utf8_message = sjis_to_utf8(GFX.InfoString);
ImGui_DrawTextOverlay(utf8_message.c_str(),
settings.spacing, settings.spacing,
height - settings.spacing, height - settings.spacing,
settings.spacing, settings.spacing,
ImGui::DrawTextAlignment::BEGIN, ImGui::DrawTextAlignment::BEGIN,
ImGui::DrawTextAlignment::END, ImGui::DrawTextAlignment::END,
width - settings.spacing * 4); width - settings.spacing * 4);
}
ImGui::Render(); ImGui::Render();

View File

@ -1818,7 +1818,7 @@ void S9xVariableDisplayString(const char* string, int linesFromBottom, int pixel
int min_lines = 1; int min_lines = 1;
std::string msg(string); std::string msg(string);
for (auto& c : msg) for (auto& c : msg)
if (c < 32) if (c == '\n')
min_lines++; min_lines++;
if (min_lines > linesFromBottom) if (min_lines > linesFromBottom)
linesFromBottom = min_lines; linesFromBottom = min_lines;
@ -1836,10 +1836,10 @@ void S9xVariableDisplayString(const char* string, int linesFromBottom, int pixel
for (int i = 0; i < len; i++) for (int i = 0; i < len; i++)
{ {
int cindex = string[i] - 32; int cindex = (uint8)string[i] - 32;
int char_width = font_width - (monospace ? 1 : (var8x10font_kern[cindex][0] + var8x10font_kern[cindex][1])); int char_width = font_width - (monospace ? 1 : (var8x10font_kern[cindex][0] + var8x10font_kern[cindex][1]));
if (dst_x + char_width > SNES_WIDTH || (uint8)string[i] < 32) if (dst_x + char_width > SNES_WIDTH || string[i] == '\n')
{ {
if (!allowWrap) if (!allowWrap)
break; break;
@ -1852,7 +1852,7 @@ void S9xVariableDisplayString(const char* string, int linesFromBottom, int pixel
break; break;
} }
if ((uint8)string[i] < 32) if (string[i] == '\n')
continue; continue;
VariableDisplayChar(dst_x, dst_y, string[i], monospace, overlap); VariableDisplayChar(dst_x, dst_y, string[i], monospace, overlap);

View File

@ -3377,37 +3377,13 @@ const char * CMemory::PublishingCompany (void)
return (nintendo_licensees[CompanyId]); return (nintendo_licensees[CompanyId]);
} }
static std::string sjis_to_utf8(std::string in)
{
std::string out;
for (const auto &i : in)
{
unsigned char c = i;
if (c > 160 && c < 192)
{
out += "\357\275";
out += c;
}
else if (c >= 192)
{
out += "\357\276";
c -= 0x40;
out += c;
}
else if (c >= 32)
out += c;
}
return out;
}
std::string CMemory::GetMultilineROMInfo() std::string CMemory::GetMultilineROMInfo()
{ {
bool8 isChecksumOK = (Memory.ROMChecksum + Memory.ROMComplementChecksum == 0xffff) && bool8 isChecksumOK = (Memory.ROMChecksum + Memory.ROMComplementChecksum == 0xffff) &&
(Memory.ROMChecksum == Memory.CalculatedChecksum); (Memory.ROMChecksum == Memory.CalculatedChecksum);
std::string utf8_romname = sjis_to_utf8(Memory.ROMName); std::string utf8_romname = Memory.ROMName;
std::string tvstandard = Settings.PAL ? "PAL" : "NTSC"; std::string tvstandard = Settings.PAL ? "PAL" : "NTSC";
std::string romid = sjis_to_utf8(Memory.ROMId); std::string romid = Memory.ROMId;
std::string checksum = isChecksumOK ? "Checksum OK" std::string checksum = isChecksumOK ? "Checksum OK"
: Settings.IsPatched == 3 ? "UPS patched" : Settings.IsPatched == 3 ? "UPS patched"
: Settings.IsPatched == 2 ? "BPS patched" : Settings.IsPatched == 2 ? "BPS patched"