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 libc
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /** @file
|
---|
33 | */
|
---|
34 |
|
---|
35 | #ifndef IMGMAP_SCREENBUFFER_H__
|
---|
36 | #define IMGMAP_SCREENBUFFER_H__
|
---|
37 |
|
---|
38 | #include <sys/types.h>
|
---|
39 | #include <bool.h>
|
---|
40 | #include <io/color.h>
|
---|
41 | #include <io/style.h>
|
---|
42 | #include "fb.h"
|
---|
43 |
|
---|
44 | typedef enum {
|
---|
45 | SCREENBUFFER_FLAG_NONE = 0,
|
---|
46 | SCREENBUFFER_FLAG_SHARED = 1
|
---|
47 | } screenbuffer_flag_t;
|
---|
48 |
|
---|
49 | typedef enum {
|
---|
50 | CHAR_ATTR_STYLE,
|
---|
51 | CHAR_ATTR_INDEX,
|
---|
52 | CHAR_ATTR_RGB
|
---|
53 | } char_attr_type_t;
|
---|
54 |
|
---|
55 | typedef enum {
|
---|
56 | CHAR_FLAG_NONE = 0,
|
---|
57 | CHAR_FLAG_DIRTY = 1
|
---|
58 | } char_flags_t;
|
---|
59 |
|
---|
60 | typedef struct {
|
---|
61 | console_color_t bgcolor;
|
---|
62 | console_color_t fgcolor;
|
---|
63 | console_color_attr_t attr;
|
---|
64 | } char_attr_index_t;
|
---|
65 |
|
---|
66 | typedef struct {
|
---|
67 | pixel_t bgcolor; /**< Background color */
|
---|
68 | pixel_t fgcolor; /**< Foreground color */
|
---|
69 | } char_attr_rgb_t;
|
---|
70 |
|
---|
71 | typedef union {
|
---|
72 | console_style_t style;
|
---|
73 | char_attr_index_t index;
|
---|
74 | char_attr_rgb_t rgb;
|
---|
75 | } char_attr_val_t;
|
---|
76 |
|
---|
77 | typedef struct {
|
---|
78 | char_attr_type_t type;
|
---|
79 | char_attr_val_t val;
|
---|
80 | } char_attrs_t;
|
---|
81 |
|
---|
82 | /** One field on screen. It contain one character and its attributes. */
|
---|
83 | typedef struct {
|
---|
84 | wchar_t ch; /**< Character itself */
|
---|
85 | char_attrs_t attrs; /**< Character attributes */
|
---|
86 | char_flags_t flags; /**< Character flags */
|
---|
87 | } charfield_t;
|
---|
88 |
|
---|
89 | /** Compare two sets of attributes.
|
---|
90 | *
|
---|
91 | * @param a1 First attribute.
|
---|
92 | * @param a2 Second attribute.
|
---|
93 | *
|
---|
94 | * @return True on equality
|
---|
95 | *
|
---|
96 | */
|
---|
97 | static inline bool attrs_same(char_attrs_t a1, char_attrs_t a2)
|
---|
98 | {
|
---|
99 | if (a1.type != a2.type)
|
---|
100 | return false;
|
---|
101 |
|
---|
102 | switch (a1.type) {
|
---|
103 | case CHAR_ATTR_STYLE:
|
---|
104 | return (a1.val.style == a2.val.style);
|
---|
105 | case CHAR_ATTR_INDEX:
|
---|
106 | return (a1.val.index.bgcolor == a2.val.index.bgcolor)
|
---|
107 | && (a1.val.index.fgcolor == a2.val.index.fgcolor)
|
---|
108 | && (a1.val.index.attr == a2.val.index.attr);
|
---|
109 | case CHAR_ATTR_RGB:
|
---|
110 | return (a1.val.rgb.bgcolor == a2.val.rgb.bgcolor)
|
---|
111 | && (a1.val.rgb.fgcolor == a2.val.rgb.fgcolor);
|
---|
112 | }
|
---|
113 |
|
---|
114 | return false;
|
---|
115 | }
|
---|
116 |
|
---|
117 | extern screenbuffer_t *screenbuffer_create(sysarg_t, sysarg_t,
|
---|
118 | screenbuffer_flag_t);
|
---|
119 |
|
---|
120 | extern charfield_t *screenbuffer_field_at(screenbuffer_t *, sysarg_t, sysarg_t);
|
---|
121 | extern bool screenbuffer_cursor_at(screenbuffer_t *, sysarg_t, sysarg_t);
|
---|
122 |
|
---|
123 | extern sysarg_t screenbuffer_get_top_row(screenbuffer_t *);
|
---|
124 |
|
---|
125 | extern sysarg_t screenbuffer_putchar(screenbuffer_t *, wchar_t, bool);
|
---|
126 | extern sysarg_t screenbuffer_newline(screenbuffer_t *);
|
---|
127 | extern sysarg_t screenbuffer_tabstop(screenbuffer_t *, sysarg_t);
|
---|
128 | extern sysarg_t screenbuffer_backspace(screenbuffer_t *);
|
---|
129 |
|
---|
130 | extern void screenbuffer_clear(screenbuffer_t *);
|
---|
131 | extern void screenbuffer_clear_row(screenbuffer_t *, sysarg_t);
|
---|
132 |
|
---|
133 | extern void screenbuffer_set_cursor(screenbuffer_t *, sysarg_t, sysarg_t);
|
---|
134 | extern void screenbuffer_set_cursor_visibility(screenbuffer_t *, bool);
|
---|
135 | extern bool screenbuffer_get_cursor_visibility(screenbuffer_t *);
|
---|
136 |
|
---|
137 | extern void screenbuffer_get_cursor(screenbuffer_t *, sysarg_t *, sysarg_t *);
|
---|
138 |
|
---|
139 | extern void screenbuffer_set_style(screenbuffer_t *, console_style_t);
|
---|
140 | extern void screenbuffer_set_color(screenbuffer_t *, console_color_t,
|
---|
141 | console_color_t, console_color_attr_t);
|
---|
142 | extern void screenbuffer_set_rgb_color(screenbuffer_t *, pixel_t, pixel_t);
|
---|
143 |
|
---|
144 | #endif
|
---|
145 |
|
---|
146 | /** @}
|
---|
147 | */
|
---|