Added a very hacky text UI
This commit is contained in:
parent
06fb67beca
commit
dae7b9c869
16 changed files with 296 additions and 33783 deletions
|
@ -30,7 +30,10 @@
|
|||
#include <stddef.h>
|
||||
|
||||
#define DEFAULT_ENTRY 0
|
||||
#define DEFAULT_TIMEOUT 30
|
||||
// default timeout of 0 disables the UI entirely, which is essentialy what *should* happen now since the UI
|
||||
// is... in a catastrophic state. Just remember to set this back to 30 once the UI is ready
|
||||
#define DEFAULT_TIMEOUT 0
|
||||
// #define DEFAULT_TIMEOUT 30
|
||||
|
||||
char *config_paths[] = {
|
||||
"\\AxBoot\\axboot.cfg",
|
||||
|
|
|
@ -22,5 +22,8 @@
|
|||
struct language i18n_csCZ = {
|
||||
.shutdown = "Vypnout",
|
||||
.reboot = "Restartovat",
|
||||
.reboot_to_firmware = "Přejít do nastavení firmwaru"
|
||||
.reboot_to_firmware = "Přejít do nastavení firmwaru",
|
||||
.resolution = "Rozlišení",
|
||||
|
||||
.language = "Jazyk"
|
||||
};
|
||||
|
|
|
@ -22,5 +22,8 @@
|
|||
struct language i18n_enUS = {
|
||||
.shutdown = "Shutdown",
|
||||
.reboot = "Reboot",
|
||||
.reboot_to_firmware = "Reboot to Firmware"
|
||||
.reboot_to_firmware = "Reboot to Firmware",
|
||||
.resolution = "Resolution",
|
||||
|
||||
.language = "Language"
|
||||
};
|
||||
|
|
|
@ -19,6 +19,20 @@
|
|||
|
||||
#include <i18n.h>
|
||||
|
||||
extern struct language i18n_csCZ;
|
||||
extern struct language i18n_enUS;
|
||||
|
||||
struct language *i18n_lang = &i18n_enUS;
|
||||
struct language_selection i18n_languages[] = {
|
||||
{
|
||||
"Čeština",
|
||||
"cs_CZ",
|
||||
&i18n_csCZ
|
||||
},
|
||||
{
|
||||
"English",
|
||||
"en_US",
|
||||
&i18n_enUS
|
||||
}
|
||||
};
|
||||
|
||||
struct language_selection *i18n_curlang = &i18n_languages[1]; // english
|
|
@ -38,6 +38,12 @@ void axboot_init()
|
|||
|
||||
//config_init();
|
||||
|
||||
// boot straight away
|
||||
if (config_get_timeout() < 1) {
|
||||
struct axboot_entry *entries = config_get_entries();
|
||||
loader_load(&(entries[config_get_default()]));
|
||||
}
|
||||
|
||||
ui_init();
|
||||
|
||||
debug("axboot_init(): Returned from main menu, something went wrong. Halting!");
|
||||
|
|
|
@ -20,9 +20,11 @@
|
|||
#include <config/config.h>
|
||||
#include <lib/string.h>
|
||||
#include <ui/framebuffer.h>
|
||||
#include <ui/keyboard.h>
|
||||
#include <ui/mouse.h>
|
||||
#include <ui/font.h>
|
||||
#include <ui/ui.h>
|
||||
#include <loader/loader.h>
|
||||
#include <time/dt.h>
|
||||
#include <i18n.h>
|
||||
#include <axboot.h>
|
||||
|
@ -30,6 +32,18 @@
|
|||
#include <print.h>
|
||||
#include <stdint.h>
|
||||
|
||||
enum {
|
||||
EVENT_TIME = (1 << 0),
|
||||
EVENT_TIMEOUT = (1 << 1),
|
||||
EVENT_MOUSE = (1 << 2),
|
||||
|
||||
EVENT_NEXT_ENTRY = (1 << 3),
|
||||
EVENT_PREV_ENTRY = (1 << 4),
|
||||
EVENT_NEXT_TAB = (1 << 5),
|
||||
|
||||
EVENT_LANG_CHANGE = (1 << 6),
|
||||
};
|
||||
|
||||
struct datetime last_dt;
|
||||
|
||||
bool gui_init(struct ui_context *ctx)
|
||||
|
@ -47,37 +61,72 @@ bool tui_init(struct ui_context *ctx)
|
|||
return false;
|
||||
}
|
||||
|
||||
int w;
|
||||
int width = ctx->fb_modes[ctx->current_mode].width;
|
||||
int height = ctx->fb_modes[ctx->current_mode].height;
|
||||
int width_center = width / 2;
|
||||
int height_center = height / 2;
|
||||
|
||||
int w, h;
|
||||
|
||||
// display string at the top center of the screen
|
||||
char *top_string = BOOTLOADER_NAME_STR " v" BOOTLOADER_VERSION_STR;
|
||||
ssfn_bbox(&(ctx->font), top_string, &w, NULL, NULL, NULL);
|
||||
|
||||
terminal_setcur(ctx, ctx->fb_modes[ctx->current_mode].width / 2 - (w / 2), ctx->fb_modes[ctx->current_mode].height / 32);
|
||||
terminal_setcur(ctx, width_center - (w / 2), height / 32);
|
||||
terminal_print(ctx, top_string);
|
||||
|
||||
// display current language
|
||||
char lang_str[64];
|
||||
snprintf((char *)&lang_str, 64, "%s: %s", i18n_curlang->lang->language, i18n_curlang->name);
|
||||
ssfn_bbox(&(ctx->font), (char *)lang_str, &w, &h, NULL, NULL);
|
||||
terminal_setcur(ctx, width - w - ctx->font.size, height - h);
|
||||
terminal_print(ctx, (char *)lang_str);
|
||||
|
||||
// display all entries
|
||||
int entry_count = config_get_entry_count();
|
||||
int entry_height_offset = height_center - ((h * entry_count) / 2);
|
||||
struct axboot_entry *entries = config_get_entries();
|
||||
|
||||
for (int i = 0; i < entry_count; i++) {
|
||||
debug("tui_init(): Drawing entries... (%u/%u)\n", i, entry_count);
|
||||
ssfn_bbox(&(ctx->font), entries[i].name, &w, &h, NULL, NULL);
|
||||
terminal_setcur(ctx, width_center - (w/2), entry_height_offset + (i * h));
|
||||
terminal_print(ctx, entries[i].name);
|
||||
}
|
||||
|
||||
// highlight default entry
|
||||
int default_entry = ctx->current_selection;
|
||||
char final_selent[128];
|
||||
int f_w, f_h;
|
||||
ssfn_bbox(&(ctx->font), " ", &f_w, &f_h, NULL, NULL);
|
||||
snprintf((char *)&final_selent, 128, "> %s <", entries[default_entry].name);
|
||||
ssfn_bbox(&(ctx->font), entries[default_entry].name, &w, &h, NULL, NULL);
|
||||
terminal_setcur(ctx, width_center - (w/2) - (f_w*2), entry_height_offset + (default_entry * h));
|
||||
terminal_print(ctx, "> ");
|
||||
terminal_setcur(ctx, width_center + (w/2), entry_height_offset + (default_entry * h));
|
||||
terminal_print(ctx, " <");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void gui_draw(struct ui_context *ctx, void *mouse_status, void *event)
|
||||
void gui_draw(struct ui_context *ctx, struct datetime *dt, struct language_selection *newlang, struct mouse_event *mouse_status, uint8_t event)
|
||||
{
|
||||
(void)ctx;
|
||||
(void)dt;
|
||||
(void)newlang;
|
||||
(void)mouse_status;
|
||||
(void)event;
|
||||
}
|
||||
|
||||
void tui_draw(struct ui_context *ctx, void *mouse_status, void *event)
|
||||
void tui_draw(struct ui_context *ctx, struct datetime *dt, struct language_selection *newlang, struct mouse_event *mouse_status, uint8_t event)
|
||||
{
|
||||
(void)mouse_status;
|
||||
(void)event;
|
||||
|
||||
// display the current date and time at the bottom left corner of the screen
|
||||
int w, h;
|
||||
struct datetime dt;
|
||||
get_datetime(&dt);
|
||||
if (memcmp(&dt, &last_dt, sizeof(struct datetime)) != 0) {
|
||||
if (event & EVENT_TIME) {
|
||||
int w, h;
|
||||
char dt_str[20] = {0}; // YYYY/mm/dd HH:MM:SS
|
||||
snprintf((char *)&dt_str, 20, "%.4u/%.2u/%.2u %.2u:%.2u:%.2u", dt.year, dt.month, dt.day, dt.h, dt.m, dt.s);
|
||||
snprintf((char *)&dt_str, 20, "%.4u/%.2u/%.2u %.2u:%.2u:%.2u", dt->year, dt->month, dt->day, dt->h, dt->m, dt->s);
|
||||
|
||||
ssfn_bbox(&(ctx->font), (char *)dt_str, &w, &h, NULL, NULL);
|
||||
|
||||
|
@ -89,7 +138,44 @@ void tui_draw(struct ui_context *ctx, void *mouse_status, void *event)
|
|||
terminal_setcur(ctx, 0, ctx->fb_modes[ctx->current_mode].height - h);
|
||||
terminal_print(ctx, (char *)dt_str);
|
||||
|
||||
last_dt = dt;
|
||||
// update last datetime
|
||||
last_dt = *dt;
|
||||
}
|
||||
|
||||
// timeout update
|
||||
if (event & EVENT_TIMEOUT) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
// select next entry
|
||||
if (event & EVENT_NEXT_ENTRY) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
// select previous entry
|
||||
if (event & EVENT_PREV_ENTRY) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
// update language
|
||||
if (event & EVENT_LANG_CHANGE) {
|
||||
int w, h;
|
||||
char curlang_str[64];
|
||||
snprintf((char *)&curlang_str, 64, "%s: %s", i18n_curlang->lang->language);
|
||||
ssfn_bbox(&(ctx->font), (char *)curlang_str, &w, &h, NULL, NULL);
|
||||
for (uint32_t y = ctx->fb_modes[ctx->current_mode].height - (2*h); y < ctx->fb_modes[ctx->current_mode].height - h; y++) {
|
||||
for (int x = 0; x < w; x++) {
|
||||
*((uint32_t *)ctx->fb_addr + (ctx->fb_modes[ctx->current_mode].pitch / ctx->fb_modes[ctx->current_mode].bpp) * y + x) = 0xFF000000;
|
||||
}
|
||||
}
|
||||
|
||||
i18n_curlang = newlang;
|
||||
|
||||
char newlang_str[64];
|
||||
snprintf((char *)&curlang_str, 64, "%s: %s", i18n_curlang->lang->language);
|
||||
ssfn_bbox(&(ctx->font), (char *)curlang_str, &w, &h, NULL, NULL);
|
||||
terminal_setcur(ctx, ctx->fb_modes[ctx->current_mode].width - w, ctx->fb_modes[ctx->current_mode].height - h);
|
||||
terminal_print(ctx, (char *)newlang_str);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,7 +210,9 @@ void ui_init()
|
|||
ctx.font_buf.y = 0;
|
||||
ctx.font_buf.fg = 0xFFFFFFFF;
|
||||
|
||||
void (*ui_callback)(struct ui_context*,void*,void*) = NULL;
|
||||
ctx.current_selection = config_get_default();
|
||||
|
||||
void (*ui_callback)(struct ui_context*,struct datetime*,struct language_selection*,struct mouse_event*,uint8_t) = NULL;
|
||||
|
||||
switch (ctx.ui) {
|
||||
case UI_MODERN: {
|
||||
|
@ -146,9 +234,57 @@ void ui_init()
|
|||
}
|
||||
}
|
||||
|
||||
struct datetime dt;
|
||||
struct mouse_event me;
|
||||
|
||||
while (1) {
|
||||
ui_callback(&ctx, NULL, NULL);
|
||||
//get_mouse(&m_x, &m_y, &m_but);
|
||||
//debug("Mouse X = %u | Mouse Y = %u\n", m_x, m_y);
|
||||
uint8_t event = 0;
|
||||
|
||||
// datetime?
|
||||
get_datetime(&dt);
|
||||
if (memcmp(&dt, &last_dt, sizeof(struct datetime)) != 0) {
|
||||
event |= EVENT_TIME;
|
||||
}
|
||||
|
||||
// mouse movement?
|
||||
get_mouse(&(me.x), &(me.y), &(me.but));
|
||||
if (memcmp(&me, &(ctx.last_mouse), sizeof(struct mouse_event)) != 0) {
|
||||
event |= EVENT_MOUSE;
|
||||
}
|
||||
|
||||
// keypress?
|
||||
uint16_t scancode;
|
||||
get_keypress(&scancode);
|
||||
if (scancode != 0) {
|
||||
switch (scancode) {
|
||||
case SCANCODE_ARROW_DOWN:
|
||||
event |= EVENT_NEXT_ENTRY;
|
||||
break;
|
||||
case SCANCODE_ARROW_UP:
|
||||
event |= EVENT_PREV_ENTRY;
|
||||
break;
|
||||
case SCANCODE_ENTER:
|
||||
// clear the screen
|
||||
for (uint32_t y = 0; y < ctx.fb_modes[ctx.current_mode].height; y++) {
|
||||
for (uint32_t x = 0; x < ctx.fb_modes[ctx.current_mode].width; x++) {
|
||||
*((uint32_t *)ctx.fb_addr + (ctx.fb_modes[ctx.current_mode].pitch / ctx.fb_modes[ctx.current_mode].bpp) * y + x) = 0xFF000000;
|
||||
}
|
||||
}
|
||||
struct axboot_entry *entries = config_get_entries();
|
||||
loader_load(&entries[ctx.current_selection]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (event != 0) {
|
||||
ui_callback(&ctx, &dt, NULL, &me, event);
|
||||
} else {
|
||||
#ifdef __x86_64
|
||||
__asm__ volatile("hlt");
|
||||
#endif
|
||||
//arch_wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,8 +24,17 @@ struct language {
|
|||
char *shutdown;
|
||||
char *reboot;
|
||||
char *reboot_to_firmware;
|
||||
char *resolution;
|
||||
|
||||
char *language;
|
||||
};
|
||||
|
||||
extern struct language *i18n_lang;
|
||||
struct language_selection {
|
||||
char *name;
|
||||
char *code;
|
||||
struct language *lang;
|
||||
};
|
||||
|
||||
extern struct language_selection *i18n_curlang;
|
||||
|
||||
#endif /* _I18N_H */
|
||||
|
|
File diff suppressed because it is too large
Load diff
31
boot/include/ui/keyboard.h
Normal file
31
boot/include/ui/keyboard.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: keyboard.c */
|
||||
/* Project: AurixOS */
|
||||
/* */
|
||||
/* Copyright (c) 2024-2025 Jozef Nagy */
|
||||
/* */
|
||||
/* This source is subject to the MIT License. */
|
||||
/* See License.txt in the root of this repository. */
|
||||
/* All other rights reserved. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
|
||||
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
|
||||
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
|
||||
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
|
||||
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
|
||||
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
|
||||
/* SOFTWARE. */
|
||||
/*********************************************************************************/
|
||||
|
||||
#ifndef _UI_KEYBOARD_H
|
||||
#define _UI_KEYBOARD_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define SCANCODE_ARROW_UP 0x1
|
||||
#define SCANCODE_ARROW_DOWN 0x2
|
||||
#define SCANCODE_ENTER 43
|
||||
|
||||
void get_keypress(uint16_t *scancode);
|
||||
|
||||
#endif /* _UI_KEYBOARD_H */
|
|
@ -39,6 +39,12 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
struct mouse_event {
|
||||
uint16_t x;
|
||||
uint16_t y;
|
||||
uint8_t but;
|
||||
};
|
||||
|
||||
struct ui_context {
|
||||
uint32_t *fb_addr;
|
||||
struct fb_mode *fb_modes;
|
||||
|
@ -46,6 +52,11 @@ struct ui_context {
|
|||
int current_mode;
|
||||
int ui;
|
||||
|
||||
struct mouse_event last_mouse;
|
||||
|
||||
int current_selection;
|
||||
int last_selection;
|
||||
|
||||
struct terminal terminal;
|
||||
|
||||
ssfn_t font;
|
||||
|
|
|
@ -51,6 +51,9 @@ EFI_STATUS uefi_entry(EFI_HANDLE ImageHandle,
|
|||
gSystemTable = SystemTable;
|
||||
gBootServices = SystemTable->BootServices;
|
||||
|
||||
// reset input
|
||||
gSystemTable->ConIn->Reset(gSystemTable->ConIn, EFI_FALSE);
|
||||
|
||||
// clear the screen
|
||||
gSystemTable->ConOut->ClearScreen(gSystemTable->ConOut);
|
||||
|
||||
|
|
39
boot/platform/uefi/ui/keyboard.c
Normal file
39
boot/platform/uefi/ui/keyboard.c
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*********************************************************************************/
|
||||
/* Module Name: keyboard.c */
|
||||
/* Project: AurixOS */
|
||||
/* */
|
||||
/* Copyright (c) 2024-2025 Jozef Nagy */
|
||||
/* */
|
||||
/* This source is subject to the MIT License. */
|
||||
/* See License.txt in the root of this repository. */
|
||||
/* All other rights reserved. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
|
||||
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
|
||||
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
|
||||
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
|
||||
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
|
||||
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
|
||||
/* SOFTWARE. */
|
||||
/*********************************************************************************/
|
||||
|
||||
#include <ui/keyboard.h>
|
||||
#include <stdint.h>
|
||||
#include <print.h>
|
||||
|
||||
#include <efi.h>
|
||||
#include <efilib.h>
|
||||
|
||||
void get_keypress(uint16_t *scancode)
|
||||
{
|
||||
EFI_INPUT_KEY key;
|
||||
if (gSystemTable->ConIn->ReadKeyStroke(gSystemTable->ConIn, &key) == EFI_SUCCESS) {
|
||||
if (key.UnicodeChar == L'\r') {
|
||||
*scancode = SCANCODE_ENTER;
|
||||
return;
|
||||
}
|
||||
*scancode = key.ScanCode;
|
||||
} else {
|
||||
*scancode = 0;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue