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
This commit is contained in:
Yann MAGNIN 2022-06-28 17:34:00 +02:00
parent 70d31c5268
commit 674d4b382c
7 changed files with 84 additions and 66 deletions

View File

@ -1,3 +1,4 @@
#include <vhex/display/draw/circle.h>
#include <vhex/display/draw/pixel.h>
#include <vhex/display/draw/line.h>
#include <vhex/display/draw/rect.h>

View File

@ -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__ */

View File

@ -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, ...
);

View File

@ -1,55 +1,50 @@
#if 0
#include <vhex/display.h>
#include <vhex/defs/utils.h>
#include <vhex/defs/types.h>
/* 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
);
}

View File

@ -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);
}

View File

@ -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));
}

View File

@ -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));
}