Subversion Repositories HelenOS-historic

Rev

Rev 1575 | Details | Compare with Previous | 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
 
1649 cejka 29
/** @addtogroup console
30
 * @{
31
 */
32
/** @file
33
 */
34
 
1487 cejka 35
#include <screenbuffer.h>
36
#include <malloc.h>
37
#include <unistd.h>
38
 
1525 cejka 39
/** Store one character to screenbuffer. Its position is determined by scr->position_x and scr->position_y.
40
 * @param scr   screenbuffer
41
 * @param c stored character
1487 cejka 42
 */
1525 cejka 43
void screenbuffer_putchar(screenbuffer_t *scr, char c)
1487 cejka 44
{
45
    keyfield_t *field;
46
 
47
    field = get_field_at(scr, scr->position_x, scr->position_y);
48
 
49
    field->character = c;
50
    field->style = scr->style;
51
}
52
 
1525 cejka 53
/** Initilize screenbuffer. Allocate space for screen content in accordance to given size.
54
 * @param scr       initialized screenbuffer
1526 cejka 55
 * @param size_x    width in characters    
56
 * @param size_y    height in characters
57
 * @return pointer to screenbuffer (same as scr parameter) or NULL
1525 cejka 58
 */
1487 cejka 59
screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, int size_x, int size_y)
60
{
61
    if ((scr->buffer = (keyfield_t *)malloc(sizeof(keyfield_t) * size_x * size_y)) == NULL) {
62
        return NULL;
63
    }
64
 
65
    scr->size_x = size_x;
66
    scr->size_y = size_y;
1553 palkovsky 67
    scr->style.fg_color = DEFAULT_FOREGROUND;
68
    scr->style.bg_color = DEFAULT_BACKGROUND;
1575 cejka 69
    scr->is_cursor_visible = 1;
1497 cejka 70
 
71
    screenbuffer_clear(scr);
72
 
1487 cejka 73
    return scr;
74
}
75
 
1526 cejka 76
/** Clear screenbuffer.
77
 * @param scr screenbuffer
78
 */
1487 cejka 79
void screenbuffer_clear(screenbuffer_t *scr)
80
{
81
    unsigned int i;
82
 
1497 cejka 83
    for (i = 0; i < (scr->size_x * scr->size_y); i++) {
1487 cejka 84
        scr->buffer[i].character = ' ';
85
        scr->buffer[i].style = scr->style;
86
    }
87
 
88
    scr->top_line = 0;
89
    scr->position_y = 0;
90
    scr->position_x = 0;
91
}
92
 
1526 cejka 93
/** Clear one buffer line.
1487 cejka 94
 * @param scr
95
 * @param line One buffer line (not a screen line!)
96
 */
97
void screenbuffer_clear_line(screenbuffer_t *scr, unsigned int line)
98
{
99
    unsigned int i;
100
 
101
    for (i = 0; i < scr->size_x; i++) {
102
        scr->buffer[i + line*scr->size_x].character = ' ';
103
        scr->buffer[i + line*scr->size_x].style = scr->style;
104
    }
105
}
106
 
1526 cejka 107
/** Copy content buffer from screenbuffer to given memory.
108
 * @param scr   source screenbuffer
109
 * @param dest  destination
110
 */
1487 cejka 111
void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest)
112
{
113
    unsigned int i;
114
 
115
    for (i = 0; i < scr->size_x * scr->size_y; i++) {
116
        dest[i] = scr->buffer[i];
117
    }
118
}
119
 
1526 cejka 120
/** Set new cursor position in screenbuffer.
121
 * @param scr
122
 * @param x
123
 * @param y
124
 */
1487 cejka 125
void screenbuffer_goto(screenbuffer_t *scr, unsigned int x, unsigned int y)
126
{
127
    scr->position_x = x % scr->size_x;
1525 cejka 128
    scr->position_y = y % scr->size_y;
1487 cejka 129
}
130
 
1526 cejka 131
/** Set new style.
132
 * @param scr
133
 * @param fg_color
134
 * @param bg_color
135
 */
1525 cejka 136
void screenbuffer_set_style(screenbuffer_t *scr, unsigned int fg_color, unsigned int bg_color)
137
{
138
    scr->style.fg_color = fg_color;
139
    scr->style.bg_color = bg_color;
140
}
141
 
1649 cejka 142
 
143
/** @}
144
 */
145