Support simple Menu
This commit is contained in:
36
examples/PoolBox/application/src/menu.cpp
Normal file
36
examples/PoolBox/application/src/menu.cpp
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user