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 #include <io/style.h>
00036 #include <io/screenbuffer.h>
00037 #include <malloc.h>
00038 #include <unistd.h>
00039
00049 void screenbuffer_putchar(screenbuffer_t *scr, wchar_t ch)
00050 {
00051 keyfield_t *field =
00052 get_field_at(scr, scr->position_x, scr->position_y);
00053
00054 field->character = ch;
00055 field->attrs = scr->attrs;
00056 }
00057
00069 screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, sysarg_t size_x,
00070 sysarg_t size_y)
00071 {
00072 scr->buffer = (keyfield_t *) malloc(sizeof(keyfield_t) * size_x * size_y);
00073 if (!scr->buffer)
00074 return NULL;
00075
00076 scr->size_x = size_x;
00077 scr->size_y = size_y;
00078 scr->attrs.t = at_style;
00079 scr->attrs.a.s.style = STYLE_NORMAL;
00080 scr->is_cursor_visible = 1;
00081
00082 screenbuffer_clear(scr);
00083
00084 return scr;
00085 }
00086
00092 void screenbuffer_clear(screenbuffer_t *scr)
00093 {
00094 size_t i;
00095
00096 for (i = 0; i < (scr->size_x * scr->size_y); i++) {
00097 scr->buffer[i].character = ' ';
00098 scr->buffer[i].attrs = scr->attrs;
00099 }
00100
00101 scr->top_line = 0;
00102 scr->position_x = 0;
00103 scr->position_y = 0;
00104 }
00105
00112 void screenbuffer_clear_line(screenbuffer_t *scr, sysarg_t line)
00113 {
00114 sysarg_t x;
00115
00116 for (x = 0; x < scr->size_x; x++) {
00117 scr->buffer[x + line * scr->size_x].character = ' ';
00118 scr->buffer[x + line * scr->size_x].attrs = scr->attrs;
00119 }
00120 }
00121
00128 void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest)
00129 {
00130 size_t i;
00131
00132 for (i = 0; i < (scr->size_x * scr->size_y); i++)
00133 dest[i] = scr->buffer[i];
00134 }
00135
00143 void screenbuffer_goto(screenbuffer_t *scr, sysarg_t x, sysarg_t y)
00144 {
00145 scr->position_x = x % scr->size_x;
00146 scr->position_y = y % scr->size_y;
00147 }
00148
00156 void screenbuffer_set_style(screenbuffer_t *scr, uint8_t style)
00157 {
00158 scr->attrs.t = at_style;
00159 scr->attrs.a.s.style = style;
00160 }
00161
00169 void screenbuffer_set_color(screenbuffer_t *scr, uint8_t fg_color,
00170 uint8_t bg_color, uint8_t flags)
00171 {
00172 scr->attrs.t = at_idx;
00173 scr->attrs.a.i.fg_color = fg_color;
00174 scr->attrs.a.i.bg_color = bg_color;
00175 scr->attrs.a.i.flags = flags;
00176 }
00177
00185 void screenbuffer_set_rgb_color(screenbuffer_t *scr, uint32_t fg_color,
00186 uint32_t bg_color)
00187 {
00188 scr->attrs.t = at_rgb;
00189 scr->attrs.a.r.fg_color = fg_color;
00190 scr->attrs.a.r.bg_color = bg_color;
00191 }
00192