Bootloader pre-release

This commit is contained in:
devdl11
2022-04-25 18:22:19 +02:00
parent add333b920
commit 5ed8aef907
65 changed files with 1328 additions and 810 deletions

View File

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