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 <screenbuffer.h>
00036 #include <malloc.h>
00037 #include <unistd.h>
00038
00043 void screenbuffer_putchar(screenbuffer_t *scr, char c)
00044 {
00045 keyfield_t *field;
00046
00047 field = get_field_at(scr, scr->position_x, scr->position_y);
00048
00049 field->character = c;
00050 field->style = scr->style;
00051 }
00052
00059 screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, int size_x, int size_y)
00060 {
00061 if ((scr->buffer = (keyfield_t *)malloc(sizeof(keyfield_t) * size_x * size_y)) == NULL) {
00062 return NULL;
00063 }
00064
00065 scr->size_x = size_x;
00066 scr->size_y = size_y;
00067 scr->style.fg_color = DEFAULT_FOREGROUND;
00068 scr->style.bg_color = DEFAULT_BACKGROUND;
00069 scr->is_cursor_visible = 1;
00070
00071 screenbuffer_clear(scr);
00072
00073 return scr;
00074 }
00075
00079 void screenbuffer_clear(screenbuffer_t *scr)
00080 {
00081 unsigned int i;
00082
00083 for (i = 0; i < (scr->size_x * scr->size_y); i++) {
00084 scr->buffer[i].character = ' ';
00085 scr->buffer[i].style = scr->style;
00086 }
00087
00088 scr->top_line = 0;
00089 scr->position_y = 0;
00090 scr->position_x = 0;
00091 }
00092
00097 void screenbuffer_clear_line(screenbuffer_t *scr, unsigned int line)
00098 {
00099 unsigned int i;
00100
00101 for (i = 0; i < scr->size_x; i++) {
00102 scr->buffer[i + line*scr->size_x].character = ' ';
00103 scr->buffer[i + line*scr->size_x].style = scr->style;
00104 }
00105 }
00106
00111 void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest)
00112 {
00113 unsigned int i;
00114
00115 for (i = 0; i < scr->size_x * scr->size_y; i++) {
00116 dest[i] = scr->buffer[i];
00117 }
00118 }
00119
00125 void screenbuffer_goto(screenbuffer_t *scr, unsigned int x, unsigned int y)
00126 {
00127 scr->position_x = x % scr->size_x;
00128 scr->position_y = y % scr->size_y;
00129 }
00130
00136 void screenbuffer_set_style(screenbuffer_t *scr, unsigned int fg_color, unsigned int bg_color)
00137 {
00138 scr->style.fg_color = fg_color;
00139 scr->style.bg_color = bg_color;
00140 }
00141
00142