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
|
|
|
|
|
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"
|
|
|
|
|
|
2017-02-20 18:42:47 +01:00
|
|
|
|
/**
|
|
|
|
|
* \brief Return the character offset for the sprite.
|
|
|
|
|
*
|
2017-09-12 17:09:50 +02:00
|
|
|
|
* \param[in] c - The character (incremented if 0xC3 or 0xC4 or 0xC5 UTF-8).
|
2017-02-20 18:42:47 +01:00
|
|
|
|
* \returns the offset.
|
|
|
|
|
*/
|
2019-01-25 17:30:22 +01:00
|
|
|
|
static Uint8
|
2017-08-14 22:10:26 +02:00
|
|
|
|
GetOffset (const char *& c)
|
2017-01-21 17:27:46 +01:00
|
|
|
|
{
|
2017-09-29 16:25:12 +02:00
|
|
|
|
/* clang-format off */
|
2019-01-25 17:30:22 +01:00
|
|
|
|
static const unsigned char table_c3[] = {
|
|
|
|
|
/* ü à â é è ë ê ï */
|
|
|
|
|
0xBC, 0xA0, 0xA2, 0xA9, 0xA8, 0xAB, 0xAA, 0xAF,
|
|
|
|
|
/* î ô ù û ä ö ç ò */
|
|
|
|
|
0xAE, 0xB4, 0xB9, 0xBB, 0xA4, 0xB6, 0xA7, 0xB2,
|
|
|
|
|
/* ì ó Ç Ö Ü */
|
|
|
|
|
0xAC, 0xB3, 0x87, 0x96, 0x9C,
|
2017-08-04 00:21:47 +02:00
|
|
|
|
};
|
2017-02-12 13:14:22 +01:00
|
|
|
|
|
2019-01-25 17:30:22 +01:00
|
|
|
|
static const unsigned char table_c4[] = {
|
|
|
|
|
/* ę ć ą Ğ ğ İ ı */
|
|
|
|
|
0x99, 0x87, 0x85, 0x9E, 0x9F, 0xB0, 0xB1,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const unsigned char table_c5[] = {
|
|
|
|
|
/* ń ź ż ł ś Ş ş */
|
|
|
|
|
0x84, 0xBA, 0xBC, 0x82, 0x9B, 0x9E, 0x9F,
|
2017-09-29 16:25:12 +02:00
|
|
|
|
};
|
2019-01-27 23:55:14 +01:00
|
|
|
|
|
|
|
|
|
static const unsigned char table_d7[] = {
|
|
|
|
|
/*a ז ו ה ד ג ב א */
|
|
|
|
|
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96,
|
|
|
|
|
/*a מ ל ך כ י ט ח */
|
|
|
|
|
0x97, 0x98, 0x99, 0x9B, 0x9A, 0x9C, 0x9E,
|
|
|
|
|
/*a ף פ ע ס ן נ ם */
|
|
|
|
|
0x9D, 0xA0, 0x9F, 0xA1, 0xA2, 0xA4, 0xA3,
|
|
|
|
|
/*a ת ש ר ק ץ צ */
|
|
|
|
|
0xA6, 0xA5, 0xA7, 0xA8, 0xA9, 0xAA,
|
|
|
|
|
};
|
2017-09-29 16:25:12 +02:00
|
|
|
|
/* clang-format on */
|
|
|
|
|
|
2019-01-25 17:30:22 +01:00
|
|
|
|
int offset = 0;
|
|
|
|
|
int inc = 0;
|
|
|
|
|
size_t size = 0;
|
|
|
|
|
const unsigned char * table = nullptr;
|
2017-02-15 18:33:49 +01:00
|
|
|
|
|
2019-01-25 17:30:22 +01:00
|
|
|
|
switch (static_cast<unsigned char> (*c))
|
2017-08-04 00:21:47 +02:00
|
|
|
|
{
|
2019-01-25 17:30:22 +01:00
|
|
|
|
case 0xC3:
|
|
|
|
|
offset = 128;
|
|
|
|
|
table = table_c3;
|
|
|
|
|
size = countof (table_c3);
|
|
|
|
|
inc = 1;
|
|
|
|
|
break;
|
|
|
|
|
case 0xC4:
|
|
|
|
|
offset = 128 + 32;
|
|
|
|
|
table = table_c4;
|
|
|
|
|
size = countof (table_c4);
|
|
|
|
|
inc = 1;
|
|
|
|
|
break;
|
|
|
|
|
case 0xC5:
|
|
|
|
|
offset = 128 + 64;
|
|
|
|
|
table = table_c5;
|
|
|
|
|
size = countof (table_c5);
|
|
|
|
|
inc = 1;
|
|
|
|
|
break;
|
2019-01-27 23:55:14 +01:00
|
|
|
|
case 0xD7:
|
|
|
|
|
offset = 128 + 96;
|
|
|
|
|
table = table_d7;
|
|
|
|
|
size = countof (table_d7);
|
|
|
|
|
inc = 1;
|
|
|
|
|
break;
|
2017-08-04 00:21:47 +02:00
|
|
|
|
}
|
2017-09-29 16:25:12 +02:00
|
|
|
|
|
2019-01-25 17:30:22 +01:00
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
|
|
|
if (static_cast<unsigned char> (*(c + inc)) == table[i])
|
|
|
|
|
return offset + i;
|
2017-09-29 16:25:12 +02:00
|
|
|
|
|
2019-01-25 17:30:22 +01:00
|
|
|
|
if (*(c + inc) < 0)
|
2017-08-04 00:21:47 +02:00
|
|
|
|
return 1; // square
|
2017-02-12 13:14:22 +01:00
|
|
|
|
|
2019-01-25 17:30:22 +01:00
|
|
|
|
return *(c + inc);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-20 18:42:47 +01:00
|
|
|
|
/**
|
|
|
|
|
* \brief Return the character length.
|
|
|
|
|
*
|
|
|
|
|
* \param[in] c - The character (can be incremented).
|
|
|
|
|
* \param[in] font - The font used (little or normal).
|
|
|
|
|
* \returns the length.
|
|
|
|
|
*/
|
2019-01-25 17:30:22 +01:00
|
|
|
|
Uint8
|
2017-08-14 22:10:26 +02:00
|
|
|
|
GetCharWidth (const char *& c, Sint32 font)
|
2017-01-21 17:27:46 +01:00
|
|
|
|
{
|
2017-08-04 00:21:47 +02:00
|
|
|
|
// clang-format off
|
2019-01-25 17:30:22 +01:00
|
|
|
|
static const Uint8 table_width[] =
|
2017-08-04 00:21:47 +02:00
|
|
|
|
{
|
2019-01-25 17:30:22 +01:00
|
|
|
|
9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 0,
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10,
|
2017-08-04 00:21:47 +02:00
|
|
|
|
5, 6, 9, 13, 11, 12, 12, 6, 6, 6, 12, 12, 5, 9, 6, 9,
|
|
|
|
|
8, 8, 9, 9, 8, 9, 8, 8, 9, 9, 6, 6, 8, 9, 10, 11,
|
|
|
|
|
12, 8, 9, 9, 9, 8, 8, 8, 9, 4, 8, 9, 8, 10, 9, 9,
|
|
|
|
|
8, 9, 8, 9, 10, 8, 9, 11, 9, 8, 10, 7, 10, 7, 13, 13,
|
|
|
|
|
9, 9, 8, 8, 8, 8, 6, 8, 8, 4, 6, 8, 4, 12, 8, 8,
|
2019-01-25 17:30:22 +01:00
|
|
|
|
8, 8, 7, 6, 7, 8, 8, 10, 8, 8, 7, 6, 6, 6, 10, 0,
|
|
|
|
|
8, 9, 9, 8, 8, 8, 8, 5, 5, 8, 8, 8, 9, 8, 8, 8,
|
|
|
|
|
5, 8, 9, 9, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
|
8, 8, 9, 8, 8, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
|
8, 8, 7, 6, 7, 9, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
2019-02-07 00:30:16 +01:00
|
|
|
|
9, 9, 8, 8, 9, 5, 7, 9, 10, 6, 8, 8, 9, 10, 9, 6,
|
|
|
|
|
7, 9, 9, 8, 9, 9, 10, 9, 8, 12, 10, 0, 0, 0, 0, 0,
|
2017-08-04 00:21:47 +02:00
|
|
|
|
};
|
|
|
|
|
|
2019-01-25 17:30:22 +01:00
|
|
|
|
static const Uint8 table_width_little[] =
|
2017-08-04 00:21:47 +02:00
|
|
|
|
{
|
2019-01-25 17:30:22 +01:00
|
|
|
|
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 6, 6, 0,
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5,
|
2019-02-08 23:07:35 +01:00
|
|
|
|
3, 2, 5, 8, 5, 11, 9, 2, 4, 4, 6, 6, 2, 4, 2, 6,
|
|
|
|
|
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 2, 2, 7, 6, 7, 6,
|
2017-08-04 00:21:47 +02:00
|
|
|
|
9, 8, 6, 7, 7, 5, 5, 8, 7, 2, 4, 7, 5, 10, 7, 8,
|
|
|
|
|
6, 8, 7, 6, 6, 6, 8, 12, 7, 6, 6, 3, 5, 3, 6, 8,
|
|
|
|
|
4, 6, 6, 6, 6, 6, 4, 6, 6, 2, 3, 5, 2, 10, 6, 6,
|
2019-01-25 17:30:22 +01:00
|
|
|
|
6, 6, 3, 5, 3, 6, 6, 8, 6, 6, 5, 4, 6, 4, 7, 0,
|
|
|
|
|
7, 6, 6, 6, 6, 6, 6, 3, 3, 6, 6, 6, 6, 6, 6, 6,
|
|
|
|
|
3, 6, 7, 8, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
|
6, 5, 7, 8, 6, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
|
6, 5, 5, 4, 5, 6, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
2019-02-08 23:07:35 +01:00
|
|
|
|
7, 7, 5, 6, 7, 2, 4, 7, 7, 3, 5, 7, 6, 7, 7, 4,
|
|
|
|
|
3, 7, 7, 7, 8, 7, 6, 7, 7, 9, 8, 0, 0, 0, 0, 0,
|
2017-08-04 00:21:47 +02:00
|
|
|
|
};
|
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
|
|
if (font == FONTLITTLE)
|
|
|
|
|
return table_width_little[GetOffset (c)];
|
2019-01-25 17:30:22 +01:00
|
|
|
|
return table_width[GetOffset (c)] - 1;
|
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;
|
|
|
|
|
bool isNumber = false;
|
|
|
|
|
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
|
|
|
|
|
2019-02-04 22:53:47 +01:00
|
|
|
|
while (*pText != '\0' || skip)
|
2017-08-04 00:21:47 +02:00
|
|
|
|
{
|
2019-02-04 22:53:47 +01:00
|
|
|
|
if (IsRightReading () && numberSize == 0)
|
|
|
|
|
{
|
|
|
|
|
it = pText;
|
|
|
|
|
isNumber = *pText >= '0' && *pText <= '9';
|
|
|
|
|
if (isNumber)
|
|
|
|
|
{
|
|
|
|
|
while (*pText >= '0' && *pText <= '9')
|
|
|
|
|
++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);
|
|
|
|
|
|
|
|
|
|
if (IsRightReading ())
|
|
|
|
|
{
|
|
|
|
|
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-02 13:55:52 +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-02 13:55:52 +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
|
|
|
|
}
|
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)
|
|
|
|
|
itl = DIMLITTLEY;
|
|
|
|
|
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;
|
2017-08-04 00:21:47 +02:00
|
|
|
|
|
|
|
|
|
if (font == FONTLITTLE)
|
|
|
|
|
itl = DIMLITTLEY;
|
|
|
|
|
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 +
|
|
|
|
|
(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)
|
|
|
|
|
itl = DIMLITTLEY;
|
|
|
|
|
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
|
|
|
|
{
|
2017-08-04 00:21:47 +02:00
|
|
|
|
Sint32 width = 0;
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
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++;
|
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|