From 5e3a4e69cea488bed4e6c2ae17d7ea8d92c84666 Mon Sep 17 00:00:00 2001 From: Dav999-v Date: Sun, 5 Mar 2023 00:21:52 +0100 Subject: [PATCH] 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 --- desktop_version/src/Font.cpp | 19 ++++++++++++++++--- desktop_version/src/Font.h | 9 +++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/desktop_version/src/Font.cpp b/desktop_version/src/Font.cpp index 49c9df52..be52c49f 100644 --- a/desktop_version/src/Font.cpp +++ b/desktop_version/src/Font.cpp @@ -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, diff --git a/desktop_version/src/Font.h b/desktop_version/src/Font.h index b768796e..d4524183 100644 --- a/desktop_version/src/Font.h +++ b/desktop_version/src/Font.h @@ -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,