Subversion Repositories HelenOS

Rev

Rev 4338 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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