2017-08-03 22:51:40 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the planetblupi source code
|
|
|
|
* Copyright (C) 1997, Daniel Roux & EPSITEC SA
|
2019-01-26 15:34:29 +01:00
|
|
|
* Copyright (C) 2017-2019, Mathieu Schroeter
|
2017-08-03 22:51:40 +02:00
|
|
|
* http://epsitec.ch; http://www.blupi.org; http://github.com/blupi-games
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see http://gnu.org/licenses
|
|
|
|
*/
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2017-08-04 00:21:47 +02:00
|
|
|
#include <stdlib.h>
|
2017-02-15 17:42:02 +01:00
|
|
|
|
2022-07-09 00:15:53 +02:00
|
|
|
#include <SDL_ttf.h>
|
|
|
|
|
2017-10-06 18:23:07 +02:00
|
|
|
#include "blupi.h"
|
2017-01-21 17:27:46 +01:00
|
|
|
#include "def.h"
|
2017-10-06 18:23:07 +02:00
|
|
|
#include "event.h"
|
2017-09-12 17:09:50 +02:00
|
|
|
#include "misc.h"
|
2017-01-21 17:27:46 +01:00
|
|
|
#include "pixmap.h"
|
|
|
|
#include "text.h"
|
|
|
|
|
2022-07-15 17:57:14 +02:00
|
|
|
struct TexText {
|
|
|
|
SDL_Texture * outline;
|
|
|
|
SDL_Texture * base;
|
|
|
|
SDL_Texture * over;
|
|
|
|
|
|
|
|
TexText (const TexText & texText)
|
|
|
|
{
|
|
|
|
this->outline = texText.outline;
|
|
|
|
this->base = texText.base;
|
|
|
|
this->over = texText.over;
|
|
|
|
}
|
|
|
|
|
|
|
|
TexText (SDL_Texture * outline, SDL_Texture * base, SDL_Texture * over)
|
|
|
|
{
|
|
|
|
this->outline = outline;
|
|
|
|
this->base = base;
|
|
|
|
this->over = over;
|
|
|
|
}
|
|
|
|
|
|
|
|
~TexText ()
|
|
|
|
{
|
2022-07-15 22:55:28 +02:00
|
|
|
SDL_DestroyTexture (this->outline);
|
2022-07-15 17:57:14 +02:00
|
|
|
SDL_DestroyTexture (this->base);
|
2022-07-15 22:55:28 +02:00
|
|
|
SDL_DestroyTexture (this->over);
|
2022-07-15 17:57:14 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class Cache
|
|
|
|
{
|
|
|
|
private:
|
2022-07-15 22:55:28 +02:00
|
|
|
std::unordered_map<std::string, std::shared_ptr<struct TexText>> list;
|
2022-07-15 17:57:14 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
Cache () {}
|
|
|
|
|
|
|
|
struct TexText * Get (const std::string & text)
|
|
|
|
{
|
|
|
|
const auto entry = this->list.find (text);
|
|
|
|
if (entry != this->list.end ())
|
2022-07-15 22:55:28 +02:00
|
|
|
return entry->second.get ();
|
2022-07-15 17:57:14 +02:00
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-07-15 22:55:28 +02:00
|
|
|
void
|
|
|
|
Insert (const std::string & text, std::shared_ptr<struct TexText> texText)
|
2022-07-15 17:57:14 +02:00
|
|
|
{
|
2022-07-15 22:55:28 +02:00
|
|
|
this->list.insert (
|
|
|
|
std::pair<std::string, std::shared_ptr<struct TexText>> (text, texText));
|
2022-07-15 17:57:14 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-07-09 00:15:53 +02:00
|
|
|
class Font
|
2017-01-21 17:27:46 +01:00
|
|
|
{
|
2022-07-09 00:15:53 +02:00
|
|
|
TTF_Font * font;
|
|
|
|
SDL_Color color;
|
|
|
|
SDL_bool outline;
|
2022-07-15 17:57:14 +02:00
|
|
|
Cache cache;
|
2022-07-09 00:15:53 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
Font (
|
|
|
|
const char * name, int size, SDL_Color color, SDL_bool bold,
|
|
|
|
SDL_bool outline, SDL_bool rtl = SDL_FALSE)
|
2017-08-04 00:21:47 +02:00
|
|
|
{
|
2022-07-09 00:15:53 +02:00
|
|
|
this->font = TTF_OpenFont (name, size);
|
|
|
|
this->color = color;
|
|
|
|
this->outline = outline;
|
|
|
|
|
|
|
|
TTF_SetFontHinting (this->font, TTF_HINTING_NORMAL);
|
|
|
|
if (bold)
|
|
|
|
TTF_SetFontStyle (this->font, TTF_STYLE_BOLD);
|
|
|
|
|
|
|
|
if (rtl)
|
2022-07-10 23:14:53 +02:00
|
|
|
TTF_SetFontDirection (this->font, TTF_DIRECTION_RTL);
|
2017-08-04 00:21:47 +02:00
|
|
|
}
|
2017-09-29 16:25:12 +02:00
|
|
|
|
2022-07-09 00:15:53 +02:00
|
|
|
~Font () { TTF_CloseFont (this->font); }
|
2017-09-29 16:25:12 +02:00
|
|
|
|
2022-07-09 00:15:53 +02:00
|
|
|
TTF_Font * GetFont () { return this->font; }
|
2017-02-12 13:14:22 +01:00
|
|
|
|
2022-07-09 00:15:53 +02:00
|
|
|
void Draw (CPixmap * pPixmap, Point pos, const char * pText, Sint32 slope)
|
|
|
|
{
|
2022-07-15 22:55:38 +02:00
|
|
|
Uint32 format;
|
2022-07-15 18:06:41 +02:00
|
|
|
int access;
|
2022-07-15 17:57:14 +02:00
|
|
|
SDL_Rect r0;
|
2017-01-21 17:27:46 +01:00
|
|
|
|
2022-07-09 00:15:53 +02:00
|
|
|
const auto isRTL = IsRightReading ();
|
|
|
|
const auto angle = isRTL ? -2.5 : 2.5;
|
|
|
|
|
2022-07-15 17:57:14 +02:00
|
|
|
auto texText = this->cache.Get (pText);
|
|
|
|
|
|
|
|
SDL_Texture * texOutline = texText ? texText->outline : nullptr;
|
|
|
|
SDL_Texture * texBase = texText ? texText->base : nullptr;
|
|
|
|
SDL_Texture * texOver = texText ? texText->over : nullptr;
|
|
|
|
|
2022-07-09 00:15:53 +02:00
|
|
|
if (this->outline)
|
|
|
|
{
|
|
|
|
TTF_SetFontOutline (this->font, 1);
|
|
|
|
|
2022-07-15 17:57:14 +02:00
|
|
|
if (!texOutline)
|
|
|
|
{
|
|
|
|
SDL_Surface * text =
|
|
|
|
TTF_RenderUTF8_Solid (this->font, pText, {0x00, 0x00, 0x00, 0});
|
|
|
|
texOutline = SDL_CreateTextureFromSurface (g_renderer, text);
|
|
|
|
SDL_FreeSurface (text);
|
|
|
|
}
|
|
|
|
|
2022-07-15 22:55:38 +02:00
|
|
|
SDL_QueryTexture (texOutline, &format, &access, &r0.w, &r0.h);
|
2022-07-09 00:15:53 +02:00
|
|
|
r0.x = pos.x;
|
|
|
|
r0.y = pos.y;
|
|
|
|
|
|
|
|
if (isRTL)
|
2022-07-15 17:57:14 +02:00
|
|
|
r0.x -= r0.w;
|
2022-07-09 00:15:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TTF_SetFontOutline (this->font, 0);
|
|
|
|
|
2022-07-15 17:57:14 +02:00
|
|
|
if (!texBase)
|
|
|
|
{
|
|
|
|
SDL_Surface * text =
|
|
|
|
TTF_RenderUTF8_Blended (this->font, pText, this->color);
|
|
|
|
texBase = SDL_CreateTextureFromSurface (g_renderer, text);
|
|
|
|
SDL_FreeSurface (text);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!texOver)
|
|
|
|
{
|
|
|
|
this->color.a = 64;
|
|
|
|
SDL_Surface * text =
|
|
|
|
TTF_RenderUTF8_Blended (this->font, pText, this->color);
|
|
|
|
texOver = SDL_CreateTextureFromSurface (g_renderer, text);
|
|
|
|
SDL_FreeSurface (text);
|
|
|
|
this->color.a = 0;
|
|
|
|
}
|
|
|
|
|
2022-07-09 00:15:53 +02:00
|
|
|
SDL_Rect r;
|
2022-07-15 22:55:38 +02:00
|
|
|
SDL_QueryTexture (texBase, &format, &access, &r.w, &r.h);
|
2022-07-09 00:15:53 +02:00
|
|
|
r.x = pos.x + (isRTL ? -1 : 1);
|
|
|
|
r.y = pos.y + 1;
|
|
|
|
|
|
|
|
if (isRTL)
|
2022-07-15 17:57:14 +02:00
|
|
|
r.x -= r.w;
|
2022-07-09 00:15:53 +02:00
|
|
|
|
2022-07-15 17:57:14 +02:00
|
|
|
if (this->outline)
|
|
|
|
pPixmap->Blit (-1, texOutline, r0, slope ? angle : 0, SDL_FLIP_NONE);
|
2022-07-09 00:15:53 +02:00
|
|
|
|
2022-07-15 17:57:14 +02:00
|
|
|
pPixmap->Blit (-1, texBase, r, slope ? angle : 0, SDL_FLIP_NONE);
|
|
|
|
pPixmap->Blit (-1, texOver, r, slope ? angle : 0, SDL_FLIP_NONE);
|
2022-07-09 00:15:53 +02:00
|
|
|
|
2022-07-15 17:57:14 +02:00
|
|
|
if (!texText)
|
2022-07-09 00:15:53 +02:00
|
|
|
{
|
2022-07-15 22:55:28 +02:00
|
|
|
std::shared_ptr<struct TexText> _texText =
|
|
|
|
std::make_shared<struct TexText> (texOutline, texBase, texOver);
|
2022-07-15 17:57:14 +02:00
|
|
|
this->cache.Insert (pText, _texText);
|
2022-07-09 00:15:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class Fonts
|
2017-01-21 17:27:46 +01:00
|
|
|
{
|
2022-07-09 00:15:53 +02:00
|
|
|
private:
|
|
|
|
Font * latinLittle;
|
|
|
|
Font * latinRed;
|
|
|
|
Font * latinSlim;
|
|
|
|
Font * latinWhite;
|
|
|
|
|
|
|
|
Font * hebrewLittle;
|
|
|
|
Font * hebrewRed;
|
|
|
|
Font * hebrewSlim;
|
|
|
|
Font * hebrewWhite;
|
|
|
|
|
2022-07-10 23:04:45 +02:00
|
|
|
Font * arabicLittle;
|
|
|
|
Font * arabicRed;
|
|
|
|
Font * arabicSlim;
|
|
|
|
Font * arabicWhite;
|
|
|
|
|
2022-07-09 00:15:53 +02:00
|
|
|
private:
|
|
|
|
Font * GetFont (Sint32 font)
|
|
|
|
{
|
2022-07-10 23:04:45 +02:00
|
|
|
if (GetLocale () == "he")
|
2022-07-09 00:15:53 +02:00
|
|
|
switch (font)
|
|
|
|
{
|
|
|
|
case FONTLITTLE:
|
|
|
|
return this->hebrewLittle;
|
|
|
|
case FONTRED:
|
|
|
|
return this->hebrewRed;
|
|
|
|
case FONTSLIM:
|
|
|
|
return this->hebrewSlim;
|
|
|
|
case FONTWHITE:
|
|
|
|
return this->hebrewWhite;
|
|
|
|
}
|
|
|
|
|
2022-07-10 23:04:45 +02:00
|
|
|
if (GetLocale () == "ar")
|
|
|
|
switch (font)
|
|
|
|
{
|
|
|
|
case FONTLITTLE:
|
|
|
|
return this->arabicLittle;
|
|
|
|
case FONTRED:
|
|
|
|
return this->arabicRed;
|
|
|
|
case FONTSLIM:
|
|
|
|
return this->arabicSlim;
|
|
|
|
case FONTWHITE:
|
|
|
|
return this->arabicWhite;
|
|
|
|
}
|
|
|
|
|
2022-07-09 00:15:53 +02:00
|
|
|
switch (font)
|
|
|
|
{
|
|
|
|
case FONTLITTLE:
|
|
|
|
return this->latinLittle;
|
|
|
|
case FONTRED:
|
|
|
|
return this->latinRed;
|
|
|
|
case FONTSLIM:
|
|
|
|
return this->latinSlim;
|
|
|
|
case FONTWHITE:
|
|
|
|
return this->latinWhite;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
Fonts ()
|
2017-08-04 00:21:47 +02:00
|
|
|
{
|
2022-07-09 00:15:53 +02:00
|
|
|
this->latinLittle = new Font (
|
|
|
|
"/home/schroeterm/devel/blupi/planetblupi-dev/ChakraPetch-Regular.ttf",
|
|
|
|
12, {0xFF, 0xFF, 0x00, 0}, SDL_FALSE, SDL_TRUE);
|
|
|
|
this->latinRed = new Font (
|
|
|
|
"/home/schroeterm/devel/blupi/planetblupi-dev/NovaSlim-Regular.ttf", 13,
|
|
|
|
{0xFF, 0x00, 0x00, 0}, SDL_TRUE, SDL_TRUE);
|
|
|
|
this->latinSlim = new Font (
|
|
|
|
"/home/schroeterm/devel/blupi/planetblupi-dev/NovaSlim-Regular.ttf", 12,
|
|
|
|
{0xB4, 0x17, 0x12, 0}, SDL_FALSE, SDL_FALSE);
|
|
|
|
this->latinWhite = new Font (
|
|
|
|
"/home/schroeterm/devel/blupi/planetblupi-dev/NovaSlim-Regular.ttf", 13,
|
|
|
|
{0xFF, 0xFF, 0xFF, 0}, SDL_TRUE, SDL_TRUE);
|
|
|
|
|
|
|
|
this->hebrewLittle = new Font (
|
2022-07-10 23:14:53 +02:00
|
|
|
"/home/schroeterm/devel/blupi/planetblupi-dev/"
|
|
|
|
"IBMPlexSansHebrew-Regular.ttf",
|
2022-07-09 00:15:53 +02:00
|
|
|
12, {0xFF, 0xFF, 0x00, 0}, SDL_FALSE, SDL_TRUE, SDL_TRUE);
|
2022-07-10 23:14:53 +02:00
|
|
|
TTF_SetFontScriptName (this->hebrewLittle->GetFont (), "Hebr");
|
2022-07-09 00:15:53 +02:00
|
|
|
this->hebrewRed = new Font (
|
2022-07-10 23:14:53 +02:00
|
|
|
"/home/schroeterm/devel/blupi/planetblupi-dev/"
|
|
|
|
"IBMPlexSansHebrew-Regular.ttf",
|
|
|
|
13, {0xFF, 0x00, 0x00, 0}, SDL_TRUE, SDL_TRUE, SDL_TRUE);
|
|
|
|
TTF_SetFontScriptName (this->hebrewRed->GetFont (), "Hebr");
|
2022-07-09 00:15:53 +02:00
|
|
|
this->hebrewSlim = new Font (
|
2022-07-10 23:14:53 +02:00
|
|
|
"/home/schroeterm/devel/blupi/planetblupi-dev/"
|
|
|
|
"IBMPlexSansHebrew-Regular.ttf",
|
|
|
|
12, {0xB4, 0x17, 0x12, 0}, SDL_FALSE, SDL_FALSE, SDL_TRUE);
|
|
|
|
TTF_SetFontScriptName (this->hebrewSlim->GetFont (), "Hebr");
|
2022-07-09 00:15:53 +02:00
|
|
|
this->hebrewWhite = new Font (
|
2022-07-10 23:14:53 +02:00
|
|
|
"/home/schroeterm/devel/blupi/planetblupi-dev/"
|
|
|
|
"IBMPlexSansHebrew-Regular.ttf",
|
|
|
|
13, {0xFF, 0xFF, 0xFF, 0}, SDL_TRUE, SDL_TRUE, SDL_TRUE);
|
|
|
|
TTF_SetFontScriptName (this->hebrewWhite->GetFont (), "Hebr");
|
2022-07-10 23:04:45 +02:00
|
|
|
|
|
|
|
this->arabicLittle = new Font (
|
2022-07-10 23:14:53 +02:00
|
|
|
"/home/schroeterm/devel/blupi/planetblupi-dev/"
|
|
|
|
"IBMPlexSansArabic-Regular.ttf",
|
2022-07-10 23:04:45 +02:00
|
|
|
12, {0xFF, 0xFF, 0x00, 0}, SDL_FALSE, SDL_TRUE, SDL_TRUE);
|
2022-07-10 23:14:53 +02:00
|
|
|
TTF_SetFontScriptName (this->arabicLittle->GetFont (), "Arab");
|
2022-07-10 23:04:45 +02:00
|
|
|
this->arabicRed = new Font (
|
2022-07-10 23:14:53 +02:00
|
|
|
"/home/schroeterm/devel/blupi/planetblupi-dev/"
|
|
|
|
"IBMPlexSansArabic-Regular.ttf",
|
|
|
|
13, {0xFF, 0x00, 0x00, 0}, SDL_TRUE, SDL_TRUE, SDL_TRUE);
|
|
|
|
TTF_SetFontScriptName (this->arabicRed->GetFont (), "Arab");
|
2022-07-10 23:04:45 +02:00
|
|
|
this->arabicSlim = new Font (
|
2022-07-10 23:14:53 +02:00
|
|
|
"/home/schroeterm/devel/blupi/planetblupi-dev/"
|
|
|
|
"IBMPlexSansArabic-Regular.ttf",
|
|
|
|
12, {0xB4, 0x17, 0x12, 0}, SDL_FALSE, SDL_FALSE, SDL_TRUE);
|
|
|
|
TTF_SetFontScriptName (this->arabicSlim->GetFont (), "Arab");
|
2022-07-10 23:04:45 +02:00
|
|
|
this->arabicWhite = new Font (
|
2022-07-10 23:14:53 +02:00
|
|
|
"/home/schroeterm/devel/blupi/planetblupi-dev/"
|
|
|
|
"IBMPlexSansArabic-Regular.ttf",
|
|
|
|
13, {0xFF, 0xFF, 0xFF, 0}, SDL_TRUE, SDL_TRUE, SDL_TRUE);
|
|
|
|
TTF_SetFontScriptName (this->arabicWhite->GetFont (), "Arab");
|
2022-07-09 00:15:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
~Fonts ()
|
2017-08-04 00:21:47 +02:00
|
|
|
{
|
2022-07-09 00:15:53 +02:00
|
|
|
delete this->latinLittle;
|
|
|
|
delete this->latinRed;
|
|
|
|
delete this->latinSlim;
|
|
|
|
delete this->latinWhite;
|
|
|
|
|
|
|
|
delete this->hebrewLittle;
|
|
|
|
delete this->hebrewRed;
|
|
|
|
delete this->hebrewSlim;
|
|
|
|
delete this->hebrewWhite;
|
2022-07-10 23:04:45 +02:00
|
|
|
|
|
|
|
delete this->arabicLittle;
|
|
|
|
delete this->arabicRed;
|
|
|
|
delete this->arabicSlim;
|
|
|
|
delete this->arabicWhite;
|
2022-07-09 00:15:53 +02:00
|
|
|
}
|
2017-08-04 00:21:47 +02:00
|
|
|
|
2022-07-09 00:15:53 +02:00
|
|
|
Sint32 GetTextWidth (const char * pText, Sint32 font)
|
|
|
|
{
|
|
|
|
int w = 0, h = 0;
|
|
|
|
TTF_SizeUTF8 (this->GetFont (font)->GetFont (), pText, &w, &h);
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Draw (
|
|
|
|
CPixmap * pPixmap, Sint32 font, Point pos, const char * pText, Sint32 slope)
|
|
|
|
{
|
|
|
|
this->GetFont (font)->Draw (pPixmap, pos, pText, slope);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Fonts *
|
2022-07-15 23:02:00 +02:00
|
|
|
GetFonts ()
|
2022-07-09 00:15:53 +02:00
|
|
|
{
|
|
|
|
static Fonts fonts;
|
|
|
|
return &fonts;
|
2017-01-21 17:27:46 +01:00
|
|
|
}
|
|
|
|
|
2017-02-20 18:42:47 +01:00
|
|
|
/**
|
|
|
|
* \brief Draw a text in a pixmap to a specific position.
|
|
|
|
*
|
|
|
|
* \param[in] pPixmap - The pixmap where it must be drawn.
|
|
|
|
* \param[in] pos - The coordinates for the text.
|
|
|
|
* \param[in] pText - The text.
|
|
|
|
* \param[in] font - The font style (little or normal).
|
2019-02-05 22:51:48 +01:00
|
|
|
* \param[in] slope - Text slope.
|
2017-02-20 18:42:47 +01:00
|
|
|
*/
|
2017-08-14 22:10:26 +02:00
|
|
|
void
|
2019-02-05 22:51:48 +01:00
|
|
|
DrawText (
|
|
|
|
CPixmap * pPixmap, Point pos, const char * pText, Sint32 font, Sint32 slope)
|
2017-01-21 17:27:46 +01:00
|
|
|
{
|
2022-07-15 23:02:00 +02:00
|
|
|
GetFonts ()->Draw (pPixmap, font, pos, pText, slope);
|
2017-01-21 17:27:46 +01:00
|
|
|
}
|
|
|
|
|
2017-02-12 00:44:46 +01:00
|
|
|
// Affiche un pavé de texte.
|
|
|
|
// Une ligne vide est affichée avec un demi interligne !
|
2017-01-21 17:27:46 +01:00
|
|
|
// Si part != -1, n'affiche que les lignes qui commencent
|
|
|
|
// par "n|", avec n=part.
|
|
|
|
|
2017-08-14 22:10:26 +02:00
|
|
|
void
|
|
|
|
DrawTextRect (
|
2017-08-21 22:08:25 +02:00
|
|
|
CPixmap * pPixmap, Point pos, char * pText, Sint32 pente, Sint32 font,
|
2017-08-04 00:21:47 +02:00
|
|
|
Sint32 part)
|
2017-01-21 17:27:46 +01:00
|
|
|
{
|
2017-08-04 00:21:47 +02:00
|
|
|
char text[100];
|
|
|
|
char * pDest;
|
|
|
|
Sint32 itl;
|
|
|
|
|
|
|
|
if (font == FONTLITTLE)
|
2022-01-14 23:26:32 +01:00
|
|
|
itl = DIMLITTLEY - 2;
|
2017-08-04 00:21:47 +02:00
|
|
|
else
|
|
|
|
itl = DIMTEXTY;
|
|
|
|
|
|
|
|
while (*pText != 0)
|
|
|
|
{
|
|
|
|
pDest = text;
|
|
|
|
while (*pText != 0 && *pText != '\r' && *pText != '\n')
|
|
|
|
*pDest++ = *pText++;
|
|
|
|
*pDest = 0;
|
|
|
|
if (*pText == '\r')
|
|
|
|
pText++; // saute '\r'
|
|
|
|
if (*pText == '\n')
|
|
|
|
pText++; // saute '\n'
|
|
|
|
|
|
|
|
pDest = text;
|
|
|
|
if (text[0] != 0 && text[1] == '|') // commence par "n|" ?
|
|
|
|
{
|
|
|
|
if (part != -1 && part != text[0] - '0')
|
|
|
|
continue;
|
|
|
|
pDest += 2; // saute "n|"
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (part != -1)
|
|
|
|
continue;
|
|
|
|
}
|
2017-02-12 13:14:22 +01:00
|
|
|
|
2019-02-05 22:51:48 +01:00
|
|
|
DrawText (pPixmap, pos, pDest, font, pente);
|
2017-02-12 13:14:22 +01:00
|
|
|
|
2017-08-04 00:21:47 +02:00
|
|
|
if (pDest[0] == 0) // ligne vide ?
|
|
|
|
{
|
|
|
|
pos.y += itl / 2; // descend de 1/2 ligne
|
|
|
|
}
|
|
|
|
else
|
2017-02-12 13:14:22 +01:00
|
|
|
{
|
2017-08-04 00:21:47 +02:00
|
|
|
pos.y += itl; // passe à la ligne suivante
|
2017-02-12 13:14:22 +01:00
|
|
|
}
|
2017-08-04 00:21:47 +02:00
|
|
|
}
|
2017-01-21 17:27:46 +01:00
|
|
|
}
|
|
|
|
|
2017-02-12 00:44:46 +01:00
|
|
|
// Affiche un texte centré pouvant éventuellement
|
|
|
|
// contenir plusieurs lignes séparées par des '\n'.
|
2017-01-21 17:27:46 +01:00
|
|
|
|
2017-08-14 22:10:26 +02:00
|
|
|
void
|
2017-08-21 22:08:25 +02:00
|
|
|
DrawTextCenter (CPixmap * pPixmap, Point pos, const char * pText, Sint32 font)
|
2017-01-21 17:27:46 +01:00
|
|
|
{
|
2017-08-04 00:21:47 +02:00
|
|
|
char text[100];
|
|
|
|
char * pDest;
|
|
|
|
Sint32 itl;
|
2017-08-21 22:08:25 +02:00
|
|
|
Point start;
|
2019-02-09 22:37:49 +01:00
|
|
|
auto isRightReading = IsRightReading ();
|
2017-08-04 00:21:47 +02:00
|
|
|
|
|
|
|
if (font == FONTLITTLE)
|
2022-01-14 23:26:32 +01:00
|
|
|
itl = DIMLITTLEY - 2;
|
2017-08-04 00:21:47 +02:00
|
|
|
else
|
|
|
|
itl = DIMTEXTY;
|
|
|
|
|
|
|
|
while (*pText != 0)
|
|
|
|
{
|
|
|
|
pDest = text;
|
|
|
|
while (*pText != 0 && *pText != '\r' && *pText != '\n')
|
|
|
|
*pDest++ = *pText++;
|
|
|
|
*pDest = 0;
|
|
|
|
if (*pText == '\r')
|
|
|
|
pText++; // saute '\r'
|
|
|
|
if (*pText == '\n')
|
|
|
|
pText++; // saute '\n'
|
|
|
|
|
2019-01-29 23:48:13 +01:00
|
|
|
pDest = text;
|
|
|
|
start.x =
|
|
|
|
pos.x +
|
2019-02-09 22:37:49 +01:00
|
|
|
(isRightReading ? GetTextWidth (pDest) : -GetTextWidth (pDest)) / 2;
|
2017-08-04 00:21:47 +02:00
|
|
|
start.y = pos.y;
|
|
|
|
DrawText (pPixmap, start, pDest, font);
|
|
|
|
|
|
|
|
if (pDest[0] == 0) // ligne vide ?
|
|
|
|
{
|
|
|
|
pos.y += itl / 2; // descend de 1/2 ligne
|
|
|
|
}
|
2017-02-12 13:14:22 +01:00
|
|
|
else
|
|
|
|
{
|
2017-08-04 00:21:47 +02:00
|
|
|
pos.y += itl; // passe à la ligne suivante
|
2017-02-12 13:14:22 +01:00
|
|
|
}
|
2017-08-04 00:21:47 +02:00
|
|
|
}
|
2017-01-21 17:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Retourne la hauteur d'un texte.
|
|
|
|
|
2017-08-14 22:10:26 +02:00
|
|
|
Sint32
|
|
|
|
GetTextHeight (char * pText, Sint32 font, Sint32 part)
|
2017-01-21 17:27:46 +01:00
|
|
|
{
|
2017-08-04 00:21:47 +02:00
|
|
|
char text[100];
|
|
|
|
char * pDest;
|
|
|
|
Sint32 itl;
|
|
|
|
Sint32 h = 0;
|
|
|
|
|
|
|
|
if (font == FONTLITTLE)
|
2022-01-14 23:26:32 +01:00
|
|
|
itl = DIMLITTLEY - 2;
|
2017-08-04 00:21:47 +02:00
|
|
|
else
|
|
|
|
itl = DIMTEXTY;
|
|
|
|
|
|
|
|
while (*pText != 0)
|
|
|
|
{
|
|
|
|
pDest = text;
|
|
|
|
while (*pText != 0 && *pText != '\r' && *pText != '\n')
|
|
|
|
*pDest++ = *pText++;
|
|
|
|
*pDest = 0;
|
|
|
|
if (*pText == '\r')
|
|
|
|
pText++; // saute '\r'
|
|
|
|
if (*pText == '\n')
|
|
|
|
pText++; // saute '\n'
|
|
|
|
|
|
|
|
pDest = text;
|
|
|
|
if (text[0] != 0 && text[1] == '|') // commence par "n|" ?
|
|
|
|
{
|
|
|
|
if (part != -1 && part != text[0] - '0')
|
|
|
|
continue;
|
|
|
|
pDest += 2; // saute "n|"
|
|
|
|
}
|
2017-02-12 13:14:22 +01:00
|
|
|
else
|
2017-08-04 00:21:47 +02:00
|
|
|
{
|
|
|
|
if (part != -1)
|
|
|
|
continue;
|
|
|
|
}
|
2017-02-12 13:14:22 +01:00
|
|
|
|
2017-08-04 00:21:47 +02:00
|
|
|
if (pDest[0] == 0) // ligne vide ?
|
|
|
|
{
|
|
|
|
h += itl / 2; // descend de 1/2 ligne
|
|
|
|
}
|
|
|
|
else
|
2017-02-12 13:14:22 +01:00
|
|
|
{
|
2017-08-04 00:21:47 +02:00
|
|
|
h += itl; // passe à la ligne suivante
|
2017-02-12 13:14:22 +01:00
|
|
|
}
|
2017-08-04 00:21:47 +02:00
|
|
|
}
|
2017-02-12 13:14:22 +01:00
|
|
|
|
2017-08-04 00:21:47 +02:00
|
|
|
return h;
|
2017-01-21 17:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Retourne la longueur d'un texte.
|
|
|
|
|
2017-08-14 22:10:26 +02:00
|
|
|
Sint32
|
|
|
|
GetTextWidth (const char * pText, Sint32 font)
|
2017-01-21 17:27:46 +01:00
|
|
|
{
|
2022-07-15 23:02:00 +02:00
|
|
|
return GetFonts ()->GetTextWidth (pText, font);
|
2017-01-21 17:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Retourne la longueur d'un grand chiffre.
|
|
|
|
|
2017-08-14 22:10:26 +02:00
|
|
|
void
|
|
|
|
GetBignumInfo (Sint32 num, Sint32 & start, Sint32 & lg)
|
2017-01-21 17:27:46 +01:00
|
|
|
{
|
2017-08-04 00:21:47 +02:00
|
|
|
static Sint32 table[11] = {0, 53, 87, 133, 164, 217, 253, 297, 340, 382, 426};
|
2017-01-21 17:27:46 +01:00
|
|
|
|
2017-08-04 00:21:47 +02:00
|
|
|
start = table[num];
|
|
|
|
lg = table[num + 1] - table[num];
|
2017-01-21 17:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Affiche un grand nombre.
|
|
|
|
|
2017-08-14 22:10:26 +02:00
|
|
|
void
|
2017-08-21 22:08:25 +02:00
|
|
|
DrawBignum (CPixmap * pPixmap, Point pos, Sint32 num)
|
2017-01-21 17:27:46 +01:00
|
|
|
{
|
2017-08-04 00:21:47 +02:00
|
|
|
char string[10];
|
|
|
|
Sint32 i = 0;
|
|
|
|
Sint32 start, lg;
|
2017-08-21 22:08:25 +02:00
|
|
|
Rect rect;
|
2017-08-04 00:21:47 +02:00
|
|
|
|
2017-08-13 17:15:09 +02:00
|
|
|
snprintf (string, sizeof (string), "%d", num);
|
2017-08-04 00:21:47 +02:00
|
|
|
|
|
|
|
rect.top = 0;
|
|
|
|
rect.bottom = 52;
|
|
|
|
while (string[i] != 0)
|
|
|
|
{
|
|
|
|
GetBignumInfo (string[i] - '0', start, lg);
|
|
|
|
|
|
|
|
rect.left = start;
|
|
|
|
rect.right = start + lg;
|
|
|
|
pPixmap->DrawPart (-1, CHBIGNUM, pos, rect);
|
|
|
|
pos.x += lg + 4;
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
2017-01-21 17:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Retourne la longueur d'un grand nombre.
|
|
|
|
|
2017-08-14 22:10:26 +02:00
|
|
|
Sint32
|
|
|
|
GetBignumWidth (Sint32 num)
|
2017-01-21 17:27:46 +01:00
|
|
|
{
|
2017-08-04 00:21:47 +02:00
|
|
|
char string[10];
|
|
|
|
Sint32 i = 0;
|
|
|
|
Sint32 start, lg;
|
|
|
|
Sint32 width = -4;
|
2017-01-21 17:27:46 +01:00
|
|
|
|
2017-08-13 17:15:09 +02:00
|
|
|
snprintf (string, sizeof (string), "%d", num);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
2017-08-04 00:21:47 +02:00
|
|
|
while (string[i] != 0)
|
|
|
|
{
|
|
|
|
GetBignumInfo (string[i] - '0', start, lg);
|
|
|
|
width += lg + 4;
|
|
|
|
i++;
|
|
|
|
}
|
2017-01-21 17:27:46 +01:00
|
|
|
|
2017-08-04 00:21:47 +02:00
|
|
|
return width;
|
2017-01-21 17:27:46 +01:00
|
|
|
}
|