library: Fix '\n' in NF_WriteText16()

Also, slightly rework the code of NF_WriteText() to match the code sytle
of the rest of the library.
This commit is contained in:
Antonio Niño Díaz 2024-07-06 12:44:24 +01:00
parent 70fe30ef29
commit d892d6cc8a
2 changed files with 23 additions and 11 deletions

View File

@ -189,21 +189,25 @@ void NF_WriteText(int screen, u32 layer, u32 x, u32 y, const char *text)
for (u32 n = 0; n < tsize; n++) for (u32 n = 0; n < tsize; n++)
{ {
int value = 0; int value = 0;
if(text[n]==10) value = 10; // If newline found put the character to the newline --BG2CNT
else value = text[n] - 32; // Else, skip the first 32 non-printable characters --BG2CNT // If newline found, put the character to the newline. If not, skip the
// first 32 characters.
if (text[n] == '\n')
value = '\n';
else
value = text[n] - 32;
if (value < 0) if (value < 0)
value = 0; value = 0;
string[n] = value; string[n] = value;
// Handle special characters // Handle special characters (newline characters are special too)
if (string[n] > 95|| if ((string[n] > 95) || (string[n] == 10))
string[n]==10) //If the character is a newline, it's a special character --BG2CNT
{ {
switch (text[n]) switch (text[n])
{ {
case 10: // \n case '\n':
string[n] = 200; string[n] = 200;
break; break;

View File

@ -162,18 +162,26 @@ void NF_WriteText16(int screen, u32 layer, u32 x, u32 y, const char *text)
// Store the text string in the temporary buffer // Store the text string in the temporary buffer
for (u32 n = 0; n < tsize; n++) for (u32 n = 0; n < tsize; n++)
{ {
int value = text[n] - 32; // Skip the first 32 non-printable characters int value = 0;
// If newline found, put the character to the newline. If not, skip the
// first 32 characters.
if (text[n] == '\n')
value = '\n';
else
value = text[n] - 32;
if (value < 0) if (value < 0)
value = 0; value = 0;
string[n] = value; string[n] = value;
// Handle special characters // Handle special characters (newline characters are special too)
if (string[n] > 95) if ((string[n] > 95) || (string[n] == 10))
{ {
switch (text[n]) switch (text[n])
{ {
case 10: // \n case '\n':
string[n] = 200; string[n] = 200;
break; break;