From 674d4b382c70eefb2bc1f4f6982ce7e6bde026a3 Mon Sep 17 00:00:00 2001 From: Yann MAGNIN Date: Tue, 28 Jun 2022 17:34:00 +0200 Subject: [PATCH] VxKernel 0.6.0-16 : Add rectangle API + fix horizontal line @add <> include/vhex/display/draw/rect | add filled rectangle API <> src/display/draw/drect | add filled rectangle drawing API @update <> include/vhex/display/draw/text | merge halign and valign argument | add special alignment flags @fix <> src/display/font | fix height for text display geometry <> src/display/text | fix alignment calculation --- include/vhex/display/draw.h | 1 + include/vhex/display/draw/rect.h | 22 ++++++++ include/vhex/display/text/render.h | 16 +++--- src/display/draw/drect.c | 91 ++++++++++++++---------------- src/display/font/information.c | 2 +- src/display/text/render/dprint.c | 6 +- src/display/text/render/dtext.c | 12 ++-- 7 files changed, 84 insertions(+), 66 deletions(-) create mode 100644 include/vhex/display/draw/rect.h diff --git a/include/vhex/display/draw.h b/include/vhex/display/draw.h index 4412453..83bd814 100644 --- a/include/vhex/display/draw.h +++ b/include/vhex/display/draw.h @@ -1,3 +1,4 @@ #include #include #include +#include diff --git a/include/vhex/display/draw/rect.h b/include/vhex/display/draw/rect.h new file mode 100644 index 0000000..e67612a --- /dev/null +++ b/include/vhex/display/draw/rect.h @@ -0,0 +1,22 @@ +#ifndef __VHEX_DISPLAY_DRAW_RECT__ +# define __VHEX_DISPLAY_DRAW_RECT__ + +//--- +// User-level API +//--- + +/* drect_filled() : draw filled rectangle */ +extern void drect_filled(int color, int x1, int y1, int x2, int y2); + +//--- +// Kernel-level API +//--- + +/* drect_filled() : draw filled rectangle */ +extern void drect_filled_render( + dsurface_t *surface, + int color, + int x1, int y1, int x2, int y2 +); + +#endif /* __VHEX_DISPLAY_DRAW_RECT__ */ diff --git a/include/vhex/display/text/render.h b/include/vhex/display/text/render.h index 255c2fe..8b44b86 100644 --- a/include/vhex/display/text/render.h +++ b/include/vhex/display/text/render.h @@ -9,20 +9,20 @@ be relative to the rendered string. */ enum { /* Horizontal settings: default in dtext() is DTEXT_LEFT */ - DTEXT_LEFT = 0, - DTEXT_CENTER = 1, - DTEXT_RIGHT = 2, + DTEXT_LEFT = 0x01, + DTEXT_CENTER = 0x02, + DTEXT_RIGHT = 0x04, /* Vertical settings: default in dtext() is DTEXT_TOP */ - DTEXT_TOP = 0, - DTEXT_MIDDLE = 1, - DTEXT_BOTTOM = 2, + DTEXT_TOP = 0x10, + DTEXT_MIDDLE = 0x20, + DTEXT_BOTTOM = 0x40, }; /* dtext_opt(): Display a string of text */ extern did_t dtext_opt( int x, int y, int fg, int bg, - int halign, int valign, + int align, char const * const str, int size ); @@ -33,7 +33,7 @@ extern did_t dtext(int x, int y, int fg, char const * const text); extern did_t dprint_opt( int x, int y, int fg, int bg, - int halign, int valign, + int align, char const * const str, ... ); diff --git a/src/display/draw/drect.c b/src/display/draw/drect.c index fda8f21..d0d540a 100644 --- a/src/display/draw/drect.c +++ b/src/display/draw/drect.c @@ -1,55 +1,50 @@ -#if 0 #include #include -#include -/* drect() - fill a rectangle of the screen */ -void drect(int x1, int y1, int x2, int y2, int color) -{ - extern uint16_t vhex_vram[]; +//--- +// Kernel-level API +//--- - if(color == C_NONE) return; +/* drect_filled() : draw filled rectangle */ +void drect_filled_render( + dsurface_t *surface, + int color, + int x1, int y1, int x2, int y2 +) { + if (y1 > y2) swap(y1, y2); - if(x1 > x2) swap(x1, x2); - if(y1 > y2) swap(y1, y2); - - /* Order and bounds */ - if(x1 >= 396 || x2 < 0 || y1 >= 224 || y2 < 0) return; - if(x1 < 0) x1 = 0; - if(x2 >= 396) x2 = 395; - if(y1 < 0) y1 = 0; - if(y2 >= 224) y2 = 223; - - /* The method is exactly like dhline(). I first handle odd endpoints, - then write longwords for the longest section */ - - uint16_t *base = vhex_vram + 396 * y1; - int height = y2 - y1 + 1; - - /* Now copy everything that's left as longwords */ - - int ax1 = x1 + (x1 & 1); - int ax2 = (x2 + 1) & ~1; - - uint32_t *v = (void *)(base + ax1); - uint32_t op = (color << 16) | color; - int width = (ax2 - ax1) >> 1; - - if(color == C_INVERT) for(int h = height; h; h--) - { - base[x1] ^= 0xffff; - base[x2] ^= 0xffff; - for(int w = 0; w < width; w++) v[w] ^= 0xffffffff; - v += 198; - base += 396; - } - else for(int h = height; h; h--) - { - base[x1] = color; - base[x2] = color; - for(int w = 0; w < width; w++) v[w] = op; - v += 198; - base += 396; + for (int y = y1 ; y <= y2 ; ++y) { + dhline_render(surface, y, x1, x2, color); } } -#endif + +//--- +// Dstack-level API +//--- + +/* drect_filled_dstack() : dstack API wrapper */ +static void drect_filled_dstack(dsurface_t *surface, uint32_t *args) +{ + drect_filled_render( + surface, + (int)args[0], + (int)args[1], + (int)args[2], + (int)args[3], + (int)args[4] + ); +} + +//--- +// User-level API +//--- + +/* plasma() : draw plasma effect */ +void drect_filled(int color, int x1, int y1, int x2, int y2) +{ + dstack_add_action( + DSTACK_CALL(&drect_filled_dstack, color, x1, y1, x2, y2), + NULL, + NULL + ); +} diff --git a/src/display/font/information.c b/src/display/font/information.c index f3900a7..be78115 100644 --- a/src/display/font/information.c +++ b/src/display/font/information.c @@ -135,7 +135,7 @@ int dfont_text_geometry( /* set geometry information */ if (w != NULL) *w = mx - font->char_spacing; - if (h != NULL) *h = y; + if (h != NULL) *h = y + font->glyph.height; if (size != NULL) *size = length; return (0); } diff --git a/src/display/text/render/dprint.c b/src/display/text/render/dprint.c index 230041e..d343524 100644 --- a/src/display/text/render/dprint.c +++ b/src/display/text/render/dprint.c @@ -18,14 +18,14 @@ did_t dprint(int x, int y, int fg, char const * const text, ...) vsnprintf(buff, 1024, text, ap); va_end(ap); - return (dtext_opt(x, y, fg, C_NONE, DTEXT_LEFT, DTEXT_TOP, buff, -1)); + return (dtext_opt(x, y, fg, C_NONE, DTEXT_LEFT | DTEXT_TOP, buff, -1)); } /* dprint_opt(): Display a string of text */ did_t dprint_opt( int x, int y, int fg, int bg, - int halign, int valign, + int align, char const *text, ... ) { va_list ap; @@ -35,5 +35,5 @@ did_t dprint_opt( vsnprintf(buff, 1024, text, ap); va_end(ap); - return (dtext_opt(x, y, fg, bg, halign, valign, buff, -1)); + return (dtext_opt(x, y, fg, bg, align, buff, -1)); } diff --git a/src/display/text/render/dtext.c b/src/display/text/render/dtext.c index 11fd8d0..f1b7971 100644 --- a/src/display/text/render/dtext.c +++ b/src/display/text/render/dtext.c @@ -154,7 +154,7 @@ void dtext_dstack(dsurface_t *surface, uint32_t *arg) did_t dtext_opt( int x, int y, int fg, int bg, - int halign, int valign, + int align, char const * const str, int size ) { size_t width; @@ -172,10 +172,10 @@ did_t dtext_opt( } /* handle position */ - if (halign == DTEXT_CENTER) x = x - (width / 2); - if (halign == DTEXT_RIGHT) x = x - (width); - if (valign == DTEXT_CENTER) y = y - (height / 2); - if (valign == DTEXT_BOTTOM) y = y - (height); + if (align & DTEXT_CENTER) x = x - (width / 2); + if (align & DTEXT_RIGHT) x = x - (width); + if (align & DTEXT_MIDDLE) y = y - (height / 2); + if (align & DTEXT_BOTTOM) y = y - (height); /* register the string */ real_str = dtext_info_register(str); @@ -196,5 +196,5 @@ did_t dtext_opt( /* dtext() : display text information */ did_t dtext(int x, int y, int fg, char const * const text) { - return (dtext_opt(x, y, fg, C_NONE, DTEXT_LEFT, DTEXT_TOP, text, -1)); + return (dtext_opt(x, y, fg, C_NONE, DTEXT_LEFT | DTEXT_TOP, text, -1)); }