Support exiting GPU Test
This commit is contained in:
parent
21efede7cb
commit
376cf02697
|
@ -0,0 +1,6 @@
|
|||
#pragma once
|
||||
#include "../src/include/menu.hpp"
|
||||
|
||||
namespace Shared {
|
||||
extern Menu::BackMenu back_menu;
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
#include "../../../include/shared.hpp"
|
||||
#include "include/gpu_test_assets.hpp"
|
||||
#include <PSX/GPU/gpu.hpp>
|
||||
#include <PSX/GPU/make_gpu_primitives.hpp>
|
||||
#include <PSX/Periphery/periphery.hpp>
|
||||
#include <stdio.h>
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
#include "font_writer.hpp"
|
||||
#include <FontWriter/font_writer.hpp>
|
||||
#include <PSX/Timer/frame_timer.hpp>
|
||||
|
||||
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<uint32_t> 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();
|
||||
};
|
||||
}
|
|
@ -2,6 +2,8 @@
|
|||
#include <PSX/Periphery/periphery.hpp>
|
||||
|
||||
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<JabyEngine::Periphery::GenericController>();
|
||||
|
||||
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<JabyEngine::Periphery::GenericController>();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue