00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00035 #ifndef LIBC_SCREENBUFFER_H__
00036 #define LIBC_SCREENBUFFER_H__
00037
00038 #include <stdint.h>
00039 #include <sys/types.h>
00040 #include <bool.h>
00041
00042 typedef enum {
00043 at_style,
00044 at_idx,
00045 at_rgb
00046 } attr_type_t;
00047
00048 typedef struct {
00049 uint8_t style;
00050 } attr_style_t;
00051
00052 typedef struct {
00053 uint8_t fg_color;
00054 uint8_t bg_color;
00055 uint8_t flags;
00056 } attr_idx_t;
00057
00058 typedef struct {
00059 uint32_t bg_color;
00060 uint32_t fg_color;
00061 } attr_rgb_t;
00062
00063 typedef union {
00064 attr_style_t s;
00065 attr_idx_t i;
00066 attr_rgb_t r;
00067 } attr_val_t;
00068
00069 typedef struct {
00070 attr_type_t t;
00071 attr_val_t a;
00072 } attrs_t;
00073
00075 typedef struct {
00076 wchar_t character;
00077 attrs_t attrs;
00078 } keyfield_t;
00079
00082 typedef struct {
00083 keyfield_t *buffer;
00085 sysarg_t size_x;
00086 sysarg_t size_y;
00089 sysarg_t position_x;
00090 sysarg_t position_y;
00091
00092 attrs_t attrs;
00093 size_t top_line;
00095 bool is_cursor_visible;
00096 } screenbuffer_t;
00097
00110 static inline keyfield_t *get_field_at(screenbuffer_t *scr, sysarg_t x, sysarg_t y)
00111 {
00112 return scr->buffer + x + ((y + scr->top_line) % scr->size_y) * scr->size_x;
00113 }
00114
00123 static inline bool attrs_same(attrs_t a1, attrs_t a2)
00124 {
00125 if (a1.t != a2.t)
00126 return false;
00127
00128 switch (a1.t) {
00129 case at_style:
00130 return (a1.a.s.style == a2.a.s.style);
00131 case at_idx:
00132 return (a1.a.i.fg_color == a2.a.i.fg_color)
00133 && (a1.a.i.bg_color == a2.a.i.bg_color)
00134 && (a1.a.i.flags == a2.a.i.flags);
00135 case at_rgb:
00136 return (a1.a.r.fg_color == a2.a.r.fg_color)
00137 && (a1.a.r.bg_color == a2.a.r.bg_color);
00138 }
00139
00140 return false;
00141 }
00142
00143 extern void screenbuffer_putchar(screenbuffer_t *, wchar_t);
00144 extern screenbuffer_t *screenbuffer_init(screenbuffer_t *, sysarg_t, sysarg_t);
00145
00146 extern void screenbuffer_clear(screenbuffer_t *);
00147 extern void screenbuffer_clear_line(screenbuffer_t *, sysarg_t);
00148 extern void screenbuffer_copy_buffer(screenbuffer_t *, keyfield_t *);
00149 extern void screenbuffer_goto(screenbuffer_t *, sysarg_t, sysarg_t);
00150 extern void screenbuffer_set_style(screenbuffer_t *, uint8_t);
00151 extern void screenbuffer_set_color(screenbuffer_t *, uint8_t, uint8_t, uint8_t);
00152 extern void screenbuffer_set_rgb_color(screenbuffer_t *, uint32_t, uint32_t);
00153
00154 #endif
00155