diff options
| author | Hannes Schulze <haschu0103@outlook.de> | 2025-02-06 16:28:39 +0100 |
|---|---|---|
| committer | Hannes Schulze <haschu0103@outlook.de> | 2025-02-06 16:28:39 +0100 |
| commit | 30b4364c772114303d9045677186a53855ea5343 (patch) | |
| tree | 3ac3443cdea7274e688bc633fa12bf1e089d6624 /lib/nes/app/graphics | |
| parent | 64308c9e520dbd8e72b675d0ba064ecdaf9bd494 (diff) | |
implement in-game popups
Diffstat (limited to 'lib/nes/app/graphics')
| -rw-r--r-- | lib/nes/app/graphics/renderer.cc | 54 | ||||
| -rw-r--r-- | lib/nes/app/graphics/renderer.hh | 4 | ||||
| -rw-r--r-- | lib/nes/app/graphics/tiles/CMakeLists.txt | 14 | ||||
| -rw-r--r-- | lib/nes/app/graphics/tiles/border_bottom.png | bin | 0 -> 139 bytes | |||
| -rw-r--r-- | lib/nes/app/graphics/tiles/border_bottom_left.png | bin | 0 -> 151 bytes | |||
| -rw-r--r-- | lib/nes/app/graphics/tiles/border_bottom_right.png | bin | 0 -> 148 bytes | |||
| -rw-r--r-- | lib/nes/app/graphics/tiles/border_left.png | bin | 0 -> 140 bytes | |||
| -rw-r--r-- | lib/nes/app/graphics/tiles/border_right.png | bin | 0 -> 139 bytes | |||
| -rw-r--r-- | lib/nes/app/graphics/tiles/border_top.png | bin | 0 -> 136 bytes | |||
| -rw-r--r-- | lib/nes/app/graphics/tiles/border_top_left.png | bin | 0 -> 146 bytes | |||
| -rw-r--r-- | lib/nes/app/graphics/tiles/border_top_right.png | bin | 0 -> 146 bytes |
11 files changed, 69 insertions, 3 deletions
diff --git a/lib/nes/app/graphics/renderer.cc b/lib/nes/app/graphics/renderer.cc index d512e71..564125b 100644 --- a/lib/nes/app/graphics/renderer.cc +++ b/lib/nes/app/graphics/renderer.cc @@ -5,6 +5,7 @@ #include "nes/app/graphics/image-view.hh" #include "nes/app/graphics/text-attributes.hh" #include "nes/app/graphics/tiles/characters.hh" +#include "nes/app/graphics/tiles/borders.hh" #include "nes/common/display.hh" namespace nes::app @@ -125,11 +126,9 @@ namespace nes::app } } - auto renderer::render_rect( - i32 const x, i32 const y, u32 const width, u32 const height, color const c) -> void + auto renderer::render_rect(i32 const x, i32 const y, u32 const width, u32 const height, color const c) -> void { if (c == color::transparent) { return; } - if (x >= static_cast<i32>(renderer::width) || y >= static_cast<i32>(renderer::height)) { return; } auto const resolved = resolve_color(c); auto const x_stop = std::min(x + static_cast<i32>(width), static_cast<i32>(renderer::width)); @@ -145,6 +144,55 @@ namespace nes::app } } + auto renderer::render_border(i32 const x, i32 const y, u32 const width, u32 const height, color const c) -> void + { + 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); + 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) + { + if (border_x == x_start && border_y == y_start) + { + render_mask_tile(border_x, border_y, tiles::border_top_left, c); + } + else if (border_x == x_last && border_y == y_start) + { + render_mask_tile(border_x, border_y, tiles::border_top_right, c); + } + else if (border_x == x_last && border_y == y_last) + { + render_mask_tile(border_x, border_y, tiles::border_bottom_right, c); + } + else if (border_x == x_start && border_y == y_last) + { + render_mask_tile(border_x, border_y, tiles::border_bottom_left, c); + } + else if (border_x == x_start) + { + render_mask_tile(border_x, border_y, tiles::border_left, c); + } + else if (border_x == x_last) + { + render_mask_tile(border_x, border_y, tiles::border_right, c); + } + else if (border_y == y_start) + { + render_mask_tile(border_x, border_y, tiles::border_top, c); + } + else if (border_y == y_last) + { + render_mask_tile(border_x, border_y, tiles::border_bottom, c); + } + } + } + } + + auto renderer::render_fill(color const c) -> void { render_rect(0, 0, width, height, c); diff --git a/lib/nes/app/graphics/renderer.hh b/lib/nes/app/graphics/renderer.hh index 9b764a6..83cafb3 100644 --- a/lib/nes/app/graphics/renderer.hh +++ b/lib/nes/app/graphics/renderer.hh @@ -37,6 +37,8 @@ namespace nes::app auto operator=(renderer const&) -> renderer& = delete; auto operator=(renderer&&) -> renderer& = delete; + auto get_display() const -> display& { return display_; } + /// Render a colored tile at the given tile coordinates. 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. @@ -66,6 +68,8 @@ namespace nes::app /// Render a rectangle at the given tile coordinates with a given size (measured in tiles). auto render_rect(i32 x, i32 y, u32 width, u32 height, color) -> void; + /// Render a border around a rectangle with the given size (measured in tiles). + auto render_border(i32 x, i32 y, u32 width, u32 height, color) -> void; /// Completely fill the screen. auto render_fill(color) -> void; diff --git a/lib/nes/app/graphics/tiles/CMakeLists.txt b/lib/nes/app/graphics/tiles/CMakeLists.txt index 144b9da..eced5ca 100644 --- a/lib/nes/app/graphics/tiles/CMakeLists.txt +++ b/lib/nes/app/graphics/tiles/CMakeLists.txt @@ -74,6 +74,20 @@ nes_generate_tiles( nes_generate_tiles( nes + borders + TYPE mask + FILES + border_top.png + border_top_left.png + border_top_right.png + border_left.png + border_right.png + border_bottom.png + border_bottom_left.png + border_bottom_right.png) + +nes_generate_tiles( + nes banner TYPE image FILES banner.png)
\ No newline at end of file diff --git a/lib/nes/app/graphics/tiles/border_bottom.png b/lib/nes/app/graphics/tiles/border_bottom.png Binary files differnew file mode 100644 index 0000000..05ac7a7 --- /dev/null +++ b/lib/nes/app/graphics/tiles/border_bottom.png diff --git a/lib/nes/app/graphics/tiles/border_bottom_left.png b/lib/nes/app/graphics/tiles/border_bottom_left.png Binary files differnew file mode 100644 index 0000000..974b1b1 --- /dev/null +++ b/lib/nes/app/graphics/tiles/border_bottom_left.png diff --git a/lib/nes/app/graphics/tiles/border_bottom_right.png b/lib/nes/app/graphics/tiles/border_bottom_right.png Binary files differnew file mode 100644 index 0000000..2fa6822 --- /dev/null +++ b/lib/nes/app/graphics/tiles/border_bottom_right.png diff --git a/lib/nes/app/graphics/tiles/border_left.png b/lib/nes/app/graphics/tiles/border_left.png Binary files differnew file mode 100644 index 0000000..ba5ecb6 --- /dev/null +++ b/lib/nes/app/graphics/tiles/border_left.png diff --git a/lib/nes/app/graphics/tiles/border_right.png b/lib/nes/app/graphics/tiles/border_right.png Binary files differnew file mode 100644 index 0000000..801bd7d --- /dev/null +++ b/lib/nes/app/graphics/tiles/border_right.png diff --git a/lib/nes/app/graphics/tiles/border_top.png b/lib/nes/app/graphics/tiles/border_top.png Binary files differnew file mode 100644 index 0000000..94d5cf5 --- /dev/null +++ b/lib/nes/app/graphics/tiles/border_top.png diff --git a/lib/nes/app/graphics/tiles/border_top_left.png b/lib/nes/app/graphics/tiles/border_top_left.png Binary files differnew file mode 100644 index 0000000..f67b585 --- /dev/null +++ b/lib/nes/app/graphics/tiles/border_top_left.png diff --git a/lib/nes/app/graphics/tiles/border_top_right.png b/lib/nes/app/graphics/tiles/border_top_right.png Binary files differnew file mode 100644 index 0000000..0b8613c --- /dev/null +++ b/lib/nes/app/graphics/tiles/border_top_right.png |
