Add localization "foundation" (many code changes)

This commit adds most of the code changes necessary for making the game
translatable, but does not yet "unhardcode" nearly all of the strings
(except in a few cases where it was hard to separate added
loc::gettexts from foundational code changes, or all the localization-
related menus which were also added by this commit.)

This commit is part of rewritten history of the localization branch.
The original (unsquashed) commit history can be found here:
https://github.com/Dav999-v/VVVVVV/tree/localization-orig
This commit is contained in:
Dav999-v
2022-12-30 22:57:24 +01:00
committed by Misa Elizabeth Kai
parent 35d92e8e64
commit ec611ffa9d
22 changed files with 1567 additions and 95 deletions

View File

@@ -1,5 +1,6 @@
#include "Textbox.h"
#include <SDL.h>
#include <utf8/unchecked.h>
textboxclass::textboxclass(void)
@@ -103,8 +104,9 @@ void textboxclass::resize(void)
if (len > (unsigned int)max) max = len;
}
w = (max +2) * 8;
h = (lines.size() + 2) * 8;
// 16 for the borders
w = max*8 + 16;
h = lines.size()*8 + 16;
}
void textboxclass::addline(const std::string& t)
@@ -113,3 +115,40 @@ void textboxclass::addline(const std::string& t)
resize();
if ((int) lines.size() >= 12) lines.clear();
}
void textboxclass::pad(size_t left_pad, size_t right_pad)
{
// Pad the current text with a certain number of spaces on the left and right
for (size_t iter = 0; iter < lines.size(); iter++)
{
lines[iter] = std::string(left_pad, ' ') + lines[iter] + std::string(right_pad, ' ');
}
resize();
}
void textboxclass::padtowidth(size_t new_w)
{
/* Pad the current text so that each line is new_w pixels wide.
* Each existing line is centered in that width. */
resize();
size_t chars_w = SDL_max(w-16, new_w) / 8;
for (size_t iter = 0; iter < lines.size(); iter++)
{
size_t n_glyphs = utf8::unchecked::distance(lines[iter].begin(), lines[iter].end());
signed int padding_needed = chars_w - n_glyphs;
if (padding_needed < 0)
{
continue;
}
size_t left_pad = padding_needed / 2;
size_t right_pad = padding_needed - left_pad;
lines[iter] = std::string(left_pad, ' ') + lines[iter] + std::string(right_pad, ' ');
}
resize();
}
void textboxclass::centertext()
{
padtowidth(w-16);
}