Subversion Repositories HelenOS

Rev

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

Rev 4348 Rev 4691
Line 25... Line 25...
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
#include <screenbuffer.h>
35
#include <screenbuffer.h>
36
#include <console/style.h>
36
#include <io/style.h>
37
#include <malloc.h>
37
#include <malloc.h>
38
#include <unistd.h>
38
#include <unistd.h>
39
 
39
 
40
/** Store one character to screenbuffer. Its position is determined by
40
/** Store one character to screenbuffer.
-
 
41
 *
41
 * scr->position_x and scr->position_y.
42
 * Its position is determined by scr->position_x
-
 
43
 * and scr->position_y.
-
 
44
 *
-
 
45
 * @param scr Screenbuffer
-
 
46
 * @param c   Stored character
42
 *
47
 *
43
 * @param scr   screenbuffer
-
 
44
 * @param c stored character
-
 
45
 */
48
 */
46
void screenbuffer_putchar(screenbuffer_t *scr, wchar_t ch)
49
void screenbuffer_putchar(screenbuffer_t *scr, wchar_t ch)
47
{
50
{
48
    keyfield_t *field;
51
    keyfield_t *field =
49
 
-
 
50
    field = get_field_at(scr, scr->position_x, scr->position_y);
52
        get_field_at(scr, scr->position_x, scr->position_y);
51
 
53
   
52
    field->character = ch;
54
    field->character = ch;
53
    field->attrs = scr->attrs;
55
    field->attrs = scr->attrs;
54
}
56
}
55
 
57
 
-
 
58
/** Initilize screenbuffer.
-
 
59
 *
56
/** Initilize screenbuffer. Allocate space for screen content in accordance to given size.
60
 * Allocate space for screen content in accordance to given size.
-
 
61
 *
57
 * @param scr       initialized screenbuffer
62
 * @param scr    Initialized screenbuffer
58
 * @param size_x    width in characters    
63
 * @param size_x Width in characters
59
 * @param size_y    height in characters
64
 * @param size_y Height in characters
-
 
65
 *
60
 * @return pointer to screenbuffer (same as scr parameter) or NULL
66
 * @return Pointer to screenbuffer (same as scr parameter) or NULL
-
 
67
 *
61
 */
68
 */
62
screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, int size_x, int size_y)
69
screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, size_t size_x, size_t size_y)
63
{
70
{
64
    scr->buffer = (keyfield_t *) malloc(sizeof(keyfield_t) * size_x * size_y);
71
    scr->buffer = (keyfield_t *) malloc(sizeof(keyfield_t) * size_x * size_y);
65
    if (!scr->buffer) {
72
    if (!scr->buffer)
66
        return NULL;
73
        return NULL;
67
    }
-
 
68
   
74
   
69
    scr->size_x = size_x;
75
    scr->size_x = size_x;
70
    scr->size_y = size_y;
76
    scr->size_y = size_y;
71
    scr->attrs.t = at_style;
77
    scr->attrs.t = at_style;
72
    scr->attrs.a.s.style = STYLE_NORMAL;
78
    scr->attrs.a.s.style = STYLE_NORMAL;
Line 75... Line 81...
75
    screenbuffer_clear(scr);
81
    screenbuffer_clear(scr);
76
   
82
   
77
    return scr;
83
    return scr;
78
}
84
}
79
 
85
 
80
/** Clear screenbuffer.
86
/** Clear screenbuffer.
-
 
87
 *
81
 * @param scr screenbuffer
88
 * @param scr Screenbuffer
-
 
89
 *
82
 */
90
 */
83
void screenbuffer_clear(screenbuffer_t *scr)
91
void screenbuffer_clear(screenbuffer_t *scr)
84
{
92
{
85
    unsigned int i;
93
    size_t i;
86
   
94
   
87
    for (i = 0; i < (scr->size_x * scr->size_y); i++) {
95
    for (i = 0; i < (scr->size_x * scr->size_y); i++) {
88
        scr->buffer[i].character = ' ';
96
        scr->buffer[i].character = ' ';
89
        scr->buffer[i].attrs = scr->attrs;
97
        scr->buffer[i].attrs = scr->attrs;
90
    }
98
    }
91
 
99
   
92
    scr->top_line = 0;
100
    scr->top_line = 0;
93
    scr->position_y = 0;
-
 
94
    scr->position_x = 0;
101
    scr->position_x = 0;
-
 
102
    scr->position_y = 0;
95
}
103
}
96
 
104
 
97
/** Clear one buffer line.
105
/** Clear one buffer line.
-
 
106
 *
98
 * @param scr
107
 * @param scr
99
 * @param line One buffer line (not a screen line!)
108
 * @param line One buffer line (not a screen line!)
-
 
109
 *
100
 */
110
 */
