RenderInfo amb tres estats (off/dalt/baix), temps de joc i persistència; ombra, mono-dígits i easing compartits (v0.14.0)
This commit is contained in:
1 parent
46a578fd86
commit
6f3fafbfff
17 files changed
+376
-97
No files matched your search
@@ -224,6 +224,54 @@ void Text::writeDX(Uint8 flags, int x, int y, const std::string& text, int kerni
|
||||
}
|
||||
}
|
||||
|
||||
// Amplada fixa per dígits: cada '0'-'9' ocupa digit_cell_w centrat dins de
|
||||
// la cel·la; la resta de glifs avancen amb la seua amplada natural. Emprat
|
||||
// pel comptador de temps de l'overlay RenderInfo per a que els dígits no
|
||||
// balleteigen quan canvien.
|
||||
void Text::writeMonoDigits(int x, int y, const std::string& text, Uint8 color, int digit_cell_w, int kerning) {
|
||||
int shift = 0;
|
||||
std::size_t pos = 0;
|
||||
|
||||
sprite_->setY(static_cast<float>(y));
|
||||
while (pos < text.size()) {
|
||||
std::uint32_t cp = nextCodepoint(text, pos);
|
||||
auto it = offset_.find(cp);
|
||||
if (it == offset_.end()) { it = offset_.find('?'); }
|
||||
if (it == offset_.end()) { continue; }
|
||||
|
||||
const bool IS_DIGIT = (cp >= '0' && cp <= '9');
|
||||
const int GLYPH_W = it->second.w;
|
||||
const int CELL_W = IS_DIGIT ? digit_cell_w : GLYPH_W;
|
||||
const int GLYPH_X = IS_DIGIT ? x + shift + ((CELL_W - GLYPH_W) / 2) : x + shift;
|
||||
|
||||
sprite_->setClip(static_cast<float>(it->second.x),
|
||||
static_cast<float>(it->second.y),
|
||||
static_cast<float>(box_width_),
|
||||
static_cast<float>(box_height_));
|
||||
sprite_->setX(static_cast<float>(GLYPH_X));
|
||||
sprite_->render(1, color);
|
||||
|
||||
shift += CELL_W + kerning;
|
||||
}
|
||||
}
|
||||
|
||||
auto Text::lengthMonoDigits(const std::string& text, int digit_cell_w, int kerning) const -> int {
|
||||
int shift = 0;
|
||||
std::size_t pos = 0;
|
||||
|
||||
while (pos < text.size()) {
|
||||
std::uint32_t cp = nextCodepoint(text, pos);
|
||||
auto it = offset_.find(cp);
|
||||
if (it == offset_.end()) { it = offset_.find('?'); }
|
||||
if (it == offset_.end()) { continue; }
|
||||
|
||||
const bool IS_DIGIT = (cp >= '0' && cp <= '9');
|
||||
shift += (IS_DIGIT ? digit_cell_w : it->second.w) + kerning;
|
||||
}
|
||||
|
||||
return shift > 0 ? shift - kerning : 0;
|
||||
}
|
||||
|
||||
auto Text::length(const std::string& text, int kerning) const -> int {
|
||||
int shift = 0;
|
||||
std::size_t pos = 0;
|
||||
|
||||
Reference in new issue
Block a user