wm: add support for graphical logo

This commit is contained in:
boreddevnl 2026-05-09 18:54:20 +02:00
parent 8fcf0f67a4
commit 2784c36e84
4 changed files with 93 additions and 6 deletions

View file

@ -13,6 +13,7 @@ static struct limine_framebuffer *g_fb = NULL;
static uint32_t g_bg_color = 0xFF696969; static uint32_t g_bg_color = 0xFF696969;
extern void serial_write(const char *str); extern void serial_write(const char *str);
extern uint32_t blend_src_over_dst(uint32_t dst, uint32_t src);
static int g_color_mode = 0; static int g_color_mode = 0;
@ -24,6 +25,9 @@ static uint32_t *g_bg_image = NULL;
static int g_bg_image_w = 0; static int g_bg_image_w = 0;
static int g_bg_image_h = 0; static int g_bg_image_h = 0;
static bool g_use_image = false; static bool g_use_image = false;
static uint32_t *g_logo_pixels = NULL;
static int g_logo_w = 0;
static int g_logo_h = 0;
static DirtyRect g_dirty = {0, 0, 0, 0, false}; static DirtyRect g_dirty = {0, 0, 0, 0, false};
static spinlock_t graphics_lock = SPINLOCK_INIT; static spinlock_t graphics_lock = SPINLOCK_INIT;
@ -744,7 +748,44 @@ void graphics_set_bg_image(uint32_t *pixels, int w, int h) {
g_use_pattern = false; g_use_pattern = false;
} }
void graphics_set_logo_pixels(uint32_t *pixels, int w, int h) {
g_logo_pixels = pixels;
g_logo_w = w;
g_logo_h = h;
}
void draw_boredos_logo(int x, int y, int scale) { void draw_boredos_logo(int x, int y, int scale) {
if (g_logo_pixels) {
for (int r = 0; r < g_logo_h; r++) {
for (int c = 0; c < g_logo_w; c++) {
uint32_t pixel = g_logo_pixels[r * g_logo_w + c];
uint8_t a = (pixel >> 24) & 0xFF;
if (a == 0) continue;
if (scale == 1) {
if (a == 255) {
put_pixel(x + c, y + r, pixel);
} else {
uint32_t dst = graphics_get_pixel(x + c, y + r);
put_pixel(x + c, y + r, blend_src_over_dst(dst, pixel));
}
} else {
for (int sy = 0; sy < scale; sy++) {
for (int sx = 0; sx < scale; sx++) {
if (a == 255) {
put_pixel(x + (c * scale) + sx, y + (r * scale) + sy, pixel);
} else {
uint32_t dst = graphics_get_pixel(x + (c * scale) + sx, y + (r * scale) + sy);
put_pixel(x + (c * scale) + sx, y + (r * scale) + sy, blend_src_over_dst(dst, pixel));
}
}
}
}
}
}
return;
}
// Width: 60, Height: 16 // Width: 60, Height: 16
// 1: Magenta, 2: Blue, 3: Cyan, 4: White, 0: Deadspace // 1: Magenta, 2: Blue, 3: Cyan, 4: White, 0: Deadspace
static const uint8_t boredos_bmp[] = { static const uint8_t boredos_bmp[] = {

View file

@ -38,6 +38,7 @@ void graphics_copy_screenbuffer(uint32_t *dest);
void draw_boredos_logo(int x, int y, int scale); void draw_boredos_logo(int x, int y, int scale);
void graphics_set_logo_pixels(uint32_t *pixels, int w, int h);
// Get screen dimensions // Get screen dimensions
int get_screen_width(void); int get_screen_width(void);

View file

@ -244,10 +244,10 @@ void wallpaper_init(void) {
wallpaper_load_setting(); wallpaper_load_setting();
if (pending_wallpaper_path == NULL) { if (pending_wallpaper_path == NULL) {
if (fat32_exists("/Library/images/Wallpapers/bored.jpg")) { if (fat32_exists("/Library/images/Wallpapers/boredos.png")) {
wallpaper_request_set_from_file("/Library/images/Wallpapers/bored.jpg"); wallpaper_request_set_from_file("/Library/images/Wallpapers/boredos.png");
} else if (fat32_exists("/Library/images/Wallpapers/moon.jpg")) { } else if (fat32_exists("/Library/images/Wallpapers/mountain.jpg")) {
wallpaper_request_set_from_file("/Library/images/Wallpapers/moon.jpg"); wallpaper_request_set_from_file("/Library/images/Wallpapers/mountain.jpg");
} }
} }
} }

View file

@ -805,7 +805,7 @@ static dock_icon_entry_t dock_icons[DOCK_ICON_COUNT] = {
{"libreoffice-writer.png", DOCK_ICON_UNTRIED, {0}}, {"libreoffice-writer.png", DOCK_ICON_UNTRIED, {0}},
}; };
static uint32_t blend_src_over_dst(uint32_t dst, uint32_t src) { uint32_t blend_src_over_dst(uint32_t dst, uint32_t src) {
uint32_t sa = (src >> 24) & 0xFF; uint32_t sa = (src >> 24) & 0xFF;
if (sa == 0) return dst; if (sa == 0) return dst;
if (sa == 255) return 0xFF000000 | (src & 0x00FFFFFF); if (sa == 255) return 0xFF000000 | (src & 0x00FFFFFF);
@ -2519,7 +2519,7 @@ static void wm_paint_region(int y_start, int y_end, DirtyRect dirty, int pass) {
} else if (pass == 2) { } else if (pass == 2) {
if (0 < cy + ch && 30 > cy) { if (0 < cy + ch && 30 > cy) {
draw_rect(0, 0, sw, 30, COLOR_MENUBAR_BG); draw_rect(0, 0, sw, 30, COLOR_MENUBAR_BG);
draw_boredos_logo(8, 8, 1); draw_boredos_logo(8, 4, 1);
draw_clock(sw - 80, 12); draw_clock(sw - 80, 12);
} }
@ -4008,7 +4008,52 @@ void wm_process_deferred_thumbs(void) {
} }
} }
static void wm_load_menu_logo(void) {
const char *path = "/Library/images/icons/boredos/bOS13.png";
FAT32_FileHandle *fh = fat32_open(path, "r");
if (!fh) return;
uint32_t size = fh->size;
unsigned char *encoded = (unsigned char*)kmalloc(size);
if (!encoded) {
fat32_close(fh);
return;
}
int total = 0;
while (total < (int)size) {
int chunk = fat32_read(fh, encoded + total, (int)size - total);
if (chunk <= 0) break;
total += chunk;
}
fat32_close(fh);
int w = 0, h = 0, channels = 0;
unsigned char *rgba = stbi_load_from_memory(encoded, total, &w, &h, &channels, 4);
kfree(encoded);
if (!rgba) return;
uint32_t *pixels = (uint32_t*)kmalloc(w * h * 4);
if (!pixels) {
stbi_image_free(rgba);
return;
}
for (int i = 0; i < w * h; i++) {
uint32_t r = rgba[i * 4];
uint32_t g = rgba[i * 4 + 1];
uint32_t b = rgba[i * 4 + 2];
uint32_t a = rgba[i * 4 + 3];
pixels[i] = (a << 24) | (r << 16) | (g << 8) | b;
}
stbi_image_free(rgba);
graphics_set_logo_pixels(pixels, w, h);
}
void wm_init(void) { void wm_init(void) {
wm_load_menu_logo();
disk_manager_init(); disk_manager_init();
log_ok("Disk Manager ready"); log_ok("Disk Manager ready");