source: mainline/uspace/lib/c/include/io/screenbuffer.h@ f3b4051

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since f3b4051 was 369a5f8, checked in by Martin Decky <martin@…>, 16 years ago

add STYLE_SELECTED and STYLE_INVERTED into serial output driver
move screenbuffer.{c|h} into libc, make it slightly more generic
collateral changes

  • Property mode set to 100644
File size: 4.6 KB
Line 
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
29/** @addtogroup console
30 * @{
31 */
32/** @file
33 */
34
35#ifndef LIBC_SCREENBUFFER_H__
36#define LIBC_SCREENBUFFER_H__
37
38#include <stdint.h>
39#include <sys/types.h>
40#include <ipc/ipc.h>
41#include <bool.h>
42
43typedef enum {
44 at_style,
45 at_idx,
46 at_rgb
47} attr_type_t;
48
49typedef struct {
50 uint8_t style;
51} attr_style_t;
52
53typedef struct {
54 uint8_t fg_color;
55 uint8_t bg_color;
56 uint8_t flags;
57} attr_idx_t;
58
59typedef struct {
60 uint32_t bg_color; /**< background color */
61 uint32_t fg_color; /**< foreground color */
62} attr_rgb_t;
63
64typedef union {
65 attr_style_t s;
66 attr_idx_t i;
67 attr_rgb_t r;
68} attr_val_t;
69
70typedef struct {
71 attr_type_t t;
72 attr_val_t a;
73} attrs_t;
74
75/** One field on screen. It contain one character and its attributes. */
76typedef struct {
77 wchar_t character; /**< Character itself */
78 attrs_t attrs; /**< Character attributes */
79} keyfield_t;
80
81/** Structure for buffering state of one virtual console.
82 */
83typedef struct {
84 keyfield_t *buffer; /**< Screen content - characters and
85 their attributes (used as a circular buffer) */
86 ipcarg_t size_x; /**< Number of columns */
87 ipcarg_t size_y; /**< Number of rows */
88
89 /** Coordinates of last printed character for determining cursor position */
90 ipcarg_t position_x;
91 ipcarg_t position_y;
92
93 attrs_t attrs; /**< Current attributes. */
94 size_t top_line; /**< Points to buffer[][] line that will
95 be printed at screen as the first line */
96 bool is_cursor_visible; /**< Cursor state - default is visible */
97} screenbuffer_t;
98
99/** Returns keyfield for position on screen
100 *
101 * Screenbuffer->buffer is cyclic buffer so we
102 * must couted in index of the topmost line.
103 *
104 * @param scr Screenbuffer
105 * @param x Position on screen
106 * @param y Position on screen
107 *
108 * @return Keyfield structure with character and its attributes on x, y
109 *
110 */
111static inline keyfield_t *get_field_at(screenbuffer_t *scr, ipcarg_t x, ipcarg_t y)
112{
113 return scr->buffer + x + ((y + scr->top_line) % scr->size_y) * scr->size_x;
114}
115
116/** Compares two sets of attributes.
117 *
118 * @param s1 First style
119 * @param s2 Second style
120 *
121 * @return Nonzero on equality
122 *
123 */
124static inline bool attrs_same(attrs_t a1, attrs_t a2)
125{
126 if (a1.t != a2.t)
127 return false;
128
129 switch (a1.t) {
130 case at_style:
131 return (a1.a.s.style == a2.a.s.style);
132 case at_idx:
133 return (a1.a.i.fg_color == a2.a.i.fg_color)
134 && (a1.a.i.bg_color == a2.a.i.bg_color)
135 && (a1.a.i.flags == a2.a.i.flags);
136 case at_rgb:
137 return (a1.a.r.fg_color == a2.a.r.fg_color)
138 && (a1.a.r.bg_color == a2.a.r.bg_color);
139 }
140
141 return false;
142}
143
144extern void screenbuffer_putchar(screenbuffer_t *, wchar_t);
145extern screenbuffer_t *screenbuffer_init(screenbuffer_t *, ipcarg_t, ipcarg_t);
146
147extern void screenbuffer_clear(screenbuffer_t *);
148extern void screenbuffer_clear_line(screenbuffer_t *, ipcarg_t);
149extern void screenbuffer_copy_buffer(screenbuffer_t *, keyfield_t *);
150extern void screenbuffer_goto(screenbuffer_t *, ipcarg_t, ipcarg_t);
151extern void screenbuffer_set_style(screenbuffer_t *, uint8_t);
152extern void screenbuffer_set_color(screenbuffer_t *, uint8_t, uint8_t, uint8_t);
153extern void screenbuffer_set_rgb_color(screenbuffer_t *, uint32_t, uint32_t);
154
155#endif
156
157/** @}
158 */
Note: See TracBrowser for help on using the repository browser.