setos

拙OS
Log | Files | Refs | LICENSE

commit ae621d8d640936605da8bed4a8312f7a997369a5
parent 902a616ca900395ec60fee888169959f75d750cc
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Fri,  5 Apr 2024 12:42:37 +0900

add thickness to border

Diffstat:
Msys/include/draw.h | 4+++-
Msys/src/kernel/draw.c | 28++++++++++++++++------------
Msys/src/kernel/main.c | 14++++++--------
3 files changed, 25 insertions(+), 21 deletions(-)

diff --git a/sys/include/draw.h b/sys/include/draw.h @@ -37,6 +37,8 @@ typedef struct Window { int init_root_window(uint32 *fb_base, int hres, int vres, int ppsl, EFI_GRAPHICS_PIXEL_FORMAT pf); extern void (* pixel)(Window *dst, Point p, RGBA32 col); void line(Window *dst, Point p0, Point p1, RGBA32 col); -void border(Window *dst, Rectangle r, RGBA32 col); +// i is the thickness of the border. +// i = 0: one pixel line, i > 0: inside the border, i < 0: outside the border. +void border(Window *dst, Rectangle r, int i, RGBA32 col); void fill(Window *dst, Rectangle r, RGBA32 col); void clear(Window *dst); \ No newline at end of file diff --git a/sys/src/kernel/draw.c b/sys/src/kernel/draw.c @@ -101,20 +101,24 @@ line(Window *dst, Point p0, Point p1, RGBA32 col) } void -border(Window *dst, Rectangle r, RGBA32 col) +border(Window *dst, Rectangle r, int i, RGBA32 col) { int x, y; - for (x = r.min.x, y = r.min.y; x < r.max.x; x++) { - pixel(dst, (Point){x, y}, col); - } - for (x = r.max.x-1, y = r.min.y; y < r.max.y; y++) { - pixel(dst, (Point){x, y}, col); - } - for (x = r.max.x-1, y = r.max.y-1; x >= r.min.x; x--) { - pixel(dst, (Point){x, y}, col); - } - for (x = r.min.x, y = r.max.y-1; y >= r.min.y; y--) { - pixel(dst, (Point){x, y}, col); + int j; + int s = i > 0 ? 1 : -1; + for (j = 0; j != i+s; j += s) { + for (x = r.min.x+j, y = r.min.y+j; x < r.max.x-j; x++) { + pixel(dst, (Point){x, y}, col); + } + for (x = r.max.x-1-j, y = r.min.y+j; y < r.max.y-j; y++) { + pixel(dst, (Point){x, y}, col); + } + for (x = r.max.x-1-j, y = r.max.y-1-j; x >= r.min.x+j; x--) { + pixel(dst, (Point){x, y}, col); + } + for (x = r.min.x+j, y = r.max.y-1-j; y >= r.min.y+j; y--) { + pixel(dst, (Point){x, y}, col); + } } } diff --git a/sys/src/kernel/main.c b/sys/src/kernel/main.c @@ -15,12 +15,12 @@ kernel_main(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop) gop->Mode->Info->PixelsPerScanLine, gop->Mode->Info->PixelFormat ) < 0) { - // can't print to console. + // still can't print to console. goto halt; } Window win0 = { - .fb = root_window.fb + (100 * root_window.ppsl + 150), + .fb = root_window.fb + (150 + 100 * root_window.ppsl), .fg = 0x0, .bg = 0xffffea00, .hres = 400, @@ -37,14 +37,12 @@ kernel_main(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop) .pos = (Point){0, 0} }; Rectangle rect = { - .min = (Point){100, 100}, - .max = (Point){500, 400}, + .min = (Point){150, 100}, + .max = (Point){150 + 400, 100 + 300} }; - border(&root_window, rect, 0x00ff8000); - rect.min.x += 500; - rect.max.x += 500; - fill(&root_window, rect, 0x0080ff00); clear(&win0); + border(&root_window, rect, 5, 0xaa666600); + border(&root_window, rect, 0, 0x00000000); cons_printf(&con0, "hello window!\n"); halt: