Rev 2787 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2787 | Rev 4377 | ||
|---|---|---|---|
| Line 33... | Line 33... | ||
| 33 | */ |
33 | */ |
| 34 | 34 | ||
| 35 | #ifndef __SCREENBUFFER_H__ |
35 | #ifndef __SCREENBUFFER_H__ |
| 36 | #define __SCREENBUFFER_H__ |
36 | #define __SCREENBUFFER_H__ |
| 37 | 37 | ||
| - | 38 | #include <stdint.h> |
|
| - | 39 | #include <sys/types.h> |
|
| 38 | 40 | ||
| 39 | #define DEFAULT_FOREGROUND 0x0 /**< default console foreground color */ |
41 | #define DEFAULT_FOREGROUND 0x0 /**< default console foreground color */ |
| 40 | #define DEFAULT_BACKGROUND 0xf0f0f0 /**< default console background color */ |
42 | #define DEFAULT_BACKGROUND 0xf0f0f0 /**< default console background color */ |
| 41 | 43 | ||
| 42 | typedef struct { |
44 | typedef struct { |
| - | 45 | uint8_t style; |
|
| - | 46 | } attr_style_t; |
|
| - | 47 | ||
| - | 48 | typedef struct { |
|
| - | 49 | uint8_t fg_color; |
|
| - | 50 | uint8_t bg_color; |
|
| - | 51 | uint8_t flags; |
|
| - | 52 | } attr_idx_t; |
|
| - | 53 | ||
| - | 54 | typedef struct { |
|
| 43 | unsigned int bg_color; /**< background color */ |
55 | uint32_t bg_color; /**< background color */ |
| 44 | unsigned int fg_color; /**< foreground color */ |
56 | uint32_t fg_color; /**< foreground color */ |
| - | 57 | } attr_rgb_t; |
|
| - | 58 | ||
| - | 59 | typedef struct { |
|
| - | 60 | enum { |
|
| - | 61 | at_style, |
|
| - | 62 | at_idx, |
|
| - | 63 | at_rgb |
|
| - | 64 | } t; |
|
| - | 65 | union { |
|
| - | 66 | attr_style_t s; |
|
| - | 67 | attr_idx_t i; |
|
| - | 68 | attr_rgb_t r; |
|
| - | 69 | } a; |
|
| 45 | } style_t; |
70 | } attrs_t; |
| 46 | 71 | ||
| 47 | /** One field on screen. It contain one character and its attributes. */ |
72 | /** One field on screen. It contain one character and its attributes. */ |
| 48 | typedef struct { |
73 | typedef struct { |
| 49 | char character; /**< Character itself */ |
74 | wchar_t character; /**< Character itself */ |
| 50 | style_t style; /**< Character`s attributes */ |
75 | attrs_t attrs; /**< Character`s attributes */ |
| 51 | } keyfield_t; |
76 | } keyfield_t; |
| 52 | 77 | ||
| 53 | /** Structure for buffering state of one virtual console. |
78 | /** Structure for buffering state of one virtual console. |
| 54 | */ |
79 | */ |
| 55 | typedef struct { |
80 | typedef struct { |
| 56 | keyfield_t *buffer; /**< Screen content - characters and its style. Used as cyclyc buffer. */ |
81 | keyfield_t *buffer; /**< Screen content - characters and their attributes. Used as a circular buffer. */ |
| 57 | unsigned int size_x, size_y; /**< Number of columns and rows */ |
82 | unsigned int size_x, size_y; /**< Number of columns and rows */ |
| 58 | unsigned int position_x, position_y; /**< Coordinates of last printed character for determining cursor position */ |
83 | unsigned int position_x, position_y; /**< Coordinates of last printed character for determining cursor position */ |
| 59 | style_t style; /**< Current style */ |
84 | attrs_t attrs; /**< Current attributes. */ |
| 60 | unsigned int top_line; /**< Points to buffer[][] line that will be printed at screen as the first line */ |
85 | unsigned int top_line; /**< Points to buffer[][] line that will be printed at screen as the first line */ |
| 61 | unsigned char is_cursor_visible; /**< Cursor state - default is visible */ |
86 | unsigned char is_cursor_visible; /**< Cursor state - default is visible */ |
| 62 | } screenbuffer_t; |
87 | } screenbuffer_t; |
| 63 | 88 | ||
| 64 | /** Returns keyfield for position on screen. Screenbuffer->buffer is cyclic buffer so we must couted in index of the topmost line. |
89 | /** Returns keyfield for position on screen. Screenbuffer->buffer is cyclic buffer so we must couted in index of the topmost line. |
| 65 | * @param scr screenbuffer |
90 | * @param scr screenbuffer |
| 66 | * @param x position on screen |
91 | * @param x position on screen |
| 67 | * @param y position on screen |
92 | * @param y position on screen |
| 68 | * @return keyfield structure with character and its attributes on x,y |
93 | * @return keyfield structure with character and its attributes on x,y |
| 69 | */ |
94 | */ |
| 70 | static inline keyfield_t *get_field_at(screenbuffer_t *scr, unsigned int x, unsigned int y) |
95 | static inline keyfield_t *get_field_at(screenbuffer_t *scr, unsigned int x, unsigned int y) |
| 71 | { |
96 | { |
| 72 | return scr->buffer + x + ((y + scr->top_line) % scr->size_y) * scr->size_x; |
97 | return scr->buffer + x + ((y + scr->top_line) % scr->size_y) * scr->size_x; |
| 73 | } |
98 | } |
| 74 | 99 | ||
| 75 | /** Compares two styles. |
100 | /** Compares two sets of attributes. |
| 76 | * @param s1 first style |
101 | * @param s1 first style |
| 77 | * @param s2 second style |
102 | * @param s2 second style |
| 78 | * @return nonzero on equality |
103 | * @return nonzero on equality |
| 79 | */ |
104 | */ |
| 80 | static inline int style_same(style_t s1, style_t s2) |
105 | static inline int attrs_same(attrs_t a1, attrs_t a2) |
| 81 | { |
106 | { |
| - | 107 | if (a1.t != a2.t) return 0; |
|
| - | 108 | ||
| - | 109 | switch (a1.t) { |
|
| - | 110 | case at_style: return a1.a.s.style == a2.a.s.style; |
|
| - | 111 | case at_idx: return a1.a.i.fg_color == a2.a.i.fg_color && |
|
| - | 112 | a1.a.i.bg_color == a2.a.i.bg_color && |
|
| - | 113 | a1.a.i.flags == a2.a.i.flags; |
|
| 82 | return s1.fg_color == s2.fg_color && s1.bg_color == s2.bg_color; |
114 | case at_rgb: return a1.a.r.fg_color == a2.a.r.fg_color && |
| - | 115 | a1.a.r.bg_color == a2.a.r.bg_color; |
|
| - | 116 | } |
|
| 83 | } |
117 | } |
| 84 | 118 | ||
| 85 | 119 | ||
| 86 | void screenbuffer_putchar(screenbuffer_t *scr, char c); |
120 | void screenbuffer_putchar(screenbuffer_t *scr, wchar_t c); |
| 87 | screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, int size_x, int size_y); |
121 | screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, int size_x, int size_y); |
| 88 | 122 | ||
| 89 | void screenbuffer_clear(screenbuffer_t *scr); |
123 | void screenbuffer_clear(screenbuffer_t *scr); |
| 90 | void screenbuffer_clear_line(screenbuffer_t *scr, unsigned int line); |
124 | void screenbuffer_clear_line(screenbuffer_t *scr, unsigned int line); |
| 91 | void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest); |
125 | void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest); |
| 92 | void screenbuffer_goto(screenbuffer_t *scr, unsigned int x, unsigned int y); |
126 | void screenbuffer_goto(screenbuffer_t *scr, unsigned int x, unsigned int y); |
| - | 127 | void screenbuffer_set_style(screenbuffer_t *scr, int style); |
|
| 93 | void screenbuffer_set_style(screenbuffer_t *scr, unsigned int fg_color, unsigned int bg_color); |
128 | void screenbuffer_set_color(screenbuffer_t *scr, unsigned int fg_color, |
| - | 129 | unsigned int bg_color, unsigned int attr); |
|
| - | 130 | void screenbuffer_set_rgb_color(screenbuffer_t *scr, unsigned int fg_color, |
|
| - | 131 | unsigned int bg_color); |
|
| 94 | 132 | ||
| 95 | #endif |
133 | #endif |
| 96 | 134 | ||
| 97 | 135 | ||
| 98 | /** @} |
136 | /** @} |