From 6382172ac01ef17913c54177e556706d6ae2ec7f Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Mon, 23 Oct 2023 17:49:31 +0200 Subject: WindowServer: Draw a border around the active window --- userland/windowserver/draw.c | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'userland/windowserver/draw.c') diff --git a/userland/windowserver/draw.c b/userland/windowserver/draw.c index 5b3402a..cf3cd99 100644 --- a/userland/windowserver/draw.c +++ b/userland/windowserver/draw.c @@ -41,6 +41,25 @@ void draw_mouse(DISPLAY *disp, int mouse_x, int mouse_y) { update_full_display(disp, mouse_x, mouse_y); } +void draw_line(DISPLAY *disp, int sx, int sy, int dx, int dy, uint32_t color) { + int x = sx; + int y = sy; + for (;;) { + // Bounds checking + if (y * WIDTH + x > HEIGHT * WIDTH) + break; + + if (x >= dx - 1 && y >= dy - 1) + break; + uint32_t *ptr = disp->back_buffer + (BPP * y * WIDTH) + (x * BPP); + *ptr = color; + if (x < dx - 1) + x++; + if (y < dy - 1) + y++; + } +} + void draw_window(DISPLAY *disp, const WINDOW *w) { int x, y; uint8_t border_size = disp->border_size; @@ -50,6 +69,18 @@ void draw_window(DISPLAY *disp, const WINDOW *w) { const int sy = w->sy; x = px; y = py; + // Draw a border around the current selected window + if (w == disp->active_window) { + // Top + draw_line(disp, px - 1, py - 1, px + sx + 1, py - 1, 0xFF00FF); + // Bottom + draw_line(disp, px - 1, py + sy, px + sx + 1, py + sy, 0xFF00FF); + // Left + draw_line(disp, px - 1, py - 1, px - 1, py + sy + 1, 0xFF00FF); + // Right + draw_line(disp, px + sx, py - 1, px + sx, py + sy + 1, 0xFF00FF); + } + for (int i = 0; i < sy; i++) { if ((i + py) * WIDTH + px > HEIGHT * WIDTH) break; @@ -57,7 +88,6 @@ void draw_window(DISPLAY *disp, const WINDOW *w) { if (i * sx > HEIGHT * WIDTH) break; uint32_t *bm = &w->bitmap_ptr[i * sx]; - // ((uint8_t *)w->bitmap_ptr) + BPP * ((i + py) * WIDTH) + px * BPP; for (int j = 0; j < sx; j++) { ptr[j] = bm[j]; } @@ -75,12 +105,7 @@ void update_active_window(DISPLAY *disp) { } void update_full_display(DISPLAY *disp, int mouse_x, int mouse_y) { - draw_wallpaper(disp); /* - for (int i = 0; i < 100; i++) { - if (!disp->windows[i]) - continue; - draw_window(disp, disp->windows[i]); - }*/ + draw_wallpaper(disp); update_active_window(disp); update_display(disp); } -- cgit v1.2.3