Rev 4211 | Rev 4456 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 4211 | Rev 4421 | ||
|---|---|---|---|
| Line 25... | Line 25... | ||
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
27 | */ |
| 28 | 28 | ||
| 29 | /** @addtogroup console |
29 | /** @addtogroup console |
| 30 | * @{ |
30 | * @{ |
| 31 | */ |
31 | */ |
| 32 | /** @file |
32 | /** @file |
| 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> |
38 | #include <stdint.h> |
| 39 | #include <sys/types.h> |
39 | #include <sys/types.h> |
| 40 | 40 | ||
| 41 | #define DEFAULT_FOREGROUND 0x0 /**< default console foreground color */ |
41 | #define DEFAULT_FOREGROUND 0x0 /**< default console foreground color */ |
| 42 | #define DEFAULT_BACKGROUND 0xf0f0f0 /**< default console background color */ |
42 | #define DEFAULT_BACKGROUND 0xf0f0f0 /**< default console background color */ |
| 43 | 43 | ||
| 44 | typedef struct { |
44 | typedef struct { |
| 45 | uint8_t style; |
45 | uint8_t style; |
| 46 | } attr_style_t; |
46 | } attr_style_t; |
| 47 | 47 | ||
| Line 50... | Line 50... | ||
| 50 | uint8_t bg_color; |
50 | uint8_t bg_color; |
| 51 | uint8_t flags; |
51 | uint8_t flags; |
| 52 | } attr_idx_t; |
52 | } attr_idx_t; |
| 53 | 53 | ||
| 54 | typedef struct { |
54 | typedef struct { |
| 55 | uint32_t bg_color; /**< background color */ |
55 | uint32_t bg_color; /**< background color */ |
| 56 | uint32_t fg_color; /**< foreground color */ |
56 | uint32_t fg_color; /**< foreground color */ |
| 57 | } attr_rgb_t; |
57 | } attr_rgb_t; |
| 58 | 58 | ||
| 59 | typedef struct { |
59 | typedef struct { |
| 60 | enum { |
60 | enum { |
| 61 | at_style, |
61 | at_style, |
| Line 64... | Line 64... | ||
| 64 | } t; |
64 | } t; |
| 65 | union { |
65 | union { |
| 66 | attr_style_t s; |
66 | attr_style_t s; |
| 67 | attr_idx_t i; |
67 | attr_idx_t i; |
| 68 | attr_rgb_t r; |
68 | attr_rgb_t r; |
| 69 | } a; |
69 | } a; |
| 70 | } attrs_t; |
70 | } attrs_t; |
| 71 | 71 | ||
| 72 | /** One field on screen. It contain one character and its attributes. */ |
72 | /** One field on screen. It contain one character and its attributes. */ |
| 73 | typedef struct { |
73 | typedef struct { |
| 74 | wchar_t character; /**< Character itself */ |
74 | wchar_t character; /**< Character itself */ |
| 75 | attrs_t attrs; /**< Character`s attributes */ |
75 | attrs_t attrs; /**< Character`s attributes */ |
| 76 | } keyfield_t; |
76 | } keyfield_t; |
| 77 | 77 | ||
| 78 | /** Structure for buffering state of one virtual console. |
78 | /** Structure for buffering state of one virtual console. |
| 79 | */ |
79 | */ |
| 80 | typedef struct { |
80 | typedef struct { |
| - | 81 | keyfield_t *buffer; /**< Screen content - characters and |
|
| 81 | keyfield_t *buffer; /**< Screen content - characters and their attributes. Used as a circular buffer. */ |
82 | their attributes (used as a circular buffer) */ |
| 82 | unsigned int size_x, size_y; /**< Number of columns and rows */ |
83 | unsigned int size_x; /**< Number of columns */ |
| - | 84 | unsigned int size_y; /**< Number of rows */ |
|
| - | 85 | ||
| 83 | unsigned int position_x, position_y; /**< Coordinates of last printed character for determining cursor position */ |
86 | /** Coordinates of last printed character for determining cursor position */ |
| - | 87 | unsigned int position_x; |
|
| - | 88 | unsigned int position_y; |
|
| - | 89 | ||
| 84 | attrs_t attrs; /**< Current attributes. */ |
90 | attrs_t attrs; /**< Current attributes. */ |
| 85 | unsigned int top_line; /**< Points to buffer[][] line that will be printed at screen as the first line */ |
91 | unsigned int top_line; /**< Points to buffer[][] line that will |
| - | 92 | be printed at screen as the first line */ |
|
| 86 | unsigned char is_cursor_visible; /**< Cursor state - default is visible */ |
93 | unsigned char is_cursor_visible; /**< Cursor state - default is visible */ |
| 87 | } screenbuffer_t; |
94 | } screenbuffer_t; |
| 88 | 95 | ||
| - | 96 | /** Returns keyfield for position on screen |
|
| - | 97 | * |
|
| 89 | /** Returns keyfield for position on screen. Screenbuffer->buffer is cyclic buffer so we must couted in index of the topmost line. |
98 | * Screenbuffer->buffer is cyclic buffer so we |
| - | 99 | * must couted in index of the topmost line. |
|
| - | 100 | * |
|
| 90 | * @param scr screenbuffer |
101 | * @param scr Screenbuffer |
| 91 | * @param x position on screen |
102 | * @param x Position on screen |
| 92 | * @param y position on screen |
103 | * @param y Position on screen |
| - | 104 | * |
|
| 93 | * @return keyfield structure with character and its attributes on x,y |
105 | * @return Keyfield structure with character and its attributes on x, y |
| - | 106 | * |
|
| 94 | */ |
107 | */ |
| 95 | static inline keyfield_t *get_field_at(screenbuffer_t *scr, unsigned int x, unsigned int y) |
108 | static inline keyfield_t *get_field_at(screenbuffer_t *scr, unsigned int x, unsigned int y) |
| 96 | { |
109 | { |
| 97 | return scr->buffer + x + ((y + scr->top_line) % scr->size_y) * scr->size_x; |
110 | return scr->buffer + x + ((y + scr->top_line) % scr->size_y) * scr->size_x; |
| 98 | } |
111 | } |
| 99 | 112 | ||
| 100 | /** Compares two sets of attributes. |
113 | /** Compares two sets of attributes. |
| - | 114 | * |
|
| 101 | * @param s1 first style |
115 | * @param s1 First style |
| 102 | * @param s2 second style |
116 | * @param s2 Second style |
| - | 117 | * |
|
| 103 | * @return nonzero on equality |
118 | * @return Nonzero on equality |
| - | 119 | * |
|
| 104 | */ |
120 | */ |
| 105 | static inline int attrs_same(attrs_t a1, attrs_t a2) |
121 | static inline int attrs_same(attrs_t a1, attrs_t a2) |
| 106 | { |
122 | { |
| 107 | if (a1.t != a2.t) return 0; |
123 | if (a1.t != a2.t) |
| - | 124 | return 0; |
|
| 108 | 125 | ||
| 109 | switch (a1.t) { |
126 | switch (a1.t) { |
| - | 127 | case at_style: |
|
| 110 | case at_style: return a1.a.s.style == a2.a.s.style; |
128 | return (a1.a.s.style == a2.a.s.style); |
| - | 129 | case at_idx: |
|
| 111 | case at_idx: return a1.a.i.fg_color == a2.a.i.fg_color && |
130 | return (a1.a.i.fg_color == a2.a.i.fg_color) |
| 112 | a1.a.i.bg_color == a2.a.i.bg_color && |
131 | && (a1.a.i.bg_color == a2.a.i.bg_color) |
| 113 | a1.a.i.flags == a2.a.i.flags; |
132 | && (a1.a.i.flags == a2.a.i.flags); |
| - | 133 | case at_rgb: |
|
| 114 | case at_rgb: return a1.a.r.fg_color == a2.a.r.fg_color && |
134 | return (a1.a.r.fg_color == a2.a.r.fg_color) |
| 115 | a1.a.r.bg_color == a2.a.r.bg_color; |
135 | && (a1.a.r.bg_color == a2.a.r.bg_color); |
| 116 | } |
136 | } |
| 117 | } |
137 | } |
| 118 | 138 | ||
| 119 | 139 | ||
| 120 | void screenbuffer_putchar(screenbuffer_t *scr, wchar_t c); |
140 | void screenbuffer_putchar(screenbuffer_t *scr, wchar_t c); |
| Line 130... | Line 150... | ||
| 130 | void screenbuffer_set_rgb_color(screenbuffer_t *scr, unsigned int fg_color, |
150 | void screenbuffer_set_rgb_color(screenbuffer_t *scr, unsigned int fg_color, |
| 131 | unsigned int bg_color); |
151 | unsigned int bg_color); |
| 132 | 152 | ||
| 133 | #endif |
153 | #endif |
| 134 | 154 | ||
| 135 | - | ||
| 136 | /** @} |
155 | /** @} |
| 137 | */ |
156 | */ |
| 138 | - | ||