Support simple Menu

This commit is contained in:
Jaby 2024-01-03 16:10:00 -06:00
parent a7096ac92c
commit 7674d4b55f
4 changed files with 83 additions and 3 deletions

View File

@ -1,34 +1,49 @@
#include "../include/asset_mgr.hpp"
#include "include/font_writer.hpp"
#include "include/menu.hpp"
#include "include/paco.hpp"
#include <FontWriter/fonts.hpp>
#include <FontWriter/font_writer.hpp>
#include <PSX/Periphery/periphery.hpp>
#include <stdio.h>
using namespace JabyEngine;
static const Menu::SimpleMenu::Entry MenuEntries[] = {
{"Menu 1"},
{"Menu 2"},
{"Menu 3"},
{"Menu 4"},
{"Menu 5"}
};
// Do we want this namespace?
// Do we want Paco to be HERE?!
static object::Paco paco;
static Menu::SimpleMenu menu;
static void setup() {
Assets::Main::load();
FontWriter::setup();
paco.setup();
menu.setup(MenuEntries);
}
static void update() {
static const char Title[] = "Pool Box";
static constexpr auto TitleLength = (sizeof(Title) - 1)*DefaultFont::Info.font_size.width;
Periphery::query_controller();
auto cursor = FontWriter::update(JabyEngine::Make::PositionI16((GPU::Display::Width-TitleLength)/2, 16));
paco.update();
FontWriter::new_font_writer.write(cursor, Title, GPU::Color24::Yellow(), &FontWriter::wiggle);
menu.update(FontWriter::bios_font_writer, cursor, Make::PositionI16(8, 64));
}
static void render() {
FontWriter::new_font_writer.render();
FontWriter::bios_font_writer.render();
paco.render();
}

View File

@ -0,0 +1,29 @@
#pragma once
#include "font_writer.hpp"
#include <FontWriter/font_writer.hpp>
namespace Menu {
using namespace JabyEngine;
class SimpleMenu {
public:
struct Entry {
const char* name;
};
private:
const Entry* entries;
size_t size;
uint8_t cur_selection;
public:
void setup(const Entry* entries, size_t size);
template<size_t N>
void setup(const Entry (&entries)[N]) {
SimpleMenu::setup(entries, N);
}
void update(JabyEngine::FontWriter& font_writer, State& cursor, const GPU::PositionI16& start);
};
}

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);
}
}
}
}