101
void screenbuffer_clear_line(screenbuffer_t *scr, unsigned int line)
111
void screenbuffer_clear_line(screenbuffer_t *scr, size_t line)
102
{
112
{
103
    unsigned int i;
113
    size_t x;
104
   
114
   
105
    for (i = 0; i < scr->size_x; i++) {
115
    for (x = 0; x < scr->size_x; x++) {
106
        scr->buffer[i + line * scr->size_x].character = ' ';
116
        scr->buffer[x + line * scr->size_x].character = ' ';
107
        scr->buffer[i + line * scr->size_x].attrs = scr->attrs;
117
        scr->buffer[x + line * scr->size_x].attrs = scr->attrs;
108
    }
118
    }
109
}
119
}
110
 
120
 
111
/** Copy content buffer from screenbuffer to given memory.
121
/** Copy content buffer from screenbuffer to given memory.
-
 
122
 *
112
 * @param scr   source screenbuffer
123
 * @param scr  Source screenbuffer
113
 * @param dest  destination
124
 * @param dest Destination
-
 
125
 *
114
 */
126
 */
115
void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest)
127
void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest)
116
{
128
{
117
    unsigned int i;
129
    size_t i;
118
   
130
   
119
    for (i = 0; i < scr->size_x * scr->size_y; i++) {
131
    for (i = 0; i < (scr->size_x * scr->size_y); i++)
120
        dest[i] = scr->buffer[i];
132
        dest[i] = scr->buffer[i];
121
    }
-
 
122
}
133
}
123
 
134
 
124
/** Set new cursor position in screenbuffer.
135
/** Set new cursor position in screenbuffer.
-
 
136
 *
125
 * @param scr
137
 * @param scr
126
 * @param x
138
 * @param x
127
 * @param y
139
 * @param y
-
 
140
 *
128
 */
141
 */
129
void screenbuffer_goto(screenbuffer_t *scr, unsigned int x, unsigned int y)
142
void screenbuffer_goto(screenbuffer_t *scr, size_t x, size_t y)
130
{
143
{
131
    scr->position_x = x % scr->size_x;
144
    scr->position_x = x % scr->size_x;
132
    scr->position_y = y % scr->size_y;
145
    scr->position_y = y % scr->size_y;
133
}
146
}
134
 
147
 
135
/** Set new style.
148
/** Set new style.
-
 
149
 *
136
 * @param scr
150
 * @param scr
137
 * @param fg_color
151
 * @param fg_color
138
 * @param bg_color
152
 * @param bg_color
-
 
153
 *
139
 */
154
 */
140
void screenbuffer_set_style(screenbuffer_t *scr, int style)
155
void screenbuffer_set_style(screenbuffer_t *scr, uint8_t style)
141
{
156
{
142
    scr->attrs.t = at_style;
157
    scr->attrs.t = at_style;
143
    scr->attrs.a.s.style = style;
158
    scr->attrs.a.s.style = style;
144
}
159
}
145
 
160
 
146
/** Set new color.
161
/** Set new color.
-
 
162
 *
147
 * @param scr
163
 * @param scr
148
 * @param fg_color
164
 * @param fg_color
149
 * @param bg_color
165
 * @param bg_color
-
 
166
 *
150
 */
167
 */
151
void screenbuffer_set_color(screenbuffer_t *scr, unsigned int fg_color, unsigned int bg_color, unsigned int flags)
168
void screenbuffer_set_color(screenbuffer_t *scr, uint8_t fg_color, uint8_t bg_color, uint8_t flags)
152
{
169
{
153
    scr->attrs.t = at_idx;
170
    scr->attrs.t = at_idx;
154
    scr->attrs.a.i.fg_color = fg_color;
171
    scr->attrs.a.i.fg_color = fg_color;
155
    scr->attrs.a.i.bg_color = bg_color;
172
    scr->attrs.a.i.bg_color = bg_color;
156
    scr->attrs.a.i.flags = flags;
173
    scr->attrs.a.i.flags = flags;
157
}
174
}
158
 
175
 
159
/** Set new RGB color.
176
/** Set new RGB color.
-
 
177
 *
160
 * @param scr
178
 * @param scr
161
 * @param fg_color
179
 * @param fg_color
162
 * @param bg_color
180
 * @param bg_color
-
 
181
 *
163
 */
182
 */
164
void screenbuffer_set_rgb_color(screenbuffer_t *scr, unsigned int fg_color, unsigned int bg_color)
183
void screenbuffer_set_rgb_color(screenbuffer_t *scr, uint32_t fg_color, uint32_t bg_color)
165
{
184
{
166
    scr->attrs.t = at_rgb;
185
    scr->attrs.t = at_rgb;
167
    scr->attrs.a.r.fg_color = fg_color;
186
    scr->attrs.a.r.fg_color = fg_color;
168
    scr->attrs.a.r.bg_color = bg_color;
187
    scr->attrs.a.r.bg_color = bg_color;
169
}
188
}
170
 
189
 
171
 
-
 
172
/** @}
190
/** @}
173
 */
191
 */