screenbuffer.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2006 Josef Cejka
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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 

Generated on Thu Jun 2 07:45:46 2011 for HelenOS/USB by  doxygen 1.4.7