summaryrefslogtreecommitdiff
path: root/lib/nes/app/graphics/renderer.hh
diff options
context:
space:
mode:
authorHannes Schulze <haschu0103@outlook.de>2025-01-31 23:24:45 +0100
committerHannes Schulze <haschu0103@outlook.de>2025-01-31 23:24:45 +0100
commitcd8ae0e4f628bd491fcaf1dd4778bc283d619065 (patch)
treedea35210e2bfe21182cfec76511a84de9a23a2fa /lib/nes/app/graphics/renderer.hh
parent307e07d6513f9524b7fcab5134494bd175465cd1 (diff)
implement renderer
Diffstat (limited to 'lib/nes/app/graphics/renderer.hh')
-rw-r--r--lib/nes/app/graphics/renderer.hh62
1 files changed, 62 insertions, 0 deletions
diff --git a/lib/nes/app/graphics/renderer.hh b/lib/nes/app/graphics/renderer.hh
new file mode 100644
index 0000000..7b46461
--- /dev/null
+++ b/lib/nes/app/graphics/renderer.hh
@@ -0,0 +1,62 @@
+#pragma once
+
+#include <string_view>
+#include <cstdint>
+
+namespace nes
+{
+ class display;
+ class rgb;
+} // namespace nes
+
+namespace nes::app
+{
+ struct image_tile;
+ struct mask_tile;
+ class image_view;
+ enum class color : std::uint8_t;
+
+ /// Renders tiles and other primitive shapes onto a display.
+ ///
+ /// The renderer sees the display as a canvas divided into 8x8 tiles. All elements (except shadows and borders) must
+ /// be arranged on this 8x8 grid.
+ class renderer
+ {
+ display& display_;
+
+ public:
+ static constexpr auto width = unsigned{ 32 };
+ static constexpr auto height = unsigned{ 30 };
+
+ explicit renderer(display&);
+
+ renderer(renderer const&) = delete;
+ renderer(renderer&&) = delete;
+ auto operator=(renderer const&) -> renderer& = delete;
+ auto operator=(renderer&&) -> renderer& = delete;
+
+ /// If set, add a drop shadow behind newly drawn opaque elements.
+ auto set_shadow(unsigned x_px, unsigned y_px, color) -> void;
+ /// If set, add an inner border inside newly drawn opaque elements.
+ auto set_border(unsigned px, color) -> void;
+
+ /// Render a colored tile at the given tile coordinates.
+ auto render_image_tile(unsigned x, unsigned y, image_tile) -> void;
+ /// Render an alpha-only tile at the given tile coordinates with the given color.
+ auto render_mask_tile(unsigned x, unsigned y, mask_tile, color) -> void;
+ /// Render an image at the given tile coordinates.
+ auto render_image(unsigned x, unsigned y, image_view) -> void;
+ /// Render a string of text at the given tile coordinates (one tile per character).
+ auto render_text(unsigned x, unsigned 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(unsigned x, unsigned y, std::string_view, unsigned width, color) -> void;
+ /// Render a rectangle at the given tile coordinates with a given size (measured in tiles).
+ auto render_rect(unsigned x, unsigned y, unsigned width, unsigned height, color) -> void;
+ /// Completely fill the screen.
+ auto render_fill(color) -> void;
+
+ private:
+ auto resolve_color(color) const -> rgb;
+ };
+} // namespace nes::app \ No newline at end of file