Rev 4421 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 4421 | Rev 4456 | ||
|---|---|---|---|
| Line 31... | Line 31... | ||
| 31 | */ |
31 | */ |
| 32 | /** @file |
32 | /** @file |
| 33 | */ |
33 | */ |
| 34 | 34 | ||
| 35 | #include <screenbuffer.h> |
35 | #include <screenbuffer.h> |
| 36 | #include <console/style.h> |
36 | #include <io/style.h> |
| 37 | #include <malloc.h> |
37 | #include <malloc.h> |
| 38 | #include <unistd.h> |
38 | #include <unistd.h> |
| 39 | 39 | ||
| 40 | /** Store one character to screenbuffer. |
40 | /** Store one character to screenbuffer. |
| 41 | * |
41 | * |
| Line 64... | Line 64... | ||
| 64 | * @param size_y Height in characters |
64 | * @param size_y Height in characters |
| 65 | * |
65 | * |
| 66 | * @return Pointer to screenbuffer (same as scr parameter) or NULL |
66 | * @return Pointer to screenbuffer (same as scr parameter) or NULL |
| 67 | * |
67 | * |
| 68 | */ |
68 | */ |
| 69 | screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, int size_x, int size_y) |
69 | screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, size_t size_x, size_t size_y) |
| 70 | { |
70 | { |
| 71 | scr->buffer = (keyfield_t *) malloc(sizeof(keyfield_t) * size_x * size_y); |
71 | scr->buffer = (keyfield_t *) malloc(sizeof(keyfield_t) * size_x * size_y); |
| 72 | if (!scr->buffer) |
72 | if (!scr->buffer) |
| 73 | return NULL; |
73 | return NULL; |
| 74 | 74 | ||
| Line 88... | Line 88... | ||
| 88 | * @param scr Screenbuffer |
88 | * @param scr Screenbuffer |
| 89 | * |
89 | * |
| 90 | */ |
90 | */ |
| 91 | void screenbuffer_clear(screenbuffer_t *scr) |
91 | void screenbuffer_clear(screenbuffer_t *scr) |
| 92 | { |
92 | { |
| 93 | unsigned int i; |
93 | size_t i; |
| 94 | 94 | ||
| 95 | for (i = 0; i < (scr->size_x * scr->size_y); i++) { |
95 | for (i = 0; i < (scr->size_x * scr->size_y); i++) { |
| 96 | scr->buffer[i].character = ' '; |
96 | scr->buffer[i].character = ' '; |
| 97 | scr->buffer[i].attrs = scr->attrs; |
97 | scr->buffer[i].attrs = scr->attrs; |
| 98 | } |
98 | } |
| 99 | 99 | ||
| 100 | scr->top_line = 0; |
100 | scr->top_line = 0; |
| 101 | scr->position_y = 0; |
- | |
| 102 | scr->position_x = 0; |
101 | scr->position_x = 0; |
| - | 102 | scr->position_y = 0; |
|
| 103 | } |
103 | } |
| 104 | 104 | ||
| 105 | /** Clear one buffer line. |
105 | /** Clear one buffer line. |
| 106 | * |
106 | * |
| 107 | * @param scr |
107 | * @param scr |
| 108 | * @param line One buffer line (not a screen line!) |
108 | * @param line One buffer line (not a screen line!) |
| 109 | * |
109 | * |
| 110 | */ |
110 | */ |
| 111 | void screenbuffer_clear_line(screenbuffer_t *scr, unsigned int line) |
111 | void screenbuffer_clear_line(screenbuffer_t *scr, size_t line) |
| 112 | { |
112 | { |
| 113 | unsigned int i; |
113 | size_t x; |
| 114 | 114 | ||
| 115 | for (i = 0; i < scr->size_x; i++) { |
115 | for (x = 0; x < scr->size_x; x++) { |
| 116 | scr->buffer[i + line * scr->size_x].character = ' '; |
116 | scr->buffer[x + line * scr->size_x].character = ' '; |
| 117 | scr->buffer[i + line * scr->size_x].attrs = scr->attrs; |
117 | scr->buffer[x + line * scr->size_x].attrs = scr->attrs; |
| 118 | } |
118 | } |
| 119 | } |
119 | } |
| 120 | 120 | ||
| 121 | /** Copy content buffer from screenbuffer to given memory. |
121 | /** Copy content buffer from screenbuffer to given memory. |
| 122 | * |
122 | * |
| 123 | * @param scr Source screenbuffer |
123 | * @param scr Source screenbuffer |
| 124 | * @param dest Destination |
124 | * @param dest Destination |
| 125 | * |
125 | * |
| 126 | */ |
126 | */ |
| 127 | void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest) |
127 | void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest) |
| 128 | { |
128 | { |
| 129 | unsigned int i; |
129 | size_t i; |
| 130 | 130 | ||
| 131 | for (i = 0; i < scr->size_x * scr->size_y; i++) |
131 | for (i = 0; i < (scr->size_x * scr->size_y); i++) |
| 132 | dest[i] = scr->buffer[i]; |
132 | dest[i] = scr->buffer[i]; |
| 133 | } |
133 | } |
| 134 | 134 | ||
| 135 | /** Set new cursor position in screenbuffer. |
135 | /** Set new cursor position in screenbuffer. |
| 136 | * |
136 | * |
| 137 | * @param scr |
137 | * @param scr |
| 138 | * @param x |
138 | * @param x |
| 139 | * @param y |
139 | * @param y |
| 140 | * |
140 | * |
| 141 | */ |
141 | */ |
| 142 | void screenbuffer_goto(screenbuffer_t *scr, unsigned int x, unsigned int y) |
142 | void screenbuffer_goto(screenbuffer_t *scr, size_t x, size_t y) |
| 143 | { |
143 | { |
| 144 | scr->position_x = x % scr->size_x; |
144 | scr->position_x = x % scr->size_x; |
| 145 | scr->position_y = y % scr->size_y; |
145 | scr->position_y = y % scr->size_y; |
| 146 | } |
146 | } |
| 147 | 147 | ||
| Line 150... | Line 150... | ||
| 150 | * @param scr |
150 | * @param scr |
| 151 | * @param fg_color |
151 | * @param fg_color |
| 152 | * @param bg_color |
152 | * @param bg_color |
| 153 | * |
153 | * |
| 154 | */ |
154 | */ |
| 155 | void screenbuffer_set_style(screenbuffer_t *scr, int style) |
155 | void screenbuffer_set_style(screenbuffer_t *scr, uint8_t style) |
| 156 | { |
156 | { |
| 157 | scr->attrs.t = at_style; |
157 | scr->attrs.t = at_style; |
| 158 | scr->attrs.a.s.style = style; |
158 | scr->attrs.a.s.style = style; |
| 159 | } |
159 | } |
| 160 | 160 | ||
| Line 163... | Line 163... | ||
| 163 | * @param scr |
163 | * @param scr |
| 164 | * @param fg_color |
164 | * @param fg_color |
| 165 | * @param bg_color |
165 | * @param bg_color |
| 166 | * |
166 | * |
| 167 | */ |
167 | */ |
| 168 | void screenbuffer_set_color(screenbuffer_t *scr, unsigned int fg_color, unsigned int bg_color, unsigned int flags) |
168 | void screenbuffer_set_color(screenbuffer_t *scr, uint8_t fg_color, uint8_t bg_color, uint8_t flags) |
| 169 | { |
169 | { |
| 170 | scr->attrs.t = at_idx; |
170 | scr->attrs.t = at_idx; |
| 171 | scr->attrs.a.i.fg_color = fg_color; |
171 | scr->attrs.a.i.fg_color = fg_color; |
| 172 | scr->attrs.a.i.bg_color = bg_color; |
172 | scr->attrs.a.i.bg_color = bg_color; |
| 173 | scr->attrs.a.i.flags = flags; |
173 | scr->attrs.a.i.flags = flags; |
| Line 178... | Line 178... | ||
| 178 | * @param scr |
178 | * @param scr |
| 179 | * @param fg_color |
179 | * @param fg_color |
| 180 | * @param bg_color |
180 | * @param bg_color |
| 181 | * |
181 | * |
| 182 | */ |
182 | */ |
| 183 | void screenbuffer_set_rgb_color(screenbuffer_t *scr, unsigned int fg_color, unsigned int bg_color) |
183 | void screenbuffer_set_rgb_color(screenbuffer_t *scr, uint32_t fg_color, uint32_t bg_color) |
| 184 | { |
184 | { |
| 185 | scr->attrs.t = at_rgb; |
185 | scr->attrs.t = at_rgb; |
| 186 | scr->attrs.a.r.fg_color = fg_color; |
186 | scr->attrs.a.r.fg_color = fg_color; |
| 187 | scr->attrs.a.r.bg_color = bg_color; |
187 | scr->attrs.a.r.bg_color = bg_color; |
| 188 | } |
188 | } |