fix rotated text

This commit is contained in:
2025-10-09 23:19:05 +02:00
parent 7fc48e5e93
commit c3295b9b01

View File

@@ -1053,9 +1053,11 @@ private:
fpsLastSampleMs = nowMs; fpsLastSampleMs = nowMs;
} }
char fpsBuf[16]; char fpsValueBuf[16];
std::snprintf(fpsBuf, sizeof(fpsBuf), "%u FPS", static_cast<unsigned>(fpsCurrent)); std::snprintf(fpsValueBuf, sizeof(fpsValueBuf), "%u", static_cast<unsigned>(fpsCurrent));
const std::string fpsText(fpsBuf); const std::string fpsValue(fpsValueBuf);
const std::string fpsLabel = "FPS";
const std::string fpsText = fpsValue + " FPS";
const std::string scaleHint = (scaleMode == ScaleMode::FullHeight) ? "START+B NORMAL" : "START+B SCALE"; const std::string scaleHint = (scaleMode == ScaleMode::FullHeight) ? "START+B NORMAL" : "START+B SCALE";
if (scaleMode == ScaleMode::FullHeight) { if (scaleMode == ScaleMode::FullHeight) {
@@ -1069,46 +1071,69 @@ private:
const int maxLeftX = std::max(0, screenWidth - rotatedWidth); const int maxLeftX = std::max(0, screenWidth - rotatedWidth);
const int maxRightXBase = std::max(0, screenWidth - rotatedWidth); const int maxRightXBase = std::max(0, screenWidth - rotatedWidth);
const int horizontalPadding = 8;
const int fpsLineGap = 4;
const int fpsLabelWidth = font16x8::measureText(fpsLabel, 1, 1);
const int fpsValueWidth = font16x8::measureText(fpsValue, 1, 1);
const int fpsBlockWidth = std::max(fpsLabelWidth, fpsValueWidth);
int fpsX = std::max(0, screenWidth - fpsBlockWidth - horizontalPadding);
const int fpsY = horizontalPadding;
font16x8::drawText(framebuffer, fpsX, fpsY, fpsLabel, 1, true, 1);
font16x8::drawText(framebuffer, fpsX, fpsY + font16x8::kGlyphHeight + fpsLineGap, fpsValue, 1, true, 1);
const int reservedTop = fpsY + (font16x8::kGlyphHeight * 2) + fpsLineGap + horizontalPadding;
if (!activeRomName.empty()) { if (!activeRomName.empty()) {
const int textHeight = measureVerticalText(activeRomName, textScale); const std::string rotatedRomName(activeRomName.rbegin(), activeRomName.rend());
const int textHeight = measureVerticalText(rotatedRomName, textScale);
const int maxOrigin = std::max(0, screenHeight - textHeight); const int maxOrigin = std::max(0, screenHeight - textHeight);
int leftX = std::clamp((leftMargin - rotatedWidth) / 2, 0, maxLeftX); int leftX = 8;
int leftY = std::clamp((screenHeight - textHeight) / 2, 0, maxOrigin); int leftY = std::clamp((screenHeight - textHeight) / 2, 0, maxOrigin);
drawTextRotated(framebuffer, leftX, leftY, activeRomName, false, textScale, true, 1); drawTextRotated(framebuffer, leftX, leftY, rotatedRomName, true, textScale, true, 1);
if (!statusMessage.empty()) {
const std::string rotatedStatusMessage(statusMessage.rbegin(), statusMessage.rend());
const int textHeight = measureVerticalText(rotatedStatusMessage, textScale);
const int maxOrigin = std::max(0, screenHeight - textHeight);
leftX = leftX + 20;
leftY = std::clamp((screenHeight - textHeight) / 2, 0, maxOrigin);
drawTextRotated(framebuffer, leftX, leftY, rotatedStatusMessage, true, textScale, true, 1);
}
} }
std::vector<std::string_view> rightTexts;
rightTexts.reserve(2U);
rightTexts.emplace_back("START+SELECT BACK");
rightTexts.emplace_back(scaleHint);
const int gap = 8; const int gap = 8;
int totalRight = 0; int totalRightHeight = 0;
const auto accumulateHeight = [&](std::string_view text) { for (std::string_view text: rightTexts) {
if (text.empty()) if (text.empty())
return; continue;
if (totalRight > 0) std::string rotated(text.rbegin(), text.rend());
totalRight += gap; if (totalRightHeight > 0)
totalRight += measureVerticalText(text, textScale); totalRightHeight += gap;
}; totalRightHeight += measureVerticalText(rotated, textScale);
accumulateHeight(fpsText); }
accumulateHeight("START+SELECT BACK");
accumulateHeight(scaleHint);
if (!statusMessage.empty())
accumulateHeight(statusMessage);
const int maxRightOrigin = std::max(0, screenHeight - totalRight); const int maxRightOrigin = std::max(0, screenHeight - totalRightHeight);
int rightY = std::clamp((screenHeight - totalRight) / 2, 0, maxRightOrigin); int rightY = std::clamp((screenHeight - totalRightHeight) / 2, 0, maxRightOrigin);
int rightX = screenWidth - rightMargin + std::max(0, (rightMargin - rotatedWidth) / 2); if (rightY < reservedTop)
rightX = std::clamp(rightX, 0, maxRightXBase); rightY = std::min(std::max(reservedTop, 0), maxRightOrigin);
const auto drawRight = [&](std::string_view text) { int rightX = screenWidth - 20;
for (size_t i = 0; i < rightTexts.size(); ++i) {
std::string_view text = rightTexts[i];
if (text.empty()) if (text.empty())
return; continue;
drawTextRotated(framebuffer, rightX, rightY, text, true, textScale, true, 1); std::string rotated(text.rbegin(), text.rend());
rightY += measureVerticalText(text, textScale); rightY = screenHeight - measureVerticalText(rotated, textScale) - 8;
rightY += gap; drawTextRotated(framebuffer, rightX, rightY, rotated, true, textScale, true, 1);
}; rightX -= 20;
drawRight(fpsText); }
drawRight("START+SELECT BACK");
drawRight(scaleHint);
if (!statusMessage.empty())
drawRight(statusMessage);
} else { } else {
if (!activeRomName.empty()) if (!activeRomName.empty())
font16x8::drawText(framebuffer, 16, 16, activeRomName, 1, true, 1); font16x8::drawText(framebuffer, 16, 16, activeRomName, 1, true, 1);