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-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;
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
int w0, h0;
|
|
|
|
SDL_Rect r0;
|
|
|
|
SDL_Texture * tex0;
|
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;
|
|
|
|
|
|
|
|
if (this->outline)
|
|
|
|
{
|
|
|
|
TTF_SetFontOutline (this->font, 1);
|
|
|
|
SDL_Surface * text =
|
|
|
|
TTF_RenderUTF8_Solid (this->font, pText, {0x00, 0x00, 0x00, 0});
|
|
|
|
tex0 = SDL_CreateTextureFromSurface (g_renderer, text);
|
|
|
|
SDL_FreeSurface (text);
|
|
|
|
|
|
|
|
TTF_SizeUTF8 (this->font, pText, &w0, &h0);
|
|
|
|
r0.x = pos.x;
|
|
|
|
r0.y = pos.y;
|
|
|
|
r0.w = w0;
|
|
|
|
r0.h = h0;
|
|
|
|
|
|
|
|
if (isRTL)
|
|
|
|
r0.x -= w0;
|
|
|
|
}
|
|
|
|
|
|
|
|
TTF_SetFontOutline (this->font, 0);
|
|
|
|
SDL_Surface * text =
|
|
|
|
TTF_RenderUTF8_Blended (this->font, pText, this->color);
|
|
|
|
SDL_Texture * tex = SDL_CreateTextureFromSurface (g_renderer, text);
|
|
|
|
SDL_FreeSurface (text);
|
|
|
|
|
|
|
|
TTF_SetFontOutline (this->font, 0);
|
|
|
|
this->color.a = 64;
|
|
|
|
SDL_Surface * text2 =
|
|
|
|
TTF_RenderUTF8_Blended (this->font, pText, this->color);
|
|
|
|
SDL_Texture * tex2 = SDL_CreateTextureFromSurface (g_renderer, text2);
|
|
|
|
SDL_FreeSurface (text2);
|
|
|
|
this->color.a = 0;
|
|
|
|
|
|
|
|
int w, h;
|
|
|
|
TTF_SizeUTF8 (this->font, pText, &w, &h);
|
|
|
|
SDL_Rect r;
|
|
|
|
r.x = pos.x + (isRTL ? -1 : 1);
|
|
|
|
r.y = pos.y + 1;
|
|
|
|
r.w = w;
|
|
|
|
r.h = h;
|
|
|
|
|
|
|
|
if (isRTL)
|
|
|
|
r.x -= w;
|
|
|
|
|
|
|
|
int res;
|
|
|
|
SDL_Texture * target;
|
|
|
|
|
|
|
|
target = SDL_GetRenderTarget (g_renderer);
|
|
|
|
|
|
|
|
if (this->outline)
|
|
|
|
{
|
|
|
|
/* outline */
|
|
|
|
res = pPixmap->Blit (-1, tex0, r0, slope ? angle : 0, SDL_FLIP_NONE);
|
|
|
|
SDL_DestroyTexture (tex0);
|
|
|
|
}
|
|
|
|
|
|
|
|
res = pPixmap->Blit (-1, tex, r, slope ? angle : 0, SDL_FLIP_NONE);
|
|
|
|
SDL_DestroyTexture (tex);
|
|
|
|
|
|
|
|
res = pPixmap->Blit (-1, tex2, r, slope ? angle : 0, SDL_FLIP_NONE);
|
|
|
|
SDL_DestroyTexture (tex2);
|
|
|
|
|
|
|
|
SDL_SetRenderTarget (g_renderer, target);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
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 *
|
|
|
|
FontsInit ()
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2019-02-04 22:53:47 +01:00
|
|
|
Sint32 rank;
|
2019-02-17 14:13:24 +01:00
|
|
|
bool isLatin = false;
|
2019-02-04 22:53:47 +01:00
|
|
|
int numberSize = 0;
|
|
|
|
const char * it = nullptr;
|
|
|
|
int skip = 0;
|
2019-02-05 22:51:48 +01:00
|
|
|
Sint32 start = pos.y;
|
|
|
|
Sint32 rel = 0;
|
2017-02-12 13:14:22 +01:00
|
|
|
|
2022-06-24 23:23:07 +02:00
|
|
|
auto useD7 = strchr (pText, 0xD7) != nullptr ||
|
|
|
|
strchr (pText, 0xD8) != nullptr ||
|
|
|
|
strchr (pText, 0xD9) != nullptr;
|
2022-07-09 00:15:53 +02:00
|
|
|
auto length = strlen (pText);
|
|
|
|
|
2022-07-10 23:14:53 +02:00
|
|
|
// if (length >= 1 && !useD7 && IsRightReading ())
|
2022-07-09 00:15:53 +02:00
|
|
|
// pos.x -= GetTextWidth (pText, font);
|
|
|
|
|
|
|
|
FontsInit ()->Draw (pPixmap, font, pos, pText, slope);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
TTF_Font * _font;
|
|
|
|
SDL_bool outline;
|
|
|
|
SDL_Color black;
|
|
|
|
switch (font) {
|
|
|
|
case FONTLITTLE:
|
|
|
|
outline = SDL_TRUE;
|
|
|
|
black = { 0xFF, 0xFF, 0x00, 0 };
|
|
|
|
//_font = TTF_OpenFont("/usr/share/fonts/truetype/roboto/unhinted/RobotoTTF/Roboto-Regular.ttf", 10);
|
|
|
|
_font = TTF_OpenFont("/home/schroeterm/devel/blupi/planetblupi-dev/ChakraPetch-Regular.ttf", 12);
|
|
|
|
//_font = TTF_OpenFont("/home/schroeterm/devel/blupi/planetblupi-dev/Tomorrow-Regular.ttf", 11);
|
|
|
|
//_font = TTF_OpenFont("/home/schroeterm/devel/blupi/planetblupi-dev/NovaOval-Regular.ttf", 11);
|
|
|
|
break;
|
|
|
|
case FONTRED:
|
|
|
|
outline = SDL_TRUE;
|
|
|
|
black = { 0xFF, 0x00, 0x00, 0 };
|
|
|
|
_font = TTF_OpenFont("/home/schroeterm/devel/blupi/planetblupi-dev/NovaSlim-Regular.ttf", 13);
|
|
|
|
TTF_SetFontStyle(_font, TTF_STYLE_BOLD);
|
|
|
|
//_font = TTF_OpenFont("/usr/share/fonts/truetype/ubuntu/Ubuntu-B.ttf", 12);
|
|
|
|
break;
|
|
|
|
case FONTSLIM:
|
|
|
|
outline = SDL_FALSE;
|
|
|
|
black = { 0xB4, 0x17, 0x12, 0 };
|
|
|
|
_font = TTF_OpenFont("/home/schroeterm/devel/blupi/planetblupi-dev/NovaSlim-Regular.ttf", 12);
|
|
|
|
//TTF_SetFontStyle(_font, TTF_STYLE_BOLD);
|
|
|
|
//_font = TTF_OpenFont("/usr/share/fonts/truetype/ubuntu/Ubuntu-B.ttf", 12);
|
|
|
|
break;
|
|
|
|
case FONTWHITE:
|
|
|
|
outline = SDL_TRUE;
|
|
|
|
black = { 0xFF, 0xFF, 0xFF, 0 };
|
|
|
|
//_font = TTF_OpenFont("/usr/share/fonts/truetype/roboto/unhinted/RobotoTTF/Roboto-Bold.ttf", 12);
|
|
|
|
//_font = TTF_OpenFont("/usr/share/fonts/truetype/ubuntu/Ubuntu-B.ttf", 13);
|
|
|
|
_font = TTF_OpenFont("/home/schroeterm/devel/blupi/planetblupi-dev/NovaSlim-Regular.ttf", 13);
|
|
|
|
TTF_SetFontStyle(_font, TTF_STYLE_BOLD);
|
|
|
|
//TTF_SetFontSizeDPI(_font, 14, 64,64);
|
|
|
|
//TTF_SetFontKerning(_font, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
TTF_SetFontHinting(_font, TTF_HINTING_NORMAL);
|
|
|
|
|
|
|
|
int w0, h0;
|
|
|
|
SDL_Rect r0;
|
|
|
|
SDL_Texture * tex0;
|
|
|
|
|
|
|
|
if (outline)
|
|
|
|
{
|
|
|
|
TTF_SetFontOutline(_font, 1);
|
|
|
|
SDL_Surface * text = TTF_RenderUTF8_Solid(_font, pText, {0x00, 0x00, 0x00, 0});
|
|
|
|
tex0 = SDL_CreateTextureFromSurface(g_renderer, text);
|
|
|
|
SDL_FreeSurface(text);
|
|
|
|
|
2019-02-09 22:37:49 +01:00
|
|
|
|
2022-07-09 00:15:53 +02:00
|
|
|
TTF_SizeUTF8(_font, pText, &w0, &h0);
|
|
|
|
r0.x = pos.x;
|
|
|
|
r0.y = pos.y;
|
|
|
|
r0.w = w0;
|
|
|
|
r0.h = h0;
|
|
|
|
}
|
2019-02-09 22:37:49 +01:00
|
|
|
|
2022-07-09 00:15:53 +02:00
|
|
|
TTF_SetFontOutline(_font, 0);
|
|
|
|
SDL_Surface * text = TTF_RenderUTF8_Blended(_font, pText, black);
|
|
|
|
SDL_Texture * tex = SDL_CreateTextureFromSurface(g_renderer, text);
|
|
|
|
SDL_FreeSurface(text);
|
|
|
|
|
|
|
|
TTF_SetFontOutline(_font, 0);
|
|
|
|
black.a = 64;
|
|
|
|
SDL_Surface * text2 = TTF_RenderUTF8_Blended(_font, pText, black);
|
|
|
|
SDL_Texture * tex2 = SDL_CreateTextureFromSurface(g_renderer, text2);
|
|
|
|
SDL_FreeSurface(text2);
|
|
|
|
|
|
|
|
int w, h;
|
|
|
|
TTF_SizeUTF8(_font, pText, &w, &h);
|
|
|
|
SDL_Rect r;
|
|
|
|
r.x = pos.x + 1;
|
|
|
|
r.y = pos.y + 1;
|
|
|
|
r.w = w;
|
|
|
|
r.h = h;
|
|
|
|
|
|
|
|
TTF_CloseFont (_font);
|
|
|
|
|
|
|
|
int res;
|
|
|
|
SDL_Texture * target;
|
|
|
|
|
|
|
|
if (outline) {
|
|
|
|
/* outline */
|
|
|
|
target = SDL_GetRenderTarget (g_renderer);
|
|
|
|
SDL_SetRenderTarget (g_renderer, target);
|
|
|
|
//res = SDL_RenderCopy (g_renderer, tex0, nullptr, &r0);
|
|
|
|
SDL_Point pt = {0, 0};
|
|
|
|
if (slope)
|
|
|
|
res = SDL_RenderCopyEx(g_renderer, tex0, nullptr, &r0, 2.5, &pt, SDL_FLIP_NONE);
|
|
|
|
else
|
|
|
|
res = SDL_RenderCopy (g_renderer, tex0, nullptr, &r0);
|
|
|
|
//SDL_SetRenderTarget (g_renderer, target);
|
|
|
|
SDL_DestroyTexture(tex0);
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_Point pt = {0, 0};
|
|
|
|
|
|
|
|
target = SDL_GetRenderTarget (g_renderer);
|
|
|
|
SDL_SetRenderTarget (g_renderer, target);
|
|
|
|
//res = SDL_RenderCopy (g_renderer, tex, nullptr, &r);
|
|
|
|
if (slope)
|
|
|
|
res = SDL_RenderCopyEx(g_renderer, tex, nullptr, &r, 2.5, &pt, SDL_FLIP_NONE);
|
|
|
|
else
|
|
|
|
res = SDL_RenderCopy (g_renderer, tex, nullptr, &r);
|
|
|
|
//SDL_SetRenderTarget (g_renderer, target);
|
|
|
|
SDL_DestroyTexture(tex);
|
|
|
|
|
|
|
|
target = SDL_GetRenderTarget (g_renderer);
|
|
|
|
SDL_SetRenderTarget (g_renderer, target);
|
|
|
|
//res = SDL_RenderCopy (g_renderer, tex, nullptr, &r);
|
|
|
|
if (slope)
|
|
|
|
res = SDL_RenderCopyEx(g_renderer, tex2, nullptr, &r, 2.5, &pt, SDL_FLIP_NONE);
|
|
|
|
else
|
|
|
|
res = SDL_RenderCopy (g_renderer, tex2, nullptr, &r);
|
|
|
|
//SDL_SetRenderTarget (g_renderer, target);
|
|
|
|
SDL_DestroyTexture(tex2);
|
|
|
|
#endif // 0
|
|
|
|
|
|
|
|
#if 0
|
2019-02-04 22:53:47 +01:00
|
|
|
while (*pText != '\0' || skip)
|
2017-08-04 00:21:47 +02:00
|
|
|
{
|
2019-02-09 22:37:49 +01:00
|
|
|
if (isRightReading && numberSize == 0)
|
2019-02-04 22:53:47 +01:00
|
|
|
{
|
2022-01-14 23:26:40 +01:00
|
|
|
const auto test = [] (const char * text) -> bool {
|
2019-02-17 14:13:50 +01:00
|
|
|
return *text > ' ' && *text <= '~';
|
2019-02-15 21:58:28 +01:00
|
|
|
};
|
2019-02-17 14:13:24 +01:00
|
|
|
it = pText;
|
2019-02-15 21:58:28 +01:00
|
|
|
isLatin = test (pText);
|
|
|
|
if (isLatin)
|
2019-02-04 22:53:47 +01:00
|
|
|
{
|
2019-02-15 21:58:28 +01:00
|
|
|
while (test (pText))
|
2019-02-04 22:53:47 +01:00
|
|
|
++pText;
|
|
|
|
|
|
|
|
numberSize = pText - it;
|
|
|
|
skip = numberSize - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numberSize)
|
|
|
|
{
|
|
|
|
pText = it + numberSize - 1;
|
|
|
|
numberSize--;
|
|
|
|
}
|
|
|
|
|
2019-02-06 18:36:35 +01:00
|
|
|
rank = GetOffset (pText);
|
|
|
|
|
2019-02-09 22:37:49 +01:00
|
|
|
if (isRightReading)
|
2019-02-06 18:36:35 +01:00
|
|
|
{
|
|
|
|
if (rank == '(')
|
|
|
|
rank = ')';
|
|
|
|
else if (rank == ')')
|
|
|
|
rank = '(';
|
|
|
|
}
|
|
|
|
|
2019-01-25 17:30:22 +01:00
|
|
|
auto inc = rank > 127;
|
2019-02-05 22:51:48 +01:00
|
|
|
auto lg = GetCharWidth (pText, font);
|
2017-08-04 00:21:47 +02:00
|
|
|
|
2019-02-09 22:37:49 +01:00
|
|
|
if (isRightReading)
|
2019-02-05 22:51:48 +01:00
|
|
|
pos.x += -lg;
|
|
|
|
|
|
|
|
rel += lg;
|
|
|
|
if (slope)
|
|
|
|
pos.y = start + rel / slope;
|
2019-02-02 13:55:52 +01:00
|
|
|
|
2017-08-04 00:21:47 +02:00
|
|
|
if (font != FONTLITTLE)
|
2017-02-12 13:14:22 +01:00
|
|
|
{
|
2019-01-27 23:55:14 +01:00
|
|
|
rank += 256 * font;
|
2017-08-04 00:21:47 +02:00
|
|
|
pPixmap->DrawIcon (-1, CHTEXT, rank, pos);
|
2017-02-12 13:14:22 +01:00
|
|
|
}
|
2017-08-04 00:21:47 +02:00
|
|
|
else
|
|
|
|
pPixmap->DrawIcon (-1, CHLITTLE, rank, pos);
|
|
|
|
|
2019-02-09 22:37:49 +01:00
|
|
|
if (!isRightReading)
|
2019-02-05 22:51:48 +01:00
|
|
|
pos.x += lg;
|
2019-02-02 13:55:52 +01:00
|
|
|
|
2019-02-04 22:53:47 +01:00
|
|
|
if (!numberSize && skip > 0)
|
|
|
|
{
|
|
|
|
pText += skip;
|
|
|
|
skip = 0;
|
|
|
|
}
|
|
|
|
|
2019-02-02 13:55:52 +01:00
|
|
|
if (inc)
|
2019-01-29 23:41:54 +01:00
|
|
|
pText++;
|
2019-02-02 13:55:52 +01:00
|
|
|
pText++;
|
2017-08-04 00:21:47 +02:00
|
|
|
}
|
2022-07-09 00:15:53 +02:00
|
|
|
#endif // 0
|
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-09 00:15:53 +02:00
|
|
|
#if 0
|
2017-08-04 00:21:47 +02:00
|
|
|
while (*pText != 0)
|
|
|
|
{
|
2019-01-25 17:30:22 +01:00
|
|
|
auto rank = GetOffset (pText);
|
|
|
|
auto inc = rank > 127;
|
|
|
|
|
2017-08-04 00:21:47 +02:00
|
|
|
width += GetCharWidth (pText, font);
|
2019-01-25 17:30:22 +01:00
|
|
|
|
|
|
|
if (inc)
|
|
|
|
pText++;
|
2017-08-04 00:21:47 +02:00
|
|
|
pText++;
|
|
|
|
}
|
2022-07-09 00:15:53 +02:00
|
|
|
#endif // 0
|
2017-01-21 17:27:46 +01:00
|
|
|
|
2022-07-09 00:15:53 +02:00
|
|
|
return FontsInit ()->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
|
|
|
}
|