Subversion Repositories HelenOS

Rev

Rev 4211 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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