Rev 1787 | Rev 2479 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1787 | Rev 2071 | ||
---|---|---|---|
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 |
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 | 38 | ||
39 | #define DEFAULT_FOREGROUND 0x0 /**< default console foreground color */ |
39 | #define DEFAULT_FOREGROUND 0x0 /**< default console foreground color */ |
40 | #define DEFAULT_BACKGROUND 0xf0f0f0 /**< default console background color */ |
40 | #define DEFAULT_BACKGROUND 0xf0f0f0 /**< default console background color */ |
41 | 41 | ||
42 | typedef struct { |
42 | typedef struct { |
43 | unsigned int bg_color; /**< background color */ |
43 | unsigned int bg_color; /**< background color */ |
44 | unsigned int fg_color; /**< foreground color */ |
44 | unsigned int fg_color; /**< foreground color */ |
45 | } style_t; |
45 | } style_t; |
46 | 46 | ||
47 | /** One field on screen. It contain one character and its attributes. */ |
47 | /** One field on screen. It contain one character and its attributes. */ |
48 | typedef struct { |
48 | typedef struct { |
49 | char character; /**< Character itself */ |
49 | char character; /**< Character itself */ |
50 | style_t style; /**< Character`s attributes */ |
50 | style_t style; /**< Character`s attributes */ |
51 | } keyfield_t; |
51 | } keyfield_t; |
52 | 52 | ||
53 | /** Structure for buffering state of one virtual console. |
53 | /** Structure for buffering state of one virtual console. |
54 | */ |
54 | */ |
55 | typedef struct { |
55 | typedef struct { |
56 | keyfield_t *buffer; /**< Screen content - characters and its style. Used as cyclyc buffer. */ |
56 | keyfield_t *buffer; /**< Screen content - characters and its style. Used as cyclyc buffer. */ |
57 | unsigned int size_x, size_y; /**< Number of columns and rows */ |
57 | 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 */ |
58 | unsigned int position_x, position_y; /**< Coordinates of last printed character for determining cursor position */ |
59 | style_t style; /**< Current style */ |
59 | style_t style; /**< Current style */ |
60 | unsigned int top_line; /**< Points to buffer[][] line that will be printed at screen as the first line */ |
60 | 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 */ |
61 | unsigned char is_cursor_visible; /**< Cursor state - default is visible */ |
62 | } screenbuffer_t; |
62 | } screenbuffer_t; |
63 | 63 | ||
64 | /** Returns keyfield for position on screen. Screenbuffer->buffer is cyclic buffer so we must couted in index of the topmost line. |
64 | /** 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 |
65 | * @param scr screenbuffer |
66 | * @param x position on screen |
66 | * @param x position on screen |
67 | * @param y position on screen |
67 | * @param y position on screen |
68 | * @return keyfield structure with character and its attributes on x,y |
68 | * @return keyfield structure with character and its attributes on x,y |
69 | */ |
69 | */ |
70 | static inline keyfield_t *get_field_at(screenbuffer_t *scr, unsigned int x, unsigned int y) |
70 | static inline keyfield_t *get_field_at(screenbuffer_t *scr, unsigned int x, unsigned int y) |
71 | { |
71 | { |
72 | return scr->buffer + x + ((y + scr->top_line) % scr->size_y) * scr->size_x; |
72 | return scr->buffer + x + ((y + scr->top_line) % scr->size_y) * scr->size_x; |
73 | } |
73 | } |
74 | 74 | ||
75 | /** Compares two styles. |
75 | /** Compares two styles. |
76 | * @param s1 first style |
76 | * @param s1 first style |
77 | * @param s2 second style |
77 | * @param s2 second style |
78 | * @return nonzero on equality |
78 | * @return nonzero on equality |
79 | */ |
79 | */ |
80 | static inline int style_same(style_t s1, style_t s2) |
80 | static inline int style_same(style_t s1, style_t s2) |
81 | { |
81 | { |
82 | return s1.fg_color == s2.fg_color && s1.bg_color == s2.bg_color; |
82 | return s1.fg_color == s2.fg_color && s1.bg_color == s2.bg_color; |
83 | } |
83 | } |
84 | 84 | ||
85 | 85 | ||
86 | void screenbuffer_putchar(screenbuffer_t *scr, char c); |
86 | void screenbuffer_putchar(screenbuffer_t *scr, char c); |
87 | screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, int size_x, int size_y); |
87 | screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, int size_x, int size_y); |
88 | 88 | ||
89 | void screenbuffer_clear(screenbuffer_t *scr); |
89 | void screenbuffer_clear(screenbuffer_t *scr); |
90 | void screenbuffer_clear_line(screenbuffer_t *scr, unsigned int line); |
90 | void screenbuffer_clear_line(screenbuffer_t *scr, unsigned int line); |
91 | void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest); |
91 | void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest); |
92 | void screenbuffer_goto(screenbuffer_t *scr, unsigned int x, unsigned int y); |
92 | void screenbuffer_goto(screenbuffer_t *scr, unsigned int x, unsigned int y); |
93 | void screenbuffer_set_style(screenbuffer_t *scr, unsigned int fg_color, unsigned int bg_color); |
93 | void screenbuffer_set_style(screenbuffer_t *scr, unsigned int fg_color, unsigned int bg_color); |
94 | 94 | ||
95 | #endif |
95 | #endif |
96 | 96 | ||
97 | 97 | ||
98 | /** @} |
98 | /** @} |
99 | */ |
99 | */ |
100 | 100 | ||
101 | 101 |