diff options
Diffstat (limited to 'lib/nes/app/ui')
| -rw-r--r-- | lib/nes/app/ui/CMakeLists.txt | 7 | ||||
| -rw-r--r-- | lib/nes/app/ui/action.hh | 11 | ||||
| -rw-r--r-- | lib/nes/app/ui/screen-title.cc | 30 | ||||
| -rw-r--r-- | lib/nes/app/ui/screen-title.hh | 22 | ||||
| -rw-r--r-- | lib/nes/app/ui/screen.hh | 31 |
5 files changed, 101 insertions, 0 deletions
diff --git a/lib/nes/app/ui/CMakeLists.txt b/lib/nes/app/ui/CMakeLists.txt new file mode 100644 index 0000000..2faed29 --- /dev/null +++ b/lib/nes/app/ui/CMakeLists.txt @@ -0,0 +1,7 @@ +target_sources( + nes + PRIVATE + action.hh + screen.hh + screen-title.hh + screen-title.cc)
\ No newline at end of file diff --git a/lib/nes/app/ui/action.hh b/lib/nes/app/ui/action.hh new file mode 100644 index 0000000..2994f37 --- /dev/null +++ b/lib/nes/app/ui/action.hh @@ -0,0 +1,11 @@ +#pragma once + +namespace nes::app +{ + /// An action for the application to process after a scene has handled its events. + enum class action + { + none, + load_game, + }; +} // namespace nes::app
\ No newline at end of file diff --git a/lib/nes/app/ui/screen-title.cc b/lib/nes/app/ui/screen-title.cc new file mode 100644 index 0000000..2a7bc5c --- /dev/null +++ b/lib/nes/app/ui/screen-title.cc @@ -0,0 +1,30 @@ +#include "nes/app/ui/screen-title.hh" +#include "nes/app/graphics/renderer.hh" +#include "nes/app/graphics/color.hh" +#include "nes/app/graphics/mask-tile.hh" +#include "nes/app/input/input-manager.hh" + +namespace nes::app +{ + screen_title::screen_title(input_manager& input_manager) + : input_manager_{ input_manager } + { + } + + auto screen_title::render(renderer& renderer) -> void + { + renderer.render_fill(color::background_primary); + renderer.render_rect(2, 4, 28, 8, color::accent_primary); + renderer.render_mask_tile(10, 16, tiles::letter_a, color::foreground_primary); + } + + auto screen_title::process_events() -> action + { + if (input_manager_.get_keyboard().read_key_start()) + { + return action::load_game; + } + + return action::none; + } +} // namespace nes::app
\ No newline at end of file diff --git a/lib/nes/app/ui/screen-title.hh b/lib/nes/app/ui/screen-title.hh new file mode 100644 index 0000000..a8dfdc5 --- /dev/null +++ b/lib/nes/app/ui/screen-title.hh @@ -0,0 +1,22 @@ +#pragma once + +#include "nes/app/ui/screen.hh" + +namespace nes::app +{ + class input_manager; + + /// The main title screen for the emulator, used as an entrypoint for the UI. + /// + /// Presents options to load games, adjust settings, and more. + class screen_title final : public screen + { + input_manager& input_manager_; + + public: + explicit screen_title(input_manager&); + + auto render(renderer&) -> void override; + auto process_events() -> action override; + }; +} // namespace nes::app
\ No newline at end of file diff --git a/lib/nes/app/ui/screen.hh b/lib/nes/app/ui/screen.hh new file mode 100644 index 0000000..07e9d6f --- /dev/null +++ b/lib/nes/app/ui/screen.hh @@ -0,0 +1,31 @@ +#pragma once + +#include "nes/app/ui/action.hh" + +namespace nes::app +{ + class renderer; + + /// A part of the UI which takes care of rendering and handling input events. + /// + /// One screen may be shown at a time. It may be used as an overlay over an active game. + class screen + { + public: + virtual ~screen() = default; + + screen(screen const&) = delete; + screen(screen&&) = delete; + auto operator=(screen const&) -> screen& = delete; + auto operator=(screen&&) -> screen& = delete; + + /// Render a frame with the current UI state. + virtual auto render(renderer&) -> void = 0; + + /// Handle events and return an action for the application to execute. + virtual auto process_events() -> action = 0; + + protected: + explicit screen() = default; + }; +} // namespace nes::app
\ No newline at end of file |
