screenbuffer.h

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

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