Rev 1509 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1487 | cejka | 1 | /* |
2 | * Copyright (C) 2006 Josef Cejka |
||
3 | * All rights reserved. |
||
4 | * |
||
5 | * Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions |
||
7 | * are met: |
||
8 | * |
||
9 | * - Redistributions of source code must retain the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer. |
||
11 | * - Redistributions in binary form must reproduce the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer in the |
||
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 |
||
15 | * derived from this software without specific prior written permission. |
||
16 | * |
||
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 |
||
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
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 |
||
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 |
||
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
27 | */ |
||
28 | |||
29 | #ifndef __SCREENBUFFER_H__ |
||
30 | #define __SCREENBUFFER_H__ |
||
31 | |||
32 | |||
33 | #define DEFAULT_FOREGROUND_COLOR 0xffffff |
||
34 | #define DEFAULT_BACKGROUND_COLOR 0x00003f |
||
35 | |||
36 | typedef struct { |
||
37 | unsigned int bg_color; /**< background color */ |
||
38 | unsigned int fg_color; /**< foreground color */ |
||
39 | } style_t; |
||
40 | |||
41 | /** One field at screen. It contain one character and its attributes. */ |
||
42 | typedef struct { |
||
43 | char character; /**< Character itself */ |
||
44 | style_t style; /**< Character`s attributes */ |
||
45 | } keyfield_t; |
||
46 | |||
47 | /** Structure for buffering state of one virtual console. |
||
48 | */ |
||
49 | typedef struct { |
||
50 | keyfield_t *buffer; /**< Screen content - characters and its style. Used as cyclyc buffer. */ |
||
51 | unsigned int size_x, size_y; /**< Number of columns and rows */ |
||
52 | unsigned int position_x, position_y; /**< Coordinates of last printed character for determining cursor position */ |
||
53 | style_t style; /**< Current style */ |
||
54 | unsigned int top_line; /**< Points to buffer[][] line that will be printed at screen as the first line */ |
||
55 | } screenbuffer_t; |
||
56 | |||
57 | static inline keyfield_t *get_field_at(screenbuffer_t *scr, unsigned int x, unsigned int y) |
||
58 | { |
||
59 | return scr->buffer + x + ((y + scr->top_line) % scr->size_y) * scr->size_x; |
||
60 | } |
||
61 | |||
62 | |||
63 | int screenbuffer_putchar(screenbuffer_t *scr, char c); |
||
64 | screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, int size_x, int size_y); |
||
65 | |||
66 | void screenbuffer_clear(screenbuffer_t *scr); |
||
67 | void screenbuffer_clear_line(screenbuffer_t *scr, unsigned int line); |
||
68 | void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest); |
||
69 | void screenbuffer_goto(screenbuffer_t *scr, unsigned int x, unsigned int y); |
||
70 | |||
71 | #endif |
||
72 |