diff --git a/Makefile b/Makefile index 29415f1..aa8801f 100644 --- a/Makefile +++ b/Makefile @@ -164,10 +164,11 @@ clean: $(MAKE) -C $(SRC_DIR)/userland clean run: $(ISO_IMAGE) - qemu-system-x86_64 -m 2G -serial stdio -cdrom $< -boot d \ - -smp 4 -m 4G \ + qemu-system-x86_64 -m 4G -serial stdio -cdrom $< -boot d \ + -smp 4 \ -audiodev coreaudio,id=audio0 -machine pcspk-audiodev=audio0 \ -netdev user,id=net0,hostfwd=udp::12346-:12345 -device e1000,netdev=net0 \ -vga std -global VGA.xres=1920 -global VGA.yres=1080 \ - -drive file=disk.img,format=raw,file.locking=off \ + -display cocoa,show-cursor=off \ + -drive file=disk.img,format=raw,file.locking=off \ -cpu max \ No newline at end of file diff --git a/boredos.iso b/boredos.iso index 603d542..ffa5ab1 100644 Binary files a/boredos.iso and b/boredos.iso differ diff --git a/build/cmd.o b/build/cmd.o index 789a367..b312b03 100644 Binary files a/build/cmd.o and b/build/cmd.o differ diff --git a/build/explorer.o b/build/explorer.o index 1a53b63..b835460 100644 Binary files a/build/explorer.o and b/build/explorer.o differ diff --git a/build/fat32.o b/build/fat32.o index b97f4f2..78d5177 100644 Binary files a/build/fat32.o and b/build/fat32.o differ diff --git a/build/main.o b/build/main.o index fb41ce1..b19a649 100644 Binary files a/build/main.o and b/build/main.o differ diff --git a/build/ps2.o b/build/ps2.o index cab98fb..cabd19c 100644 Binary files a/build/ps2.o and b/build/ps2.o differ diff --git a/src/kernel/syscall.c b/src/kernel/syscall.c index b2ec461..2b3dd71 100644 --- a/src/kernel/syscall.c +++ b/src/kernel/syscall.c @@ -226,9 +226,9 @@ static uint64_t syscall_handler_inner(uint64_t syscall_num, uint64_t arg1, uint6 win->visible = true; win->focused = true; win->z_index = 0; - win->buf_len = 0; - win->buffer[0] = 0; + win->cursor_pos = 0; win->data = proc; + win->font = NULL; serial_write("Kernel: Dims initialized.\n"); @@ -360,14 +360,40 @@ static uint64_t syscall_handler_inner(uint64_t syscall_num, uint64_t arg1, uint6 uint64_t rflags; asm volatile("pushfq; pop %0; cli" : "=r"(rflags)); + ttf_font_t *font = win->font ? (ttf_font_t*)win->font : graphics_get_current_ttf(); + if (win->pixels) { if (ux >= -100 && ux < win->w && uy >= -100 && uy < (win->h - 20)) { graphics_set_render_target(win->pixels, win->w, win->h - 20); - draw_string(ux, uy, kernel_str, color); + if (font) { + int baseline = uy + font_manager_get_font_ascent_scaled(font, font->pixel_height) - 2; + int cur_x = ux; + const char *s = kernel_str; + while (*s) { + font_manager_render_char_scaled(font, cur_x, baseline, *s, color, font->pixel_height, put_pixel); + char buf[2] = {*s, 0}; + cur_x += font_manager_get_string_width_scaled(font, buf, font->pixel_height); + s++; + } + } else { + draw_string(ux, uy, kernel_str, color); + } graphics_set_render_target(NULL, 0, 0); } } else { - draw_string(win->x + ux, win->y + uy, kernel_str, color); + if (font) { + int baseline = win->y + uy + font_manager_get_font_ascent_scaled(font, font->pixel_height) - 2; + int cur_x = win->x + ux; + const char *s = kernel_str; + while (*s) { + font_manager_render_char_scaled(font, cur_x, baseline, *s, color, font->pixel_height, put_pixel); + char buf[2] = {*s, 0}; + cur_x += font_manager_get_string_width_scaled(font, buf, font->pixel_height); + s++; + } + } else { + draw_string(win->x + ux, win->y + uy, kernel_str, color); + } } asm volatile("push %0; popfq" : : "r"(rflags)); @@ -434,14 +460,40 @@ static uint64_t syscall_handler_inner(uint64_t syscall_num, uint64_t arg1, uint6 uint64_t rflags; asm volatile("pushfq; pop %0; cli" : "=r"(rflags)); + ttf_font_t *font = win->font ? (ttf_font_t*)win->font : graphics_get_current_ttf(); + if (win->pixels) { if (ux >= -100 && ux < win->w && uy >= -100 && uy < (win->h - 20)) { graphics_set_render_target(win->pixels, win->w, win->h - 20); - draw_string_scaled(ux, uy, kernel_str, color, scale); + if (font) { + int baseline = uy + font_manager_get_font_ascent_scaled(font, scale) - 2; + int cur_x = ux; + const char *s = kernel_str; + while (*s) { + font_manager_render_char_scaled(font, cur_x, baseline, *s, color, scale, put_pixel); + char buf[2] = {*s, 0}; + cur_x += font_manager_get_string_width_scaled(font, buf, scale); + s++; + } + } else { + draw_string_scaled(ux, uy, kernel_str, color, scale); + } graphics_set_render_target(NULL, 0, 0); } } else { - draw_string_scaled(win->x + ux, win->y + uy, kernel_str, color, scale); + if (font) { + int baseline = win->y + uy + font_manager_get_font_ascent_scaled(font, scale) - 2; + int cur_x = win->x + ux; + const char *s = kernel_str; + while (*s) { + font_manager_render_char_scaled(font, cur_x, baseline, *s, color, scale, put_pixel); + char buf[2] = {*s, 0}; + cur_x += font_manager_get_string_width_scaled(font, buf, scale); + s++; + } + } else { + draw_string_scaled(win->x + ux, win->y + uy, kernel_str, color, scale); + } } asm volatile("push %0; popfq" : : "r"(rflags)); @@ -517,9 +569,9 @@ static uint64_t syscall_handler_inner(uint64_t syscall_num, uint64_t arg1, uint6 } kernel_str[i] = 0; - ttf_font_t *font = graphics_get_current_ttf(); + ttf_font_t *font = (proc->ui_window && ((Window*)proc->ui_window)->font) ? (ttf_font_t*)((Window*)proc->ui_window)->font : graphics_get_current_ttf(); if (font) { - return (uint64_t)font_manager_get_string_width(font, kernel_str); + return (uint64_t)font_manager_get_string_width_scaled(font, kernel_str, font->pixel_height); } else { return (uint64_t)i * 8; // Fallback bitmap width } @@ -539,10 +591,18 @@ static uint64_t syscall_handler_inner(uint64_t syscall_num, uint64_t arg1, uint6 kernel_str[i] = 0; extern int graphics_get_string_width_scaled(const char *s, float scale); - return (uint64_t)graphics_get_string_width_scaled(kernel_str, scale); + ttf_font_t *font = (proc->ui_window && ((Window*)proc->ui_window)->font) ? (ttf_font_t*)((Window*)proc->ui_window)->font : graphics_get_current_ttf(); + if (font) { + return (uint64_t)font_manager_get_string_width_scaled(font, kernel_str, scale); + } else { + return (uint64_t)i * 8; // Fallback + } } else if (cmd == GUI_CMD_GET_FONT_HEIGHT) { - extern int graphics_get_font_height(void); - return (uint64_t)graphics_get_font_height(); + ttf_font_t *font = (proc->ui_window && ((Window*)proc->ui_window)->font) ? (ttf_font_t*)((Window*)proc->ui_window)->font : graphics_get_current_ttf(); + if (font) { + return (uint64_t)font_manager_get_font_height_scaled(font, font->pixel_height); + } + return 10; } else if (cmd == 14) { // GUI_CMD_WINDOW_SET_RESIZABLE Window *win = (Window *)arg2; @@ -556,8 +616,11 @@ static uint64_t syscall_handler_inner(uint64_t syscall_num, uint64_t arg1, uint6 } else if (cmd == 13) { // GUI_CMD_GET_FONT_HEIGHT_SCALED uint32_t scale_bits = (uint32_t)arg2; float scale = *(float*)&scale_bits; - extern int graphics_get_font_height_scaled(float scale); - return (uint64_t)graphics_get_font_height_scaled(scale); + ttf_font_t *font = (proc->ui_window && ((Window*)proc->ui_window)->font) ? (ttf_font_t*)((Window*)proc->ui_window)->font : graphics_get_current_ttf(); + if (font) { + return (uint64_t)font_manager_get_font_height_scaled(font, scale); + } + return 10; } else if (cmd == 15) { // GUI_CMD_WINDOW_SET_TITLE Window *win = (Window *)arg2; const char *user_title = (const char *)arg3; @@ -581,6 +644,24 @@ static uint64_t syscall_handler_inner(uint64_t syscall_num, uint64_t arg1, uint6 } } return 0; + } else if (cmd == 16) { // GUI_CMD_SET_FONT + Window *win = (Window *)arg2; + const char *user_path = (const char *)arg3; + if (win && user_path) { + char kernel_path[256]; + int i = 0; + while (i < 255 && user_path[i]) { + kernel_path[i] = user_path[i]; + i++; + } + kernel_path[i] = 0; + + ttf_font_t *new_font = font_manager_load(kernel_path, 15.0f); + if (new_font) { + win->font = new_font; + } + } + return 0; } } else if (syscall_num == SYS_FS) { int cmd = (int)arg1; diff --git a/src/kernel/userland/browser.c b/src/kernel/userland/browser.c index d0e15d5..344f8c5 100644 --- a/src/kernel/userland/browser.c +++ b/src/kernel/userland/browser.c @@ -1306,6 +1306,7 @@ static void net_init_if_needed(void) { int main(int argc, char **argv) { win_browser = ui_window_create("Bored Web", 50, 50, win_w, win_h); ui_window_set_resizable(win_browser, true); + ui_set_font(win_browser, "/Library/Fonts/times.ttf"); net_init_if_needed(); if (argc > 1) { int k=0; while(argv[1][k]) { url_input_buffer[k] = argv[1][k]; k++; } url_input_buffer[k] = 0; url_cursor = k; } navigate(url_input_buffer); diff --git a/src/kernel/userland/libc/libui.c b/src/kernel/userland/libc/libui.c index fd68447..580b32a 100644 --- a/src/kernel/userland/libc/libui.c +++ b/src/kernel/userland/libc/libui.c @@ -83,3 +83,7 @@ void ui_window_set_title(ui_window_t win, const char *title) { void ui_window_set_resizable(ui_window_t win, bool resizable) { syscall3(SYS_GUI, GUI_CMD_WINDOW_SET_RESIZABLE, (uint64_t)win, resizable ? 1 : 0); } + +void ui_set_font(ui_window_t win, const char *path) { + syscall3(SYS_GUI, GUI_CMD_SET_FONT, (uint64_t)win, (uint64_t)path); +} diff --git a/src/kernel/userland/libc/libui.h b/src/kernel/userland/libc/libui.h index 5839b29..86e79cd 100644 --- a/src/kernel/userland/libc/libui.h +++ b/src/kernel/userland/libc/libui.h @@ -20,6 +20,7 @@ #define GUI_CMD_GET_STRING_WIDTH_SCALED 12 #define GUI_CMD_GET_FONT_HEIGHT_SCALED 13 #define GUI_CMD_WINDOW_SET_TITLE 15 +#define GUI_CMD_SET_FONT 16 // Event Types #define GUI_EVENT_NONE 0 @@ -64,5 +65,6 @@ uint32_t ui_get_string_width_scaled(const char *str, float scale); uint32_t ui_get_font_height_scaled(float scale); void ui_window_set_title(ui_window_t win, const char *title); void ui_window_set_resizable(ui_window_t win, bool resizable); +void ui_set_font(ui_window_t win, const char *path); #endif diff --git a/src/kernel/wm.h b/src/kernel/wm.h index 80c6392..1825d0b 100644 --- a/src/kernel/wm.h +++ b/src/kernel/wm.h @@ -52,6 +52,7 @@ struct Window { void *data; uint32_t *pixels; uint32_t *comp_pixels; + void *font; // Callbacks void (*paint)(Window *win);