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 <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  

Generated on Sun Jun 18 18:00:18 2006 for HelenOS Userspace (ia64) by  doxygen 1.4.6