diff options
author | Alex Auvolat <alex@adnab.me> | 2015-03-11 14:35:54 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2015-03-11 14:35:54 +0100 |
commit | 5e9251bd48acafff575ed1c740e4dc05ec175508 (patch) | |
tree | 00f95aafd4e0399bcb1858f24b7e79b06a216f30 /src/lib/include | |
parent | 052ca1dc143b1df2800f9c4e43daf80c96fb472e (diff) | |
download | kogata-5e9251bd48acafff575ed1c740e4dc05ec175508.tar.gz kogata-5e9251bd48acafff575ed1c740e4dc05ec175508.zip |
Add simple drawing code & font loading.
Diffstat (limited to 'src/lib/include')
-rw-r--r-- | src/lib/include/draw.h | 62 | ||||
-rw-r--r-- | src/lib/include/proto/font_file.h | 14 |
2 files changed, 76 insertions, 0 deletions
diff --git a/src/lib/include/draw.h b/src/lib/include/draw.h new file mode 100644 index 0000000..893c5a3 --- /dev/null +++ b/src/lib/include/draw.h @@ -0,0 +1,62 @@ +#pragma once + +#include <syscall.h> +#include <proto/fb.h> + +// ---- Generic drawing functions + +// ---- Data structures + +typedef struct { + fb_info_t geom; + + fd_t fd; + uint8_t* data; +} fb_t; + +typedef struct font font_t; + +typedef uint32_t color_t; // a color is always linked to a FB on which it is to be applied + +// ---- Buffer creation + +fb_t *g_fb_from_file(fd_t file, fb_info_t *geom); +fb_t *g_fb_from_mem(uint8_t* region, fb_info_t *geom); + +void g_delete_fb(fb_t *fb); + +// ---- Color manipulation + +color_t g_color_rgb(fb_t *f, uint8_t r, uint8_t g, uint8_t b); + +// ---- Drawing primitives + +void g_plot(fb_t *fb, int x, int y, color_t c); + +void g_hline(fb_t *fb, int x, int y, int w, color_t c); // horizontal line +void g_vline(fb_t *fb, int x, int y, int h, color_t c); // vertical line +void g_line(fb_t *fb, int x1, int y1, int x2, int y2, color_t c); + +void g_rect(fb_t *fb, int x, int y, int w, int h, color_t c); +void g_fillrect(fb_t *fb, int x, int y, int w, int h, color_t c); +void g_rect_r(fb_t *fb, fb_region_t reg, color_t c); +void g_fillrect_r(fb_t *fb, fb_region_t reg, color_t c); + +void g_circle(fb_t *fb, int cx, int cy, int r, color_t c); +void g_fillcircle(fb_t *fb, int cx, int cy, int r, color_t c); + +void g_blit(fb_t *dst, int x, int y, fb_t *src); +void g_blit_region(fb_t *dst, int x, int y, fb_t *src, fb_region_t reg); + +// ---- Text manipulation + +font_t *g_load_font(const char* fontname); +void g_free_font(font_t *f); + +int g_text_width(font_t *f, const char* text); +int g_text_height(font_t *f, const char* text); + +void g_write(fb_t *fb, int x, int y, const char* text, font_t *font, color_t c); + + +/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/lib/include/proto/font_file.h b/src/lib/include/proto/font_file.h new file mode 100644 index 0000000..e57c0ab --- /dev/null +++ b/src/lib/include/proto/font_file.h @@ -0,0 +1,14 @@ +#pragma once + +#include <stdint.h> +#include <stddef.h> + +#define ASCII_BITMAP_FONT_MAGIC 0xD184C274 + +typedef struct { + uint32_t magic; + uint16_t cw, ch; + uint32_t nchars; +} ascii_bitmap_font_header; + +/* vim: set ts=4 sw=4 tw=0 noet :*/ |