Support simple Menu

This commit is contained in:
Jaby
2024-01-03 16:10:00 -06:00
committed by Jaby
parent c7255ece3c
commit 60f5582596
4 changed files with 83 additions and 3 deletions

View File

@@ -0,0 +1,36 @@
#include "include/menu.hpp"
#include <PSX/Periphery/periphery.hpp>
namespace Menu {
void SimpleMenu :: setup(const Entry* entries, size_t size) {
this->entries = entries;
this->size = size;
this->cur_selection = 0;
}
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) {
this->cur_selection -= 1;
}
if(controller.button.went_down(DigitalButton::Down) && this->cur_selection < (this->size - 1)) {
this->cur_selection += 1;
}
cursor.pos = Make::PositionI16(8, 64);
for(size_t n = 0; n < this->size; n++) {
const auto& cur_entry = this->entries[n];
if(this->cur_selection == n) {
FontWriter::bios_font_writer.write(cursor, ">%s<\n", cur_entry.name);
}
else {
FontWriter::bios_font_writer.write(cursor, "%s\n", cur_entry.name);
}
}
}
}