Rev 1575 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1575 | Rev 1649 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2006 Josef Cejka |
2 | * Copyright (C) 2006 Josef Cejka |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 |
|
- | 30 | * @{ |
|
- | 31 | */ |
|
- | 32 | /** @file |
|
- | 33 | */ |
|
- | 34 | ||
29 | #include <screenbuffer.h> |
35 | #include <screenbuffer.h> |
30 | #include <malloc.h> |
36 | #include <malloc.h> |
31 | #include <unistd.h> |
37 | #include <unistd.h> |
32 | 38 | ||
33 | /** Store one character to screenbuffer. Its position is determined by scr->position_x and scr->position_y. |
39 | /** Store one character to screenbuffer. Its position is determined by scr->position_x and scr->position_y. |
34 | * @param scr screenbuffer |
40 | * @param scr screenbuffer |
35 | * @param c stored character |
41 | * @param c stored character |
36 | */ |
42 | */ |
37 | void screenbuffer_putchar(screenbuffer_t *scr, char c) |
43 | void screenbuffer_putchar(screenbuffer_t *scr, char c) |
38 | { |
44 | { |
39 | keyfield_t *field; |
45 | keyfield_t *field; |
40 | 46 | ||
41 | field = get_field_at(scr, scr->position_x, scr->position_y); |
47 | field = get_field_at(scr, scr->position_x, scr->position_y); |
42 | 48 | ||
43 | field->character = c; |
49 | field->character = c; |
44 | field->style = scr->style; |
50 | field->style = scr->style; |
45 | } |
51 | } |
46 | 52 | ||
47 | /** Initilize screenbuffer. Allocate space for screen content in accordance to given size. |
53 | /** Initilize screenbuffer. Allocate space for screen content in accordance to given size. |
48 | * @param scr initialized screenbuffer |
54 | * @param scr initialized screenbuffer |
49 | * @param size_x width in characters |
55 | * @param size_x width in characters |
50 | * @param size_y height in characters |
56 | * @param size_y height in characters |
51 | * @return pointer to screenbuffer (same as scr parameter) or NULL |
57 | * @return pointer to screenbuffer (same as scr parameter) or NULL |
52 | */ |
58 | */ |
53 | screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, int size_x, int size_y) |
59 | screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, int size_x, int size_y) |
54 | { |
60 | { |
55 | if ((scr->buffer = (keyfield_t *)malloc(sizeof(keyfield_t) * size_x * size_y)) == NULL) { |
61 | if ((scr->buffer = (keyfield_t *)malloc(sizeof(keyfield_t) * size_x * size_y)) == NULL) { |
56 | return NULL; |
62 | return NULL; |
57 | } |
63 | } |
58 | 64 | ||
59 | scr->size_x = size_x; |
65 | scr->size_x = size_x; |
60 | scr->size_y = size_y; |
66 | scr->size_y = size_y; |
61 | scr->style.fg_color = DEFAULT_FOREGROUND; |
67 | scr->style.fg_color = DEFAULT_FOREGROUND; |
62 | scr->style.bg_color = DEFAULT_BACKGROUND; |
68 | scr->style.bg_color = DEFAULT_BACKGROUND; |
63 | scr->is_cursor_visible = 1; |
69 | scr->is_cursor_visible = 1; |
64 | 70 | ||
65 | screenbuffer_clear(scr); |
71 | screenbuffer_clear(scr); |
66 | 72 | ||
67 | return scr; |
73 | return scr; |
68 | } |
74 | } |
69 | 75 | ||
70 | /** Clear screenbuffer. |
76 | /** Clear screenbuffer. |
71 | * @param scr screenbuffer |
77 | * @param scr screenbuffer |
72 | */ |
78 | */ |
73 | void screenbuffer_clear(screenbuffer_t *scr) |
79 | void screenbuffer_clear(screenbuffer_t *scr) |
74 | { |
80 | { |
75 | unsigned int i; |
81 | unsigned int i; |
76 | 82 | ||
77 | for (i = 0; i < (scr->size_x * scr->size_y); i++) { |
83 | for (i = 0; i < (scr->size_x * scr->size_y); i++) { |
78 | scr->buffer[i].character = ' '; |
84 | scr->buffer[i].character = ' '; |
79 | scr->buffer[i].style = scr->style; |
85 | scr->buffer[i].style = scr->style; |
80 | } |
86 | } |
81 | 87 | ||
82 | scr->top_line = 0; |
88 | scr->top_line = 0; |
83 | scr->position_y = 0; |
89 | scr->position_y = 0; |
84 | scr->position_x = 0; |
90 | scr->position_x = 0; |
85 | } |
91 | } |
86 | 92 | ||
87 | /** Clear one buffer line. |
93 | /** Clear one buffer line. |
88 | * @param scr |
94 | * @param scr |
89 | * @param line One buffer line (not a screen line!) |
95 | * @param line One buffer line (not a screen line!) |
90 | */ |
96 | */ |
91 | void screenbuffer_clear_line(screenbuffer_t *scr, unsigned int line) |
97 | void screenbuffer_clear_line(screenbuffer_t *scr, unsigned int line) |
92 | { |
98 | { |
93 | unsigned int i; |
99 | unsigned int i; |
94 | 100 | ||
95 | for (i = 0; i < scr->size_x; i++) { |
101 | for (i = 0; i < scr->size_x; i++) { |
96 | scr->buffer[i + line*scr->size_x].character = ' '; |
102 | scr->buffer[i + line*scr->size_x].character = ' '; |
97 | scr->buffer[i + line*scr->size_x].style = scr->style; |
103 | scr->buffer[i + line*scr->size_x].style = scr->style; |
98 | } |
104 | } |
99 | } |
105 | } |
100 | 106 | ||
101 | /** Copy content buffer from screenbuffer to given memory. |
107 | /** Copy content buffer from screenbuffer to given memory. |
102 | * @param scr source screenbuffer |
108 | * @param scr source screenbuffer |
103 | * @param dest destination |
109 | * @param dest destination |
104 | */ |
110 | */ |
105 | void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest) |
111 | void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest) |
106 | { |
112 | { |
107 | unsigned int i; |
113 | unsigned int i; |
108 | 114 | ||
109 | for (i = 0; i < scr->size_x * scr->size_y; i++) { |
115 | for (i = 0; i < scr->size_x * scr->size_y; i++) { |
110 | dest[i] = scr->buffer[i]; |
116 | dest[i] = scr->buffer[i]; |
111 | } |
117 | } |
112 | } |
118 | } |
113 | 119 | ||
114 | /** Set new cursor position in screenbuffer. |
120 | /** Set new cursor position in screenbuffer. |
115 | * @param scr |
121 | * @param scr |
116 | * @param x |
122 | * @param x |
117 | * @param y |
123 | * @param y |
118 | */ |
124 | */ |
119 | void screenbuffer_goto(screenbuffer_t *scr, unsigned int x, unsigned int y) |
125 | void screenbuffer_goto(screenbuffer_t *scr, unsigned int x, unsigned int y) |
120 | { |
126 | { |
121 | scr->position_x = x % scr->size_x; |
127 | scr->position_x = x % scr->size_x; |
122 | scr->position_y = y % scr->size_y; |
128 | scr->position_y = y % scr->size_y; |
123 | } |
129 | } |
124 | 130 | ||
125 | /** Set new style. |
131 | /** Set new style. |
126 | * @param scr |
132 | * @param scr |
127 | * @param fg_color |
133 | * @param fg_color |
128 | * @param bg_color |
134 | * @param bg_color |
129 | */ |
135 | */ |
130 | void screenbuffer_set_style(screenbuffer_t *scr, unsigned int fg_color, unsigned int bg_color) |
136 | void screenbuffer_set_style(screenbuffer_t *scr, unsigned int fg_color, unsigned int bg_color) |
131 | { |
137 | { |
132 | scr->style.fg_color = fg_color; |
138 | scr->style.fg_color = fg_color; |
133 | scr->style.bg_color = bg_color; |
139 | scr->style.bg_color = bg_color; |
134 | } |
140 | } |
135 | 141 | ||
- | 142 | ||
- | 143 | /** @} |
|
- | 144 | */ |
|
- | 145 | ||
136 | 146 |