mirror of
https://github.com/blupi-games/planetblupi
synced 2024-12-30 10:15:36 +01:00
Retrieve the width and height when creating the texture
This commit is contained in:
parent
1f4f156bf4
commit
275af9524d
50
src/text.cxx
50
src/text.cxx
@ -32,21 +32,37 @@
|
|||||||
|
|
||||||
struct TexText {
|
struct TexText {
|
||||||
SDL_Texture * outline;
|
SDL_Texture * outline;
|
||||||
|
int outlineW;
|
||||||
|
int outlineH;
|
||||||
|
|
||||||
SDL_Texture * base;
|
SDL_Texture * base;
|
||||||
|
int baseW;
|
||||||
|
int baseH;
|
||||||
|
|
||||||
SDL_Texture * over;
|
SDL_Texture * over;
|
||||||
|
|
||||||
TexText (const TexText & texText)
|
TexText (const TexText & texText)
|
||||||
{
|
{
|
||||||
this->outline = texText.outline;
|
this->outline = texText.outline;
|
||||||
this->base = texText.base;
|
this->base = texText.base;
|
||||||
this->over = texText.over;
|
this->over = texText.over;
|
||||||
|
this->outlineW = texText.outlineW;
|
||||||
|
this->outlineH = texText.outlineH;
|
||||||
|
this->baseW = texText.baseW;
|
||||||
|
this->baseH = texText.baseH;
|
||||||
}
|
}
|
||||||
|
|
||||||
TexText (SDL_Texture * outline, SDL_Texture * base, SDL_Texture * over)
|
TexText (
|
||||||
|
SDL_Texture * outline, int outlineW, int outlineH, SDL_Texture * base,
|
||||||
|
int baseW, int baseH, SDL_Texture * over)
|
||||||
{
|
{
|
||||||
this->outline = outline;
|
this->outline = outline;
|
||||||
this->base = base;
|
this->base = base;
|
||||||
this->over = over;
|
this->over = over;
|
||||||
|
this->outlineW = outlineW;
|
||||||
|
this->outlineH = outlineH;
|
||||||
|
this->baseW = baseW;
|
||||||
|
this->baseH = baseH;
|
||||||
}
|
}
|
||||||
|
|
||||||
~TexText ()
|
~TexText ()
|
||||||
@ -125,6 +141,11 @@ public:
|
|||||||
SDL_Texture * texBase = texText ? texText->base : nullptr;
|
SDL_Texture * texBase = texText ? texText->base : nullptr;
|
||||||
SDL_Texture * texOver = texText ? texText->over : nullptr;
|
SDL_Texture * texOver = texText ? texText->over : nullptr;
|
||||||
|
|
||||||
|
int outlineW = texText ? texText->outlineW : 0;
|
||||||
|
int outlineH = texText ? texText->outlineH : 0;
|
||||||
|
int baseW = texText ? texText->baseW : 0;
|
||||||
|
int baseH = texText ? texText->baseH : 0;
|
||||||
|
|
||||||
if (this->outline)
|
if (this->outline)
|
||||||
{
|
{
|
||||||
TTF_SetFontOutline (this->font, 1);
|
TTF_SetFontOutline (this->font, 1);
|
||||||
@ -135,14 +156,16 @@ public:
|
|||||||
TTF_RenderUTF8_Solid (this->font, pText, {0x00, 0x00, 0x00, 0});
|
TTF_RenderUTF8_Solid (this->font, pText, {0x00, 0x00, 0x00, 0});
|
||||||
texOutline = SDL_CreateTextureFromSurface (g_renderer, text);
|
texOutline = SDL_CreateTextureFromSurface (g_renderer, text);
|
||||||
SDL_FreeSurface (text);
|
SDL_FreeSurface (text);
|
||||||
|
SDL_QueryTexture (texOutline, &format, &access, &outlineW, &outlineH);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_QueryTexture (texOutline, &format, &access, &r0.w, &r0.h);
|
r0.w = outlineW;
|
||||||
|
r0.h = outlineH;
|
||||||
r0.x = pos.x;
|
r0.x = pos.x;
|
||||||
r0.y = pos.y;
|
r0.y = pos.y;
|
||||||
|
|
||||||
if (isRTL)
|
if (isRTL)
|
||||||
r0.x -= r0.w;
|
r0.x -= outlineW;
|
||||||
}
|
}
|
||||||
|
|
||||||
TTF_SetFontOutline (this->font, 0);
|
TTF_SetFontOutline (this->font, 0);
|
||||||
@ -153,6 +176,7 @@ public:
|
|||||||
TTF_RenderUTF8_Blended (this->font, pText, this->color);
|
TTF_RenderUTF8_Blended (this->font, pText, this->color);
|
||||||
texBase = SDL_CreateTextureFromSurface (g_renderer, text);
|
texBase = SDL_CreateTextureFromSurface (g_renderer, text);
|
||||||
SDL_FreeSurface (text);
|
SDL_FreeSurface (text);
|
||||||
|
SDL_QueryTexture (texBase, &format, &access, &baseW, &baseH);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!texOver)
|
if (!texOver)
|
||||||
@ -166,12 +190,13 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
SDL_Rect r;
|
SDL_Rect r;
|
||||||
SDL_QueryTexture (texBase, &format, &access, &r.w, &r.h);
|
r.w = baseW;
|
||||||
|
r.h = baseH;
|
||||||
r.x = pos.x + (isRTL ? -1 : 1);
|
r.x = pos.x + (isRTL ? -1 : 1);
|
||||||
r.y = pos.y + 1;
|
r.y = pos.y + 1;
|
||||||
|
|
||||||
if (isRTL)
|
if (isRTL)
|
||||||
r.x -= r.w;
|
r.x -= baseW;
|
||||||
|
|
||||||
if (this->outline)
|
if (this->outline)
|
||||||
pPixmap->Blit (-1, texOutline, r0, slope ? angle : 0, SDL_FLIP_NONE);
|
pPixmap->Blit (-1, texOutline, r0, slope ? angle : 0, SDL_FLIP_NONE);
|
||||||
@ -182,7 +207,8 @@ public:
|
|||||||
if (!texText)
|
if (!texText)
|
||||||
{
|
{
|
||||||
std::shared_ptr<struct TexText> _texText =
|
std::shared_ptr<struct TexText> _texText =
|
||||||
std::make_shared<struct TexText> (texOutline, texBase, texOver);
|
std::make_shared<struct TexText> (
|
||||||
|
texOutline, outlineW, outlineH, texBase, baseW, baseH, texOver);
|
||||||
this->cache.Insert (pText, _texText);
|
this->cache.Insert (pText, _texText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user