From 2b26af8325b9492948cb7fe516638537e4e58337 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Tue, 25 Aug 2020 23:37:09 +0200 Subject: Some GUI things --- apps/test.c | 14 ++++++++++++-- apps/wm.c | 24 ++++++++++++++++-------- 2 files changed, 28 insertions(+), 10 deletions(-) (limited to 'apps') diff --git a/apps/test.c b/apps/test.c index efc7432..93ee07a 100644 --- a/apps/test.c +++ b/apps/test.c @@ -1,16 +1,26 @@ // MIT License, Copyright (c) 2020 Marvin Borner +#include #include #include #include +#include int main() { print("[test loaded]\n"); struct window *win = gui_new_window(); - u32 color[3] = { 0xff, 0xff, 0xff }; - gui_fill(win, color); + + const u32 background[3] = { 0x28, 0x2c, 0x34 }; + gui_fill(win, background); + const u32 border[3] = { 0xab, 0xb2, 0xbf }; + gui_border(win, border, 2); + const u32 text[3] = { 0xab, 0xb2, 0xbf }; + + gui_init("/font/spleen-12x24.psfu"); + char *hello = "Hello, world!"; + gui_write(win, win->width / 2 - (strlen(hello) * 12) / 2, 5, text, hello); while (1) { yield(); diff --git a/apps/wm.c b/apps/wm.c index 1e1a8bc..7a3e2d7 100644 --- a/apps/wm.c +++ b/apps/wm.c @@ -65,12 +65,13 @@ int main(int argc, char **argv) direct->fb = vbe->fb; list_add(windows, root); - const u32 background[3] = { 0x0, 0x0, 0x0 }; + const u32 background[3] = { 0x28, 0x2c, 0x34 }; gui_fill(root, background); - const u32 border[3] = { 0xff, 0xff, 0xff }; + const u32 border[3] = { 0xab, 0xb2, 0xbf }; gui_border(root, border, 2); // TODO: Fix wallpaper /* gui_load_wallpaper(root, "/wall.bmp"); */ + redraw_all(); event_register(EVENT_KEYBOARD); event_register(EVENT_MOUSE); @@ -86,23 +87,31 @@ int main(int argc, char **argv) case MSG_NEW_WINDOW: printf("New window for pid %d\n", msg->src); struct window *win = - new_window(vbe->width / 2 - 100, vbe->height / 2 - 100, 200, 200); + new_window(vbe->width / 2 - 100, vbe->height / 2 - 100, 500, 300); msg_send(msg->src, MSG_NEW_WINDOW, win); list_add(windows, win); focused = win; + redraw_all(); + break; + case MSG_REDRAW: + redraw_all(); break; case EVENT_KEYBOARD: { struct event_keyboard *event = msg->data; - assert(event->magic == KEYBOARD_MAGIC); + if (event->magic != KEYBOARD_MAGIC) + break; printf("Keypress %d %s!\n", event->scancode, event->press ? "pressed" : "released"); - /* focused->x += 50; */ - /* redraw_all(); */ + if (event->press) { + focused->x += 50; + redraw_all(); + } break; } case EVENT_MOUSE: { struct event_mouse *event = msg->data; - assert(event->magic == MOUSE_MAGIC); + if (event->magic != MOUSE_MAGIC) + break; mouse_x += event->diff_x; mouse_y -= event->diff_y; @@ -119,7 +128,6 @@ int main(int argc, char **argv) focused->x = mouse_x; focused->y = mouse_y; redraw_all(); - printf("%d %d\n", mouse_x, mouse_y); break; } default: -- cgit v1.2.3