mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-27 01:29:58 +01:00
Bootloader pre-release
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#include <bootloader/interface/src/menu.h>
|
||||
#include <bootloader/interface.h>
|
||||
#include <bootloader/interface/static/interface.h>
|
||||
#include <ion.h>
|
||||
#include <kandinsky/context.h>
|
||||
#include <string.h>
|
||||
@@ -9,7 +9,7 @@
|
||||
const Ion::Keyboard::Key Bootloader::Menu::k_breaking_keys[];
|
||||
|
||||
void Bootloader::Menu::setup() {
|
||||
// Here we add the colomns to the menu.
|
||||
// Here we add the columns to the menu.
|
||||
}
|
||||
|
||||
void Bootloader::Menu::open(bool noreturn) {
|
||||
@@ -17,8 +17,10 @@ void Bootloader::Menu::open(bool noreturn) {
|
||||
|
||||
uint64_t scan = 0;
|
||||
bool exit = false;
|
||||
|
||||
post_open();
|
||||
|
||||
while(!exit) {
|
||||
while(!exit && !m_forced_exit) {
|
||||
scan = Ion::Keyboard::scan();
|
||||
exit = !handleKey(scan);
|
||||
if (noreturn) {
|
||||
@@ -40,13 +42,17 @@ void Bootloader::Menu::showMenu() {
|
||||
ctx->drawString(m_title, KDPoint(x, y), k_large_font, m_foreground, m_background);
|
||||
y += largeFontHeight() + 10;
|
||||
|
||||
//TODO: center the colomns if m_centerY is true
|
||||
//TODO: center the columns if m_centerY is true
|
||||
|
||||
for (Colomn & colomn : m_colomns) {
|
||||
if (colomn.isNull()) {
|
||||
break;
|
||||
for (ColumnBinder column : m_columns) {
|
||||
if (column.isNull()) {
|
||||
continue;
|
||||
}
|
||||
if (column.type() == ColumnType::SLOT) {
|
||||
y += ((SlotColumn *)column.getColumn())->draw(ctx, y, m_background, m_foreground) + m_margin;
|
||||
} else if (column.type() == ColumnType::DEFAULT) {
|
||||
y += ((Column *)column.getColumn())->draw(ctx, y, m_background, m_foreground) + m_margin;
|
||||
}
|
||||
y += colomn.draw(ctx, y, m_background, m_foreground) + k_colomns_margin;
|
||||
}
|
||||
|
||||
if (m_bottom != nullptr) {
|
||||
@@ -66,26 +72,32 @@ bool Bootloader::Menu::handleKey(uint64_t key) {
|
||||
Ion::Power::standby();
|
||||
return false;
|
||||
}
|
||||
for (Colomn & colomn : this->m_colomns) {
|
||||
if (colomn.isNull() || !colomn.isClickable()) {
|
||||
for (ColumnBinder column : m_columns) {
|
||||
if (column.isNull()) {
|
||||
continue;
|
||||
} else {
|
||||
if (colomn.didHandledEvent(key)) {
|
||||
redraw();
|
||||
if (column.type() == ColumnType::SLOT) {
|
||||
if (((SlotColumn *)column.getColumn())->didHandledEvent(key)) {
|
||||
redraw();
|
||||
}
|
||||
} else if (column.type() == ColumnType::DEFAULT) {
|
||||
if (((Column *)column.getColumn())->didHandledEvent(key)) {
|
||||
redraw();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Bootloader::Menu::Colomn::didHandledEvent(uint64_t key) {
|
||||
bool Bootloader::Menu::Column::didHandledEvent(uint64_t key) {
|
||||
if (isMyKey(key) && isClickable()) {
|
||||
return m_callback();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int Bootloader::Menu::Colomn::draw(KDContext * ctx, int y, KDColor background, KDColor foreground) {
|
||||
int Bootloader::Menu::Column::draw(KDContext * ctx, int y, KDColor background, KDColor foreground) {
|
||||
int x = m_extraX;
|
||||
if (m_center) {
|
||||
x += Bootloader::Menu::calculateCenterX(m_text, m_font->glyphSize().width());
|
||||
@@ -93,3 +105,32 @@ int Bootloader::Menu::Colomn::draw(KDContext * ctx, int y, KDColor background, K
|
||||
ctx->drawString(m_text, KDPoint(x, y), m_font, foreground, background);
|
||||
return m_font->glyphSize().height();
|
||||
}
|
||||
|
||||
int Bootloader::Menu::SlotColumn::draw(KDContext * ctx, int y, KDColor background, KDColor foreground) {
|
||||
int x = m_extraX;
|
||||
|
||||
int width = strlen(m_text);
|
||||
if (m_kernalPatch != nullptr) {
|
||||
width += strlen(m_kernalPatch) + m_font->glyphSize().width();
|
||||
}
|
||||
if (m_osType != nullptr) {
|
||||
width += strlen(m_osType) + m_font->glyphSize().width();
|
||||
}
|
||||
if (m_center) {
|
||||
x += Bootloader::Menu::getScreen().width() - width * m_font->glyphSize().width();
|
||||
}
|
||||
ctx->drawString(m_text, KDPoint(x, y), m_font, foreground, background);
|
||||
x += strlen(m_text) * m_font->glyphSize().width() + m_font->glyphSize().width();
|
||||
if (m_kernalPatch != nullptr) {
|
||||
ctx->drawString(m_kernalPatch, KDPoint(x, y), m_font, foreground, background);
|
||||
}
|
||||
x += strlen(m_kernalPatch) * m_font->glyphSize().width() + m_font->glyphSize().width();
|
||||
if (m_osType != nullptr) {
|
||||
ctx->drawString(m_osType, KDPoint(x, y), m_font, foreground, background);
|
||||
}
|
||||
x += strlen(m_osType) * m_font->glyphSize().width() + m_font->glyphSize().width();
|
||||
if (m_kernelVersion != nullptr) {
|
||||
ctx->drawString(m_kernelVersion, KDPoint(x, y), m_font, foreground, background);
|
||||
}
|
||||
return m_font->glyphSize().height();
|
||||
}
|
||||
|
||||
@@ -2,48 +2,82 @@
|
||||
#define _BOOTLOADER_MENU_H_
|
||||
|
||||
#include <ion/keyboard.h>
|
||||
#include <bootloader/messages.h>
|
||||
#include <bootloader/interface/static/messages.h>
|
||||
#include <kandinsky/context.h>
|
||||
|
||||
namespace Bootloader {
|
||||
class Menu {
|
||||
public:
|
||||
Menu() : m_colomns(), m_background(KDColorWhite), m_title(Messages::mainTitle), m_foreground(KDColorBlack), m_bottom(nullptr), m_centerY(false) {
|
||||
setup();
|
||||
};
|
||||
Menu(KDColor forground, KDColor background, const char * title) : m_colomns(), m_background(background), m_title(title), m_foreground(forground), m_bottom(nullptr), m_centerY(false) {
|
||||
setup();
|
||||
};
|
||||
Menu(KDColor forground, KDColor background, const char * title, const char * bottom) : m_colomns(), m_background(background), m_title(title), m_foreground(forground), m_bottom(bottom), m_centerY(false) {
|
||||
setup();
|
||||
};
|
||||
Menu(KDColor forground, KDColor background, const char * title, const char * bottom, bool centerY) : m_colomns(), m_background(background), m_title(title), m_foreground(forground), m_bottom(bottom), m_centerY(centerY) {
|
||||
Menu() : Menu(KDColorBlack, KDColorWhite, Messages::mainTitle) { };
|
||||
Menu(KDColor forground, KDColor background, const char * title) : Menu(forground, background, title, nullptr) {};
|
||||
Menu(KDColor forground, KDColor background, const char * title, const char * bottom) : Menu(forground, background, title, bottom, false) {};
|
||||
Menu(KDColor forground, KDColor background, const char * title, const char * bottom, bool centerY) : Menu(forground, background, title, bottom, centerY, k_columns_margin) {};
|
||||
Menu(KDColor forground, KDColor background, const char * title, const char * bottom, bool centerY, int margin) : m_columns(), m_default_columns(), m_slot_columns(), m_background(background), m_title(title), m_foreground(forground), m_bottom(bottom), m_centerY(centerY), m_forced_exit(false), m_margin(margin) {
|
||||
setup();
|
||||
}
|
||||
static const int k_columns_margin = 5;
|
||||
|
||||
virtual void setup() = 0;
|
||||
virtual void post_open() = 0;
|
||||
|
||||
enum ColumnType {
|
||||
DEFAULT,
|
||||
SLOT
|
||||
};
|
||||
|
||||
class Colomn {
|
||||
class Column {
|
||||
public:
|
||||
Colomn() : m_text(nullptr), m_key(Ion::Keyboard::Key::None), m_font(KDFont::SmallFont), m_extraX(0), m_center(false), m_callback(nullptr) {};
|
||||
Colomn(const char * t, Ion::Keyboard::Key k, const KDFont * font, int extraX, bool center, bool(*pointer)()) : m_text(t), m_key(k), m_font(font), m_extraX(extraX), m_center(center), m_callback(pointer), m_clickable(true) {};
|
||||
Colomn(const char * t, const KDFont * font, int extraX, bool center) : m_text(t), m_key(Ion::Keyboard::Key::None), m_font(font), m_extraX(extraX), m_center(center), m_callback(nullptr), m_clickable(false) {};
|
||||
Column() : m_text(nullptr), m_key(Ion::Keyboard::Key::None), m_font(KDFont::SmallFont), m_extraX(0), m_center(false), m_callback(nullptr), m_clickable(false) {};
|
||||
|
||||
Column(const char * t, Ion::Keyboard::Key k, const KDFont * font, int extraX, bool center, bool(*pointer)()) : m_text(t), m_key(k), m_font(font), m_extraX(extraX), m_center(center), m_callback(pointer), m_clickable(true) {};
|
||||
Column(const char * t, const KDFont * font, int extraX, bool center) : m_text(t), m_key(Ion::Keyboard::Key::None), m_font(font), m_extraX(extraX), m_center(center), m_callback(nullptr), m_clickable(false) {};
|
||||
|
||||
bool isNull() const { return m_text == nullptr; };
|
||||
bool isClickable() const { return m_clickable; };
|
||||
bool didHandledEvent(uint64_t key);
|
||||
int draw(KDContext * ctx, int y, KDColor background, KDColor foreground);
|
||||
virtual int draw(KDContext * ctx, int y, KDColor background, KDColor foreground);
|
||||
virtual int columnType() { return ColumnType::DEFAULT; };
|
||||
|
||||
private:
|
||||
bool isMyKey(uint64_t key) const { return Ion::Keyboard::State(m_key) == key; };
|
||||
|
||||
protected:
|
||||
const char * m_text;
|
||||
Ion::Keyboard::Key m_key;
|
||||
const KDFont * m_font;
|
||||
int m_extraX;
|
||||
bool m_center;
|
||||
bool m_clickable;
|
||||
bool (*m_callback)();
|
||||
bool m_clickable;
|
||||
};
|
||||
|
||||
class SlotColumn : public Column {
|
||||
public:
|
||||
SlotColumn() : Column(), m_kernalPatch(nullptr), m_osType(nullptr), m_kernelVersion(nullptr) {};
|
||||
|
||||
SlotColumn(const char * t, Ion::Keyboard::Key k, const KDFont * font, int extraX, bool center, bool(*pointer)()) : Column(t, k, font, extraX, center, pointer), m_kernalPatch(nullptr), m_osType(nullptr), m_kernelVersion(nullptr) {};
|
||||
SlotColumn(const char * t, const char * k, const char * o, const char * kernelV, Ion::Keyboard::Key key, const KDFont * font, int extraX, bool center, bool(*pointer)()) : Column(t, key, font, extraX, center, pointer), m_kernalPatch(k), m_osType(o), m_kernelVersion(kernelV) {};
|
||||
|
||||
int draw(KDContext * ctx, int y, KDColor background, KDColor foreground) override;
|
||||
virtual int columnType() { return ColumnType::SLOT; };
|
||||
|
||||
private:
|
||||
const char * m_kernalPatch;
|
||||
const char * m_osType;
|
||||
const char * m_kernelVersion;
|
||||
};
|
||||
|
||||
class ColumnBinder {
|
||||
public:
|
||||
ColumnBinder() : m_pointer(nullptr), m_type(ColumnType::DEFAULT) {};
|
||||
ColumnBinder(Column * pointer) : m_pointer(pointer), m_type(ColumnType::DEFAULT) {};
|
||||
ColumnBinder(SlotColumn * pointer) : m_pointer(pointer), m_type(ColumnType::SLOT) {};
|
||||
|
||||
bool isNull() const { return m_pointer == nullptr; };
|
||||
void * getColumn() const { return m_pointer; };
|
||||
ColumnType type() const { return m_type; };
|
||||
private:
|
||||
void * m_pointer;
|
||||
ColumnType m_type;
|
||||
};
|
||||
|
||||
void open(bool noreturn = false);
|
||||
@@ -56,9 +90,11 @@ namespace Bootloader {
|
||||
|
||||
static const KDRect getScreen() { return KDRect(0, 0, 320, 240); };
|
||||
|
||||
protected:
|
||||
void forceExit() { m_forced_exit = true; };
|
||||
|
||||
private:
|
||||
static const int k_max_colomns = 5;
|
||||
static const int k_colomns_margin = 5;
|
||||
static const int k_max_columns = 6;
|
||||
|
||||
static constexpr Ion::Keyboard::Key k_breaking_keys[] = {Ion::Keyboard::Key::Back, Ion::Keyboard::Key::Home};
|
||||
|
||||
@@ -72,12 +108,18 @@ namespace Bootloader {
|
||||
void showMenu();
|
||||
|
||||
protected:
|
||||
Colomn m_colomns[k_max_colomns];
|
||||
ColumnBinder m_columns[k_max_columns];
|
||||
// Columns Storage
|
||||
Column m_default_columns[k_max_columns];
|
||||
SlotColumn m_slot_columns[k_max_columns];
|
||||
KDColor m_background;
|
||||
KDColor m_foreground;
|
||||
const char * m_title;
|
||||
const char * m_bottom;
|
||||
bool m_centerY;
|
||||
int m_margin;
|
||||
private:
|
||||
bool m_forced_exit;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user