source: mainline/uspace/srv/console/screenbuffer.c@ 7ce3cb2

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 7ce3cb2 was 7ce3cb2, checked in by Jiri Svoboda <jirik.svoboda@…>, 16 years ago

Define wchar_t in userspace. Use it in fb and console.

  • Property mode set to 100644
File size: 4.6 KB
RevLine 
[3993b3d]1/*
[df4ed85]2 * Copyright (c) 2006 Josef Cejka
[3993b3d]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
[ce5bcb4]29/** @addtogroup console
30 * @{
31 */
32/** @file
33 */
34
[3993b3d]35#include <screenbuffer.h>
[9805cde]36#include <console/style.h>
[3993b3d]37#include <malloc.h>
38#include <unistd.h>
39
[c738d65]40/** Store one character to screenbuffer. Its position is determined by
41 * scr->position_x and scr->position_y.
42 *
[a9bd960c]43 * @param scr screenbuffer
44 * @param c stored character
[3993b3d]45 */
[7ce3cb2]46void screenbuffer_putchar(screenbuffer_t *scr, wchar_t ch)
[3993b3d]47{
48 keyfield_t *field;
[7ce3cb2]49
[3993b3d]50 field = get_field_at(scr, scr->position_x, scr->position_y);
51
[7ce3cb2]52 field->character = ch;
[9805cde]53 field->attrs = scr->attrs;
[3993b3d]54}
55
[a9bd960c]56/** Initilize screenbuffer. Allocate space for screen content in accordance to given size.
57 * @param scr initialized screenbuffer
[e87e18f]58 * @param size_x width in characters
59 * @param size_y height in characters
60 * @return pointer to screenbuffer (same as scr parameter) or NULL
[a9bd960c]61 */
[3993b3d]62screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, int size_x, int size_y)
63{
[c738d65]64 scr->buffer = (keyfield_t *) malloc(sizeof(keyfield_t) * size_x * size_y);
65 if (!scr->buffer) {
[3993b3d]66 return NULL;
67 }
68
69 scr->size_x = size_x;
70 scr->size_y = size_y;
[9805cde]71 scr->attrs.t = at_style;
72 scr->attrs.a.s.style = STYLE_NORMAL;
[a8b2b5b2]73 scr->is_cursor_visible = 1;
[10569b1]74
75 screenbuffer_clear(scr);
76
[3993b3d]77 return scr;
78}
79
[e87e18f]80/** Clear screenbuffer.
81 * @param scr screenbuffer
82 */
[3993b3d]83void screenbuffer_clear(screenbuffer_t *scr)
84{
85 unsigned int i;
86
[10569b1]87 for (i = 0; i < (scr->size_x * scr->size_y); i++) {
[3993b3d]88 scr->buffer[i].character = ' ';
[9805cde]89 scr->buffer[i].attrs = scr->attrs;
[3993b3d]90 }
91
92 scr->top_line = 0;
93 scr->position_y = 0;
94 scr->position_x = 0;
95}
96
[e87e18f]97/** Clear one buffer line.
[3993b3d]98 * @param scr
99 * @param line One buffer line (not a screen line!)
100 */
101void screenbuffer_clear_line(screenbuffer_t *scr, unsigned int line)
102{
103 unsigned int i;
104
105 for (i = 0; i < scr->size_x; i++) {
[c738d65]106 scr->buffer[i + line * scr->size_x].character = ' ';
[9805cde]107 scr->buffer[i + line * scr->size_x].attrs = scr->attrs;
[3993b3d]108 }
109}
110
[e87e18f]111/** Copy content buffer from screenbuffer to given memory.
112 * @param scr source screenbuffer
113 * @param dest destination
114 */
[3993b3d]115void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest)
116{
117 unsigned int i;
118
119 for (i = 0; i < scr->size_x * scr->size_y; i++) {
120 dest[i] = scr->buffer[i];
121 }
122}
123
[e87e18f]124/** Set new cursor position in screenbuffer.
125 * @param scr
126 * @param x
127 * @param y
128 */
[3993b3d]129void screenbuffer_goto(screenbuffer_t *scr, unsigned int x, unsigned int y)
130{
131 scr->position_x = x % scr->size_x;
[a9bd960c]132 scr->position_y = y % scr->size_y;
133}
134
[e87e18f]135/** Set new style.
136 * @param scr
137 * @param fg_color
138 * @param bg_color
139 */
[9805cde]140void screenbuffer_set_style(screenbuffer_t *scr, int style)
[a9bd960c]141{
[9805cde]142 scr->attrs.t = at_style;
143 scr->attrs.a.s.style = style;
144}
145
146/** Set new color.
147 * @param scr
148 * @param fg_color
149 * @param bg_color
150 */
151void screenbuffer_set_color(screenbuffer_t *scr, unsigned int fg_color, unsigned int bg_color, unsigned int flags)
152{
153 scr->attrs.t = at_idx;
154 scr->attrs.a.i.fg_color = fg_color;
155 scr->attrs.a.i.bg_color = bg_color;
156 scr->attrs.a.i.flags = flags;
157}
158
159/** Set new RGB color.
160 * @param scr
161 * @param fg_color
162 * @param bg_color
163 */
164void screenbuffer_set_rgb_color(screenbuffer_t *scr, unsigned int fg_color, unsigned int bg_color)
165{
166 scr->attrs.t = at_rgb;
167 scr->attrs.a.r.fg_color = fg_color;
168 scr->attrs.a.r.bg_color = bg_color;
[3993b3d]169}
170
[ce5bcb4]171
172/** @}
173 */
Note: See TracBrowser for help on using the repository browser.