mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[bootloader > menus] Improvement
This commit is contained in:
@@ -4,13 +4,15 @@
|
||||
#include <kandinsky/context.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "computer.h"
|
||||
#include <bootloader/computer.h>
|
||||
|
||||
const Ion::Keyboard::Key Bootloader::Menu::k_breaking_keys[];
|
||||
|
||||
void Bootloader::Menu::setup() {
|
||||
// Here we add the colomns to the menu.
|
||||
}
|
||||
|
||||
void Bootloader::Menu::open() {
|
||||
void Bootloader::Menu::open(bool noreturn) {
|
||||
showMenu();
|
||||
|
||||
uint64_t scan = 0;
|
||||
@@ -19,16 +21,19 @@ void Bootloader::Menu::open() {
|
||||
while(!exit) {
|
||||
scan = Ion::Keyboard::scan();
|
||||
exit = !handleKey(scan);
|
||||
if (noreturn) {
|
||||
exit = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int Bootloader::Menu::calculateCenterX(const char * text, int fontWidth) {
|
||||
return (k_screen.width() - fontWidth * strlen(text)) / 2;
|
||||
return (getScreen().width() - fontWidth * strlen(text)) / 2;
|
||||
}
|
||||
|
||||
void Bootloader::Menu::showMenu() {
|
||||
KDContext * ctx = KDIonContext::sharedContext();
|
||||
ctx->fillRect(k_screen, m_background);
|
||||
ctx->fillRect(getScreen(), m_background);
|
||||
Interface::drawImage(ctx, ImageStore::Computer, 25);
|
||||
int y = ImageStore::Computer->height() + 25 + 10;
|
||||
int x = calculateCenterX(m_title, largeFontWidth());
|
||||
@@ -45,7 +50,7 @@ void Bootloader::Menu::showMenu() {
|
||||
}
|
||||
|
||||
if (m_bottom != nullptr) {
|
||||
y = k_screen.height() - smallFontHeight() - 10;
|
||||
y = getScreen().height() - smallFontHeight() - 10;
|
||||
x = calculateCenterX(m_bottom, smallFontWidth());
|
||||
ctx->drawString(m_bottom, KDPoint(x, y), k_small_font, m_foreground, m_background);
|
||||
}
|
||||
@@ -57,7 +62,7 @@ bool Bootloader::Menu::handleKey(uint64_t key) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (key == Ion::Keyboard::State(Ion::Keyboard::Key::Power)) {
|
||||
if (key == Ion::Keyboard::State(Ion::Keyboard::Key::OnOff)) {
|
||||
Ion::Power::standby();
|
||||
return false;
|
||||
}
|
||||
@@ -65,7 +70,9 @@ bool Bootloader::Menu::handleKey(uint64_t key) {
|
||||
if (colomn.isNull() || !colomn.isClickable()) {
|
||||
continue;
|
||||
} else {
|
||||
colomn.didHandledEvent(key);
|
||||
if (colomn.didHandledEvent(key)) {
|
||||
redraw();
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -46,20 +46,21 @@ namespace Bootloader {
|
||||
bool (*m_callback)();
|
||||
};
|
||||
|
||||
void open();
|
||||
void open(bool noreturn = false);
|
||||
void redraw() { showMenu(); };
|
||||
|
||||
static int calculateCenterX(const char * text, int fontWidth);
|
||||
|
||||
static constexpr const KDFont * k_small_font = KDFont::SmallFont;
|
||||
static constexpr const KDFont * k_large_font = KDFont::LargeFont;
|
||||
|
||||
static const KDRect getScreen() { return KDRect(0, 0, 320, 240); };
|
||||
|
||||
private:
|
||||
static const int k_max_colomns = 5;
|
||||
static const int k_colomns_margin = 5;
|
||||
|
||||
static constexpr Ion::Keyboard::Key k_breaking_keys[] = {Ion::Keyboard::Key::Back, Ion::Keyboard::Key::Home};
|
||||
static constexpr KDRect k_screen = KDRect(0, 0, 320, 240);
|
||||
|
||||
int smallFontHeight() const { return k_small_font->glyphSize().height(); };
|
||||
int largeFontHeight() const { return k_large_font->glyphSize().height(); };
|
||||
|
||||
Reference in New Issue
Block a user