From 839b9a45c38740598c6ea904c921a88db6c8b152 Mon Sep 17 00:00:00 2001 From: Jaby Date: Wed, 3 Jan 2024 22:44:13 -0600 Subject: [PATCH] Support exiting GPU Test --- .../PoolBox/application/include/shared.hpp | 6 +++ .../src/Overlay/GPUTest/gpu_test.cpp | 14 ++++++- .../PoolBox/application/src/application.cpp | 6 +++ .../PoolBox/application/src/include/menu.hpp | 18 +++++++++ examples/PoolBox/application/src/menu.cpp | 39 ++++++++++++++++++- 5 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 examples/PoolBox/application/include/shared.hpp diff --git a/examples/PoolBox/application/include/shared.hpp b/examples/PoolBox/application/include/shared.hpp new file mode 100644 index 00000000..49a22010 --- /dev/null +++ b/examples/PoolBox/application/include/shared.hpp @@ -0,0 +1,6 @@ +#pragma once +#include "../src/include/menu.hpp" + +namespace Shared { + extern Menu::BackMenu back_menu; +} \ No newline at end of file diff --git a/examples/PoolBox/application/src/Overlay/GPUTest/gpu_test.cpp b/examples/PoolBox/application/src/Overlay/GPUTest/gpu_test.cpp index b1ee5aa3..3c3c0949 100644 --- a/examples/PoolBox/application/src/Overlay/GPUTest/gpu_test.cpp +++ b/examples/PoolBox/application/src/Overlay/GPUTest/gpu_test.cpp @@ -1,6 +1,8 @@ +#include "../../../include/shared.hpp" #include "include/gpu_test_assets.hpp" #include #include +#include #include namespace GPUTest { @@ -118,8 +120,17 @@ namespace GPUTest { void main() { rect9.concat(rect10); + Shared::back_menu.reset(); while(true) { + // Update Phase + Periphery::query_controller(); + if(Shared::back_menu.update(Make::PositionI16(0, GPU::Display::Height - 32))) { + break; + } + + GPU::swap_buffers_vsync(2); + GPU::render(triangle1); GPU::render(triangle2); GPU::render(triangle3); @@ -147,8 +158,7 @@ namespace GPUTest { GPU::render(line4); GPU::render(rect9); - - GPU::swap_buffers_vsync(2); + Shared::back_menu.render(); } } } diff --git a/examples/PoolBox/application/src/application.cpp b/examples/PoolBox/application/src/application.cpp index 5f23b83d..0816884d 100644 --- a/examples/PoolBox/application/src/application.cpp +++ b/examples/PoolBox/application/src/application.cpp @@ -45,10 +45,16 @@ static Menu::SimpleMenu menu; static StateChange state_changer; static StateChange old_state_changer; +namespace Shared { + Menu::BackMenu back_menu; +} + static void setup() { Assets::Main::load(); FontWriter::setup(); paco.setup(); + Shared::back_menu.setup(&FontWriter::bios_font_writer); + menu.setup([](uint32_t selection) { switch(selection) { case 0: diff --git a/examples/PoolBox/application/src/include/menu.hpp b/examples/PoolBox/application/src/include/menu.hpp index 5965d64e..c48c6fa5 100644 --- a/examples/PoolBox/application/src/include/menu.hpp +++ b/examples/PoolBox/application/src/include/menu.hpp @@ -1,6 +1,7 @@ #pragma once #include "font_writer.hpp" #include +#include namespace Menu { using namespace JabyEngine; @@ -29,4 +30,21 @@ namespace Menu { void update(JabyEngine::FontWriter& font_writer, State& cursor, const GPU::PositionI16& start); }; + + class BackMenu { + private: + JabyEngine::FontWriter* font_writer; + SimpleTimer timeout; + bool waiting; + + public: + void setup(JabyEngine::FontWriter* font_writer); + void reset() { + this->timeout.reset(); + this->waiting = false; + } + + bool update(const GPU::PositionI16& position); + void render(); + }; } \ No newline at end of file diff --git a/examples/PoolBox/application/src/menu.cpp b/examples/PoolBox/application/src/menu.cpp index 8bbab7e1..e560dc5b 100644 --- a/examples/PoolBox/application/src/menu.cpp +++ b/examples/PoolBox/application/src/menu.cpp @@ -2,6 +2,8 @@ #include namespace Menu { + using DigitalButton = Periphery::GenericController::Button; + void SimpleMenu :: setup(Callback callback, const Entry* entries, size_t size) { this->selection_callback = callback; this->entries = entries; @@ -10,7 +12,6 @@ namespace Menu { } void SimpleMenu :: update(JabyEngine::FontWriter& font_writer, State& cursor, const GPU::PositionI16& start) { - using DigitalButton = Periphery::GenericController::Button; const auto& controller = Periphery::get_primary_controller_as(); if(controller.button.went_down(DigitalButton::Up) && this->cur_selection > 0) { @@ -38,4 +39,40 @@ namespace Menu { } } } + + void BackMenu :: setup(JabyEngine::FontWriter* font_writer) { + this->font_writer = font_writer; + this->timeout.reset(); + this->waiting = false; + } + + bool BackMenu :: update(const GPU::PositionI16& position) { + const auto& controller = Periphery::get_primary_controller_as(); + + if(controller.button.is_down(DigitalButton::Circle)) { + this->waiting = true; + if(this->timeout.is_expired_for(2500_ms)) { + return true; + } + } + + else { + this->waiting = false; + this->timeout.reset(); + } + + if(this->waiting) { + auto state = JabyEngine::State::create(position); + this->font_writer->write(state, "Press and hold ()\nto get back", GPU::Color24::Red()); + } + + else { + this->font_writer->clear(); + } + return false; + } + + void BackMenu :: render() { + this->font_writer->render(); + } } \ No newline at end of file