marcador provisional

This commit is contained in:
2026-04-06 14:53:58 +02:00
parent 67bf6b2017
commit 4c5e1e5470
12 changed files with 180 additions and 181 deletions

View File

@@ -219,6 +219,37 @@ void Text::writeColored(int x, int y, const std::string& text, Uint8 color, int
}
}
// Escribe texto monoespaciado con color (cada glifo centrado en una celda de ancho fijo)
void Text::writeColoredMono(int x, int y, const std::string& text, Uint8 color, int cell_w) { // NOLINT(readability-convert-member-functions-to-static)
int shift = 0;
size_t pos = 0;
sprite_->setY(y);
while (pos < text.size()) {
uint32_t cp = nextCodepoint(text, pos);
auto it = offset_.find(cp);
if (it == offset_.end()) { it = offset_.find('?'); }
if (it != offset_.end()) {
const int GLYPH_OFFSET = (cell_w - it->second.w) / 2;
sprite_->setClip(it->second.x, it->second.y, box_width_, box_height_);
sprite_->setX(x + shift + GLYPH_OFFSET);
sprite_->render(1, color);
}
shift += cell_w;
}
}
// Obtiene la longitud en pixels de una cadena monoespaciada
auto Text::lengthMono(const std::string& text, int cell_w) const -> int {
size_t pos = 0;
int count = 0;
while (pos < text.size()) {
nextCodepoint(text, pos);
++count;
}
return count * cell_w;
}
// Escribe el texto con sombra
void Text::writeShadowed(int x, int y, const std::string& text, Uint8 color, Uint8 shadow_distance, int kerning, int lenght) {
writeColored(x + shadow_distance, y + shadow_distance, text, color, kerning, lenght);