Fix BitmapFont to not lose texture updates.
Texture could also be updated by GetWidth(), which calls GetGlyph() internally, and then the next LocateGlyph() call would return false.
This commit is contained in:
parent
af226b2437
commit
363f5c1ab8
|
@ -286,9 +286,11 @@ void UiCanvas::DrawBitmapChar(char32_t codepoint, int x, int y, RgbaColor color)
|
|||
|
||||
double s0, t0, s1, t1;
|
||||
size_t w, h;
|
||||
if(font->LocateGlyph(codepoint, &s0, &t0, &s1, &t1, &w, &h)) {
|
||||
font->LocateGlyph(codepoint, &s0, &t0, &s1, &t1, &w, &h);
|
||||
if(font->textureUpdated) {
|
||||
// LocateGlyph modified the texture, reload it.
|
||||
canvas->InvalidatePixmap(font->texture);
|
||||
font->textureUpdated = false;
|
||||
}
|
||||
|
||||
canvas->DrawPixmap(font->texture,
|
||||
|
|
|
@ -545,6 +545,7 @@ const BitmapFont::Glyph &BitmapFont::GetGlyph(char32_t codepoint) {
|
|||
}
|
||||
|
||||
it = glyphs.emplace(codepoint, std::move(glyph)).first;
|
||||
textureUpdated = true;
|
||||
return (*it).second;
|
||||
}
|
||||
|
||||
|
@ -553,10 +554,9 @@ const BitmapFont::Glyph &BitmapFont::GetGlyph(char32_t codepoint) {
|
|||
return GetGlyph(0xfffd);
|
||||
}
|
||||
|
||||
bool BitmapFont::LocateGlyph(char32_t codepoint,
|
||||
void BitmapFont::LocateGlyph(char32_t codepoint,
|
||||
double *s0, double *t0, double *s1, double *t1,
|
||||
size_t *w, size_t *h) {
|
||||
bool textureUpdated = (glyphs.find(codepoint) == glyphs.end());
|
||||
const Glyph &glyph = GetGlyph(codepoint);
|
||||
*w = glyph.advanceCells * 8;
|
||||
*h = 16;
|
||||
|
@ -564,7 +564,6 @@ bool BitmapFont::LocateGlyph(char32_t codepoint,
|
|||
*s1 = *s0 + (double)(*w) / texture->width;
|
||||
*t0 = (16.0 * (glyph.position / (texture->width / 16))) / texture->height;
|
||||
*t1 = *t0 + (double)(*h) / texture->height;
|
||||
return textureUpdated;
|
||||
}
|
||||
|
||||
size_t BitmapFont::GetWidth(char32_t codepoint) {
|
||||
|
|
|
@ -58,6 +58,7 @@ public:
|
|||
std::string unifontData;
|
||||
std::map<char32_t, Glyph> glyphs;
|
||||
std::shared_ptr<Pixmap> texture;
|
||||
bool textureUpdated;
|
||||
uint16_t nextPosition;
|
||||
|
||||
static BitmapFont From(std::string &&unifontData);
|
||||
|
@ -65,7 +66,7 @@ public:
|
|||
|
||||
bool IsEmpty() const { return unifontData.empty(); }
|
||||
const Glyph &GetGlyph(char32_t codepoint);
|
||||
bool LocateGlyph(char32_t codepoint, double *s0, double *t0, double *s1, double *t1,
|
||||
void LocateGlyph(char32_t codepoint, double *s0, double *t0, double *s1, double *t1,
|
||||
size_t *advanceWidth, size_t *boundingHeight);
|
||||
|
||||
void AddGlyph(char32_t codepoint, std::shared_ptr<const Pixmap> pixmap);
|
||||
|
|
Loading…
Reference in New Issue
Block a user