diff options
author | Marvin Borner | 2020-04-29 15:26:21 +0200 |
---|---|---|
committer | Marvin Borner | 2020-04-29 15:26:21 +0200 |
commit | 396d7d303d3bf0e796d0c817883ec1dec928352a (patch) | |
tree | 69d79c31ca94da7aa3089709be08f1d959023472 /src/userspace | |
parent | 4f3c75d23188bd480739d6d1514543c95cfe3399 (diff) |
Some work on the libgui
Diffstat (limited to 'src/userspace')
-rw-r--r-- | src/userspace/libgui/draw.c | 21 | ||||
-rw-r--r-- | src/userspace/libgui/gui.h | 44 | ||||
-rw-r--r-- | src/userspace/libgui/init.c | 12 | ||||
-rw-r--r-- | src/userspace/libgui/util.c | 33 |
4 files changed, 109 insertions, 1 deletions
diff --git a/src/userspace/libgui/draw.c b/src/userspace/libgui/draw.c new file mode 100644 index 0000000..adcdec2 --- /dev/null +++ b/src/userspace/libgui/draw.c @@ -0,0 +1,21 @@ +#include <stdint.h> +#include <gui.h> + +void gui_draw_rectangle(int x1, int y1, int x2, int y2, const u32 color[3]) +{ + int pos1 = x1 * vbe_bpl + y1 * vbe_pitch; + char *draw = (char *)&fb[pos1]; + for (int i = 0; i <= y2 - y1; i++) { + for (int j = 0; j <= x2 - x1; j++) { + draw[vbe_bpl * j] = (char)color[2]; + draw[vbe_bpl * j + 1] = (char)color[1]; + draw[vbe_bpl * j + 2] = (char)color[0]; + } + draw += vbe_pitch; + } +} + +void gui_screen_clear() +{ + gui_draw_rectangle(0, 0, vbe_width - 1, vbe_height - 1, terminal_background); +}
\ No newline at end of file diff --git a/src/userspace/libgui/gui.h b/src/userspace/libgui/gui.h index b056dea..d210999 100644 --- a/src/userspace/libgui/gui.h +++ b/src/userspace/libgui/gui.h @@ -3,6 +3,16 @@ #include <stdint.h> +struct vbe_mode_info { + u16 attributes; + u16 pitch; + u16 width; + u16 height; + u8 bpp; + u8 memory_model; + u32 framebuffer; +}; + struct font { u16 font_32[758][32]; u16 font_24[758][24]; @@ -11,12 +21,44 @@ struct font { }; struct pointers { - u8 *fb; + struct vbe_mode_info *mode_info; struct font *font; }; +u32 terminal_color[3]; +u32 terminal_background[3]; +enum gui_color { + gui_black = 0x1d1f24, + gui_red = 0xE06C75, + gui_green = 0x98C379, + gui_yellow = 0xE5C07B, + gui_blue = 0x61AFEF, + gui_magenta = 0xC678DD, + gui_cyan = 0x56B6C2, + gui_white = 0xABB2BF, + gui_dark_black = 0x3E4452, + gui_dark_red = 0xBE5046, + gui_dark_green = 0x98C379, + gui_dark_yellow = 0xD19A66, + gui_dark_blue = 0x61AFEF, + gui_dark_magenta = 0xC678DD, + gui_dark_cyan = 0x56B6C2, + gui_dark_white = 0x5C6370, +}; + +u8 *fb; +int vbe_width; +int vbe_height; +int vbe_pitch; +int vbe_bpl; + struct pointers *pointers; void gui_init(); +void gui_draw_rectangle(int x1, int y1, int x2, int y2, const u32 color[3]); +void gui_screen_clear(); + +void gui_convert_color(u32 *color_array, u32 color); + #endif
\ No newline at end of file diff --git a/src/userspace/libgui/init.c b/src/userspace/libgui/init.c index dfc42eb..7cd1fc3 100644 --- a/src/userspace/libgui/init.c +++ b/src/userspace/libgui/init.c @@ -4,7 +4,19 @@ struct pointers *pointers; +u32 terminal_color[3] = { 0xab, 0xb2, 0xbf }; +u32 terminal_background[3] = { 0x1d, 0x1f, 0x24 }; + void gui_init() { pointers = syscall_pointers(); + + return; // TODO: Fix GUI page fault + vbe_width = pointers->mode_info->width; + vbe_height = pointers->mode_info->height; + vbe_pitch = pointers->mode_info->pitch; + vbe_bpl = pointers->mode_info->bpp >> 3; + fb = pointers->mode_info->framebuffer; + + gui_screen_clear(); }
\ No newline at end of file diff --git a/src/userspace/libgui/util.c b/src/userspace/libgui/util.c new file mode 100644 index 0000000..5019175 --- /dev/null +++ b/src/userspace/libgui/util.c @@ -0,0 +1,33 @@ +#include <stdint.h> +#include <gui.h> + +void gui_convert_color(u32 *color_array, u32 color) +{ + u8 red = (u8)((color >> 16) & 255); + u8 green = (u8)((color >> 8) & 255); + u8 blue = (u8)(color & 255); + + if ((vbe_bpl << 3) == 8) { + u32 new_color = + ((red * 7 / 255) << 5) + ((green * 7 / 255) << 2) + (blue * 3 / 255); + color_array[0] = (new_color >> 16) & 255; + color_array[1] = (new_color >> 8) & 255; + color_array[2] = new_color & 255; + } else if ((vbe_bpl << 3) == 16) { + u32 new_color = + (((red & 0b11111000) << 8) + ((green & 0b11111100) << 3) + (blue >> 3)); + color_array[0] = (new_color >> 16) & 255; + color_array[1] = (new_color >> 8) & 255; + color_array[2] = new_color & 255; + } else if ((vbe_bpl << 3) == 24 || (vbe_bpl << 3) == 32) { + color_array[0] = red; + color_array[1] = green; + color_array[2] = blue; + } +} + +void gui_set_color(u32 color) +{ + gui_convert_color(terminal_color, color); + gui_convert_color(terminal_background, gui_black); +}
\ No newline at end of file |