Support simple Menu
This commit is contained in:
parent
aeb1cd57da
commit
f024cba8c2
|
@ -1,34 +1,49 @@
|
||||||
#include "../include/asset_mgr.hpp"
|
#include "../include/asset_mgr.hpp"
|
||||||
#include "include/font_writer.hpp"
|
#include "include/font_writer.hpp"
|
||||||
|
#include "include/menu.hpp"
|
||||||
#include "include/paco.hpp"
|
#include "include/paco.hpp"
|
||||||
#include <FontWriter/fonts.hpp>
|
#include <FontWriter/fonts.hpp>
|
||||||
#include <FontWriter/font_writer.hpp>
|
#include <FontWriter/font_writer.hpp>
|
||||||
|
#include <PSX/Periphery/periphery.hpp>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
using namespace JabyEngine;
|
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 this namespace?
|
||||||
// Do we want Paco to be HERE?!
|
// Do we want Paco to be HERE?!
|
||||||
static object::Paco paco;
|
static object::Paco paco;
|
||||||
|
static Menu::SimpleMenu menu;
|
||||||
|
|
||||||
static void setup() {
|
static void setup() {
|
||||||
Assets::Main::load();
|
Assets::Main::load();
|
||||||
FontWriter::setup();
|
FontWriter::setup();
|
||||||
paco.setup();
|
paco.setup();
|
||||||
|
menu.setup(MenuEntries);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void update() {
|
static void update() {
|
||||||
static const char Title[] = "Pool Box";
|
static const char Title[] = "Pool Box";
|
||||||
static constexpr auto TitleLength = (sizeof(Title) - 1)*DefaultFont::Info.font_size.width;
|
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));
|
auto cursor = FontWriter::update(JabyEngine::Make::PositionI16((GPU::Display::Width-TitleLength)/2, 16));
|
||||||
paco.update();
|
paco.update();
|
||||||
|
|
||||||
FontWriter::new_font_writer.write(cursor, Title, GPU::Color24::Yellow(), &FontWriter::wiggle);
|
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() {
|
static void render() {
|
||||||
FontWriter::new_font_writer.render();
|
FontWriter::new_font_writer.render();
|
||||||
|
FontWriter::bios_font_writer.render();
|
||||||
paco.render();
|
paco.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
};
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,7 +6,7 @@ namespace JabyEngine {
|
||||||
struct DefaultFont {
|
struct DefaultFont {
|
||||||
static constexpr auto Info = FontInfo {
|
static constexpr auto Info = FontInfo {
|
||||||
.texture_size = {64, 80},
|
.texture_size = {64, 80},
|
||||||
.font_size = {12, 16}
|
.font_size = {12, 16}
|
||||||
};
|
};
|
||||||
|
|
||||||
static void load(uint32_t* work_area, SimpleTIM vram_dst);
|
static void load(uint32_t* work_area, SimpleTIM vram_dst);
|
||||||
|
|
Loading…
Reference in New Issue