Added localization, datetime and power management

This commit is contained in:
Jozef Nagy 2025-05-15 21:32:40 +02:00
parent dd4fda27bb
commit a3bc0fc76c
Signed by untrusted user who does not match committer: crz
GPG key ID: 459A4811CEAC7068
13 changed files with 34046 additions and 14 deletions

View file

@ -1,5 +1,5 @@
/*********************************************************************************/
/* Module Name: ui.c */
/* Module Name: ui.c */
/* Project: AurixOS */
/* */
/* Copyright (c) 2024-2025 Jozef Nagy */
@ -23,11 +23,15 @@
#include <ui/mouse.h>
#include <ui/font.h>
#include <ui/ui.h>
#include <time/dt.h>
#include <i18n.h>
#include <axboot.h>
#include <print.h>
#include <stdint.h>
struct datetime last_dt;
bool gui_init(struct ui_context *ctx)
{
if (!font_init(ctx, "\\AxBoot\\fonts\\vera\\Vera.sfn", 16)) {
@ -43,26 +47,50 @@ bool tui_init(struct ui_context *ctx)
return false;
}
char *top_string = BOOTLOADER_NAME_STR " ver. " BOOTLOADER_VERSION_STR;
int top_string_w;
ssfn_bbox(&(ctx->font), top_string, &top_string_w, NULL, NULL, NULL);
int w;
terminal_setcur(ctx, ctx->fb_modes[ctx->current_mode].width / 2 - (top_string_w / 2), ctx->fb_modes[ctx->current_mode].height / 32);
// 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_print(ctx, top_string);
return true;
}
void gui_draw(void *mouse_status, void *event)
void gui_draw(struct ui_context *ctx, void *mouse_status, void *event)
{
(void)ctx;
(void)mouse_status;
(void)event;
}
void tui_draw(void *mouse_status, void *event)
void tui_draw(struct ui_context *ctx, void *mouse_status, void *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) {
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);
ssfn_bbox(&(ctx->font), (char *)dt_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;
}
}
terminal_setcur(ctx, 0, ctx->fb_modes[ctx->current_mode].height - h);
terminal_print(ctx, (char *)dt_str);
last_dt = dt;
}
}
void ui_init()
@ -83,7 +111,7 @@ void ui_init()
for (int i = 0; i < ctx.total_modes; i++) {
debug("Mode %u:%s | ", i, (i == ctx.current_mode) ? " (current)" : "");
debug("Resolution: %ux%u | ", ctx.fb_modes[i].width, ctx.fb_modes[i].height);
debug("Bits Per Pixel: %u | ", ctx.fb_modes[i].bpp);
debug("Bytes Per Pixel: %u | ", ctx.fb_modes[i].bpp);
debug("Pitch: %u | ", ctx.fb_modes[i].pitch);
debug("Format: %s\n", ctx.fb_modes[i].format == FB_RGBA ? "RGBA" : "BGRA");
}
@ -96,7 +124,7 @@ void ui_init()
ctx.font_buf.y = 0;
ctx.font_buf.fg = 0xFFFFFFFF;
void (*ui_callback)(void*,void*) = NULL;
void (*ui_callback)(struct ui_context*,void*,void*) = NULL;
switch (ctx.ui) {
case UI_MODERN: {
@ -119,7 +147,7 @@ void ui_init()
}
while (1) {
ui_callback(NULL, NULL);
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);
}