diff options
Diffstat (limited to 'lib/nes/app/graphics/renderer.hh')
| -rw-r--r-- | lib/nes/app/graphics/renderer.hh | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/lib/nes/app/graphics/renderer.hh b/lib/nes/app/graphics/renderer.hh index 08e4225..cc0b9af 100644 --- a/lib/nes/app/graphics/renderer.hh +++ b/lib/nes/app/graphics/renderer.hh @@ -1,6 +1,9 @@ #pragma once #include "nes/common/types.hh" +#include "nes/app/graphics/color.hh" +#include "nes/app/graphics/text-attributes.hh" +#include "nes/common/string-builder.hh" #include <string_view> namespace nes @@ -14,7 +17,6 @@ namespace nes::app struct image_tile; struct mask_tile; class image_view; - enum class color : u8; /// Renders tiles and other primitive shapes onto a display. /// @@ -41,18 +43,33 @@ namespace nes::app auto set_border(u32 px, color) -> void; /// Render a colored tile at the given tile coordinates. - auto render_image_tile(u32 x, u32 y, image_tile const&) -> void; + auto render_image_tile(i32 x, i32 y, image_tile const&) -> void; /// Render an alpha-only tile at the given tile coordinates with the given color. - auto render_mask_tile(u32 x, u32 y, mask_tile, color) -> void; + auto render_mask_tile(i32 x, i32 y, mask_tile, color) -> void; /// Render an image at the given tile coordinates. - auto render_image(u32 x, u32 y, image_view) -> void; + 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(u32 x, u32 y, std::string_view, color) -> void; - /// Render a string of text at the given tile coordinates, limiting its length to the given width and - /// ellipsizing afterward. - auto render_text(u32 x, u32 y, std::string_view, u32 width, color) -> void; + auto render_text(i32 x, i32 y, std::string_view, color, text_attributes = text_attributes{}) -> void; + + 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, + Args... args) -> void + { + char buffer[width]; + auto const str = string_builder{ buffer, sizeof(buffer) }.append_format(fmt, args...).get_result(); + render_text(x, y, str, c, attrs); + } + + template<typename... Args> + auto render_text_format( + i32 const x, i32 const y, color const c, std::string_view const fmt, Args... args) -> void + { + render_text_format(x, y, c, text_attributes{}, fmt, args...); + } + /// Render a rectangle at the given tile coordinates with a given size (measured in tiles). - auto render_rect(u32 x, u32 y, u32 width, u32 height, color) -> void; + auto render_rect(i32 x, i32 y, u32 width, u32 height, color) -> void; /// Completely fill the screen. auto render_fill(color) -> void; |
