1
0
mirror of https://github.com/blupi-games/planetblupi synced 2024-12-30 10:15:36 +01:00

Use only one function for drawing text (with slope or not)

This commit is contained in:
Mathieu Schroeter 2019-02-05 22:51:48 +01:00
parent c772477507
commit e012a5d1a2
2 changed files with 16 additions and 42 deletions

View File

@ -176,15 +176,19 @@ GetCharWidth (const char *& c, Sint32 font)
* \param[in] pos - The coordinates for the text. * \param[in] pos - The coordinates for the text.
* \param[in] pText - The text. * \param[in] pText - The text.
* \param[in] font - The font style (little or normal). * \param[in] font - The font style (little or normal).
* \param[in] slope - Text slope.
*/ */
void void
DrawText (CPixmap * pPixmap, Point pos, const char * pText, Sint32 font) DrawText (
CPixmap * pPixmap, Point pos, const char * pText, Sint32 font, Sint32 slope)
{ {
Sint32 rank; Sint32 rank;
bool isNumber = false; bool isNumber = false;
int numberSize = 0; int numberSize = 0;
const char * it = nullptr; const char * it = nullptr;
int skip = 0; int skip = 0;
Sint32 start = pos.y;
Sint32 rel = 0;
while (*pText != '\0' || skip) while (*pText != '\0' || skip)
{ {
@ -210,9 +214,14 @@ DrawText (CPixmap * pPixmap, Point pos, const char * pText, Sint32 font)
rank = GetOffset (pText); rank = GetOffset (pText);
auto inc = rank > 127; auto inc = rank > 127;
auto lg = GetCharWidth (pText, font);
if (IsRightReading ()) if (IsRightReading ())
pos.x += -GetCharWidth (pText, font); pos.x += -lg;
rel += lg;
if (slope)
pos.y = start + rel / slope;
if (font != FONTLITTLE) if (font != FONTLITTLE)
{ {
@ -223,7 +232,7 @@ DrawText (CPixmap * pPixmap, Point pos, const char * pText, Sint32 font)
pPixmap->DrawIcon (-1, CHLITTLE, rank, pos); pPixmap->DrawIcon (-1, CHLITTLE, rank, pos);
if (!IsRightReading ()) if (!IsRightReading ())
pos.x += GetCharWidth (pText, font); pos.x += lg;
if (!numberSize && skip > 0) if (!numberSize && skip > 0)
{ {
@ -237,35 +246,6 @@ DrawText (CPixmap * pPixmap, Point pos, const char * pText, Sint32 font)
} }
} }
// Affiche un texte penché.
void
DrawTextPente (
CPixmap * pPixmap, Point pos, const char * pText, Sint32 pente, Sint32 font)
{
Sint32 rank, lg, rel, start;
start = pos.y;
rel = 0;
while (*pText != 0)
{
rank = GetOffset (pText);
auto inc = rank > 127;
rank += 256 * font;
pPixmap->DrawIcon (-1, CHTEXT, rank, pos);
lg = GetCharWidth (pText, font);
if (inc)
pText++;
pText++;
rel += lg;
pos.x += IsRightReading () ? -lg : lg;
pos.y = start + rel / pente;
}
}
// Affiche un pavé de texte. // Affiche un pavé de texte.
// Une ligne vide est affichée avec un demi interligne ! // Une ligne vide est affichée avec un demi interligne !
// Si part != -1, n'affiche que les lignes qui commencent // Si part != -1, n'affiche que les lignes qui commencent
@ -309,10 +289,7 @@ DrawTextRect (
continue; continue;
} }
if (pente == 0) DrawText (pPixmap, pos, pDest, font, pente);
DrawText (pPixmap, pos, pDest, font);
else
DrawTextPente (pPixmap, pos, pDest, pente, font);
if (pDest[0] == 0) // ligne vide ? if (pDest[0] == 0) // ligne vide ?
{ {

View File

@ -27,12 +27,9 @@
#define FONTLITTLE 10 #define FONTLITTLE 10
// clang-format on // clang-format on
void void DrawText (
DrawText (CPixmap * pPixmap, Point pos, const char * pText, Sint32 font = 0); CPixmap * pPixmap, Point pos, const char * pText, Sint32 font = 0,
Sint32 slope = 0);
void DrawTextPente (
CPixmap * pPixmap, Point pos, const char * pText, Sint32 pente,
Sint32 font = 0);
void DrawTextRect ( void DrawTextRect (
CPixmap * pPixmap, Point pos, char * pText, Sint32 pente, Sint32 font = 0, CPixmap * pPixmap, Point pos, char * pText, Sint32 pente, Sint32 font = 0,