Subversion Repositories HelenOS

Rev

Rev 4337 | Rev 4348 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4337 Rev 4338
Line 39... Line 39...
39
 
39
 
40
#define DEFAULT_FOREGROUND 0x0  /**< default console foreground color */
40
#define DEFAULT_FOREGROUND 0x0  /**< default console foreground color */
41
#define DEFAULT_BACKGROUND 0xf0f0f0 /**< default console background color */
41
#define DEFAULT_BACKGROUND 0xf0f0f0 /**< default console background color */
42
 
42
 
43
typedef struct {
43
typedef struct {
-
 
44
    uint8_t style;
-
 
45
} attr_style_t;
-
 
46
 
-
 
47
typedef struct {
-
 
48
    uint8_t fg_color;
-
 
49
    uint8_t bg_color;
-
 
50
    uint8_t flags;
-
 
51
} attr_idx_t;
-
 
52
 
-
 
53
typedef struct {
44
    uint32_t bg_color;      /**< background color */
54
    uint32_t bg_color;      /**< background color */
45
    uint32_t fg_color;      /**< foreground color */
55
    uint32_t fg_color;      /**< foreground color */
-
 
56
} attr_rgb_t;
-
 
57
 
-
 
58
typedef struct {
-
 
59
    enum {
-
 
60
        at_style,
-
 
61
        at_idx,
-
 
62
        at_rgb
-
 
63
    } t;
-
 
64
    union {
-
 
65
        attr_style_t s;
-
 
66
        attr_idx_t i;
-
 
67
        attr_rgb_t r;
-
 
68
    } a;
46
} style_t;
69
} attrs_t;
47
 
70
 
48
/** One field on screen. It contain one character and its attributes. */
71
/** One field on screen. It contain one character and its attributes. */
49
typedef struct {
72
typedef struct {
50
    char character;         /**< Character itself */
73
    char character;         /**< Character itself */
51
    style_t style;          /**< Character`s attributes */
74
    attrs_t attrs;          /**< Character`s attributes */
52
} keyfield_t;
75
} keyfield_t;
53
 
76
 
54
/** Structure for buffering state of one virtual console.
77
/** Structure for buffering state of one virtual console.
55
 */
78
 */
56
typedef struct {
79
typedef struct {
57
    keyfield_t *buffer;         /**< Screen content - characters and its style. Used as cyclyc buffer. */
80
    keyfield_t *buffer;         /**< Screen content - characters and their attributes. Used as a circular buffer. */
58
    unsigned int size_x, size_y;        /**< Number of columns and rows */
81
    unsigned int size_x, size_y;        /**< Number of columns and rows */
59
    unsigned int position_x, position_y;    /**< Coordinates of last printed character for determining cursor position */
82
    unsigned int position_x, position_y;    /**< Coordinates of last printed character for determining cursor position */
60
    style_t style;              /**< Current style */
83
    attrs_t attrs;              /**< Current attributes. */
61
    unsigned int top_line;          /**< Points to buffer[][] line that will be printed at screen as the first line */
84
    unsigned int top_line;          /**< Points to buffer[][] line that will be printed at screen as the first line */
62
    unsigned char is_cursor_visible;    /**< Cursor state - default is visible */
85
    unsigned char is_cursor_visible;    /**< Cursor state - default is visible */
63
} screenbuffer_t;
86
} screenbuffer_t;
64
 
87
 
65
/** Returns keyfield for position on screen. Screenbuffer->buffer is cyclic buffer so we must couted in index of the topmost line.
88
/** Returns keyfield for position on screen. Screenbuffer->buffer is cyclic buffer so we must couted in index of the topmost line.
Line 71... Line 94...
71
static inline keyfield_t *get_field_at(screenbuffer_t *scr, unsigned int x, unsigned int y)
94
static inline keyfield_t *get_field_at(screenbuffer_t *scr, unsigned int x, unsigned int y)
72
{
95
{
73
    return scr->buffer + x + ((y + scr->top_line) % scr->size_y) * scr->size_x;
96
    return scr->buffer + x + ((y + scr->top_line) % scr->size_y) * scr->size_x;
74
}
97
}
75
 
98
 
76
/** Compares two styles.
99
/** Compares two sets of attributes.
77
 * @param s1 first style
100
 * @param s1 first style
78
 * @param s2 second style
101
 * @param s2 second style
79
 * @return nonzero on equality
102
 * @return nonzero on equality
80
 */
103
 */
81
static inline int style_same(style_t s1, style_t s2)
104
static inline int attrs_same(attrs_t a1, attrs_t a2)
82
{
105
{
-
 
106
    if (a1.t != a2.t) return 0;
-
 
107
 
-
 
108
    switch (a1.t) {
-
 
109
    case at_style: return a1.a.s.style == a2.a.s.style;
-
 
110
    case at_idx: return a1.a.i.fg_color == a2.a.i.fg_color &&
-
 
111
        a1.a.i.bg_color == a2.a.i.bg_color &&
-
 
112
        a1.a.i.flags == a2.a.i.flags;
83
    return s1.fg_color == s2.fg_color && s1.bg_color == s2.bg_color;
113
    case at_rgb: return a1.a.r.fg_color == a2.a.r.fg_color &&
-
 
114
        a1.a.r.bg_color == a2.a.r.bg_color;
-
 
115
    }
84
}
116
}
85
 
117
 
86
 
118
 
87
void screenbuffer_putchar(screenbuffer_t *scr, char c);
119
void screenbuffer_putchar(screenbuffer_t *scr, char c);
88
screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, int size_x, int size_y);
120
screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, int size_x, int size_y);
89
 
121
 
90
void screenbuffer_clear(screenbuffer_t *scr);
122
void screenbuffer_clear(screenbuffer_t *scr);
91
void screenbuffer_clear_line(screenbuffer_t *scr, unsigned int line);
123
void screenbuffer_clear_line(screenbuffer_t *scr, unsigned int line);
92
void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest);
124
void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest);
93
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);
-
 
126
void screenbuffer_set_style(screenbuffer_t *scr, int style);
94
void screenbuffer_set_style(screenbuffer_t *scr, unsigned int fg_color, unsigned int bg_color);
127
void screenbuffer_set_color(screenbuffer_t *scr, unsigned int fg_color,
-
 
128
    unsigned int bg_color, unsigned int attr);
-
 
129
void screenbuffer_set_rgb_color(screenbuffer_t *scr, unsigned int fg_color,
-
 
130
    unsigned int bg_color);
95
 
131
 
96
#endif
132
#endif
97
 
133
 
98
 
134
 
99
/** @}
135
/** @}