diff options
| author | Hannes Schulze <haschu0103@outlook.de> | 2025-02-06 19:54:38 +0100 |
|---|---|---|
| committer | Hannes Schulze <haschu0103@outlook.de> | 2025-02-06 19:54:38 +0100 |
| commit | 64ebfde8bcd6408e3b6925624e8680c314db6efc (patch) | |
| tree | b969314f909f7f16ef5acc63f90dca317a40850a /lib/nes/app/graphics | |
| parent | d060e3a50c987d10799ccc739bdbf9d7d7a13c10 (diff) | |
get rid of nasty stdlib
Diffstat (limited to 'lib/nes/app/graphics')
| -rw-r--r-- | lib/nes/app/graphics/renderer.cc | 37 | ||||
| -rw-r--r-- | lib/nes/app/graphics/renderer.hh | 8 |
2 files changed, 23 insertions, 22 deletions
diff --git a/lib/nes/app/graphics/renderer.cc b/lib/nes/app/graphics/renderer.cc index 4f0d562..1745dd7 100644 --- a/lib/nes/app/graphics/renderer.cc +++ b/lib/nes/app/graphics/renderer.cc @@ -7,6 +7,7 @@ #include "nes/app/graphics/tiles/characters.hh" #include "nes/app/graphics/tiles/borders.hh" #include "nes/common/display.hh" +#include "nes/common/utils.hh" namespace nes::app { @@ -64,32 +65,32 @@ namespace nes::app } auto renderer::render_text( - i32 x, i32 const y, std::string_view const str, color const c, text_attributes const attributes) -> u32 + i32 x, i32 const y, string_view const str, color const c, text_attributes const attributes) -> u32 { // Enforce max length char buffer[width]; - auto const length = std::min(static_cast<u32>(str.length()), std::min(width, attributes.get_max_width())); - auto const ellipsize_dots = std::min(length, u32{ 3 }); + auto const length = min(str.get_length(), min(width, attributes.get_max_width())); + auto const ellipsize_dots = min(length, u32{ 3 }); // Enforce ellipsize mode - if (str.length() > length) + if (str.get_length() > length) { switch (attributes.get_ellipsize_mode()) { case ellipsize_mode::clip: { - std::copy_n(str.begin(), length, buffer); + copy(str.get_data(), buffer, length); break; } case ellipsize_mode::end: { - std::copy_n(str.begin(), length, buffer); + copy(str.get_data(), buffer, length); for (auto i = u32{ 0 }; i < ellipsize_dots; ++i) { buffer[length - 1 - i] = '.'; } break; } case ellipsize_mode::start: { - std::copy_n(str.begin() + str.length() - length, length, buffer); + copy(str.get_data() + str.get_length() - length, buffer, length); for (auto i = u32{ 0 }; i < ellipsize_dots; ++i) { buffer[i] = '.'; } break; } @@ -98,16 +99,16 @@ namespace nes::app auto const visible = length - ellipsize_dots; auto const start = visible / 2; auto const end = visible - start; - std::copy_n(str.begin(), start, buffer); + copy(str.get_data(), buffer, start); for (auto i = u32{ 0 }; i < ellipsize_dots; ++i) { buffer[start + i] = '.'; } - std::copy_n(str.begin() + str.length() - end, end, buffer + start + ellipsize_dots); + copy(str.get_data() + str.get_length() - end, buffer + start + ellipsize_dots, end); break; } } } else { - std::copy_n(str.begin(), length, buffer); + copy(str.get_data(), buffer, length); } // Enforce alignment @@ -132,10 +133,10 @@ namespace nes::app if (c == color::transparent) { return; } auto const resolved = resolve_color(c); - auto const x_stop = std::min(x + static_cast<i32>(width), static_cast<i32>(renderer::width)); - auto const y_stop = std::min(y + static_cast<i32>(height), static_cast<i32>(renderer::height)); - auto const x_start = std::max(x, 0); - auto const y_start = std::max(y, 0); + auto const x_stop = min(x + static_cast<i32>(width), static_cast<i32>(renderer::width)); + auto const y_stop = min(y + static_cast<i32>(height), static_cast<i32>(renderer::height)); + auto const x_start = max(x, 0); + auto const y_start = max(y, 0); for (auto y_px = i32{ y_start * 8 }; y_px < y_stop * 8; ++y_px) { for (auto x_px = i32{ x_start * 8 }; x_px < x_stop * 8; ++x_px) @@ -149,10 +150,10 @@ namespace nes::app { if (width <= 1 || height <= 1) { return; } - auto const x_last = std::min(x + static_cast<i32>(width), static_cast<i32>(renderer::width)) - 1; - auto const y_last = std::min(y + static_cast<i32>(height), static_cast<i32>(renderer::height)) - 1; - auto const x_start = std::max(x, 0); - auto const y_start = std::max(y, 0); + auto const x_last = min(x + static_cast<i32>(width), static_cast<i32>(renderer::width)) - 1; + auto const y_last = min(y + static_cast<i32>(height), static_cast<i32>(renderer::height)) - 1; + auto const x_start = max(x, 0); + auto const y_start = max(y, 0); for (auto border_y = i32{ y_start }; border_y <= y_last; ++border_y) { for (auto border_x = i32{ x_start }; border_x <= x_last; ++border_x) diff --git a/lib/nes/app/graphics/renderer.hh b/lib/nes/app/graphics/renderer.hh index 2e24ad3..50ca092 100644 --- a/lib/nes/app/graphics/renderer.hh +++ b/lib/nes/app/graphics/renderer.hh @@ -3,8 +3,8 @@ #include "nes/app/graphics/color.hh" #include "nes/app/graphics/text-attributes.hh" #include "nes/common/containers/string-builder.hh" +#include "nes/common/containers/string-view.hh" #include "nes/common/types.hh" -#include <string_view> namespace nes { @@ -46,11 +46,11 @@ namespace nes::app /// Render an image at the given tile coordinates. auto render_image(i32 x, i32 y, image_view) -> void; /// Render a string of text at the given tile coordinates (one tile per character). - auto render_text(i32 x, i32 y, std::string_view, color, text_attributes = text_attributes{}) -> u32; + auto render_text(i32 x, i32 y, string_view, color, text_attributes = text_attributes{}) -> u32; template<typename... Args> auto render_text_format( - i32 const x, i32 const y, color const c, text_attributes const attrs, std::string_view const fmt, + i32 const x, i32 const y, color const c, text_attributes const attrs, string_view const fmt, Args... args) -> u32 { string_buffer<width> buffer{}; @@ -60,7 +60,7 @@ namespace nes::app template<typename... Args> auto render_text_format( - i32 const x, i32 const y, color const c, std::string_view const fmt, Args... args) -> u32 + i32 const x, i32 const y, color const c, string_view const fmt, Args... args) -> u32 { return render_text_format(x, y, c, text_attributes{}, fmt, args...); } |
