1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-22 17:49:43 +01:00

Overload font::print text argument for both std::string and const char*

Turns out I was overplaying my hand a little when changing font::print
from std::string to const char*, so instead, I'll overload the
function: it can take either a const char* (the main function) or a
std::string (a wrapper). This means any C string that's printed
everywhere else (which is common, especially because loc::gettext gives
them) no longer needs to be converted to a std::string object each call.

   Commit 1/3: font::print_wrap
-> Commit 2/3: font::print
   Commit 3/3: font::len
This commit is contained in:
Dav999-v 2023-03-05 00:21:52 +01:00 committed by Misa Elizabeth Kai
parent 264b6474be
commit 5e3a4e69ce
2 changed files with 25 additions and 3 deletions

View file

@ -1176,7 +1176,7 @@ void print(
const uint32_t flags,
int x,
int y,
const std::string& text,
const char* text,
const uint8_t r,
const uint8_t g,
const uint8_t b
@ -1239,9 +1239,8 @@ void print(
}
int position = 0;
const char* str = text.c_str(); // TODO no std::string
uint32_t codepoint;
while ((codepoint = UTF8_next(&str)))
while ((codepoint = UTF8_next(&text)))
{
position += font::print_char(
pf.font_sel,
@ -1257,6 +1256,20 @@ void print(
}
}
void print(
const uint32_t flags,
int x,
int y,
const std::string& text,
const uint8_t r,
const uint8_t g,
const uint8_t b
)
{
// Just a std::string overload for now because it's more .c_str() to add than I'm comfortable with...
print(flags, x, y, text.c_str(), r, g, b);
}
int print_wrap(
uint32_t flags,
const int x,

View file

@ -84,6 +84,15 @@ bool glyph_dimensions(uint32_t flags, uint8_t* glyph_w, uint8_t* glyph_h);
int len(uint32_t flags, const std::string& t);
int height(const uint32_t flags);
void print(
uint32_t flags,
int x,
int y,
const char* text,
uint8_t r, uint8_t g, uint8_t b
);
// std::string overload for only font::print (use .c_str() for the others)
void print(
uint32_t flags,
int x,