1 | /*
|
---|
2 | * Copyright (c) 2006 Josef Cejka
|
---|
3 | * Copyright (c) 2011 Petr Koupy
|
---|
4 | * All rights reserved.
|
---|
5 | *
|
---|
6 | * Redistribution and use in source and binary forms, with or without
|
---|
7 | * modification, are permitted provided that the following conditions
|
---|
8 | * are met:
|
---|
9 | *
|
---|
10 | * - Redistributions of source code must retain the above copyright
|
---|
11 | * notice, this list of conditions and the following disclaimer.
|
---|
12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
13 | * notice, this list of conditions and the following disclaimer in the
|
---|
14 | * documentation and/or other materials provided with the distribution.
|
---|
15 | * - The name of the author may not be used to endorse or promote products
|
---|
16 | * derived from this software without specific prior written permission.
|
---|
17 | *
|
---|
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
28 | */
|
---|
29 |
|
---|
30 | /** @addtogroup libc
|
---|
31 | * @{
|
---|
32 | */
|
---|
33 | /** @file
|
---|
34 | */
|
---|
35 |
|
---|
36 | #ifndef LIBC_IO_CHARFIELD_H_
|
---|
37 | #define LIBC_IO_CHARFIELD_H_
|
---|
38 |
|
---|
39 | #include <stdbool.h>
|
---|
40 | #include <io/color.h>
|
---|
41 | #include <io/style.h>
|
---|
42 | #include <io/pixel.h>
|
---|
43 |
|
---|
44 | typedef enum {
|
---|
45 | CHAR_FLAG_NONE = 0,
|
---|
46 | CHAR_FLAG_DIRTY = 1
|
---|
47 | } char_flags_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 struct {
|
---|
56 | console_color_t bgcolor;
|
---|
57 | console_color_t fgcolor;
|
---|
58 | console_color_attr_t attr;
|
---|
59 | } char_attr_index_t;
|
---|
60 |
|
---|
61 | typedef struct {
|
---|
62 | pixel_t bgcolor;
|
---|
63 | pixel_t fgcolor;
|
---|
64 | } char_attr_rgb_t;
|
---|
65 |
|
---|
66 | typedef union {
|
---|
67 | console_style_t style;
|
---|
68 | char_attr_index_t index;
|
---|
69 | char_attr_rgb_t rgb;
|
---|
70 | } char_attr_val_t;
|
---|
71 |
|
---|
72 | typedef struct {
|
---|
73 | char_attr_type_t type;
|
---|
74 | char_attr_val_t val;
|
---|
75 | } char_attrs_t;
|
---|
76 |
|
---|
77 | typedef struct {
|
---|
78 | wchar_t ch;
|
---|
79 | char_attrs_t attrs;
|
---|
80 | char_flags_t flags;
|
---|
81 | } charfield_t;
|
---|
82 |
|
---|
83 | static inline bool attrs_same(char_attrs_t a1, char_attrs_t a2)
|
---|
84 | {
|
---|
85 | if (a1.type != a2.type)
|
---|
86 | return false;
|
---|
87 |
|
---|
88 | switch (a1.type) {
|
---|
89 | case CHAR_ATTR_STYLE:
|
---|
90 | return (a1.val.style == a2.val.style);
|
---|
91 | case CHAR_ATTR_INDEX:
|
---|
92 | return (a1.val.index.bgcolor == a2.val.index.bgcolor)
|
---|
93 | && (a1.val.index.fgcolor == a2.val.index.fgcolor)
|
---|
94 | && (a1.val.index.attr == a2.val.index.attr);
|
---|
95 | case CHAR_ATTR_RGB:
|
---|
96 | return (a1.val.rgb.bgcolor == a2.val.rgb.bgcolor)
|
---|
97 | && (a1.val.rgb.fgcolor == a2.val.rgb.fgcolor);
|
---|
98 | }
|
---|
99 |
|
---|
100 | return false;
|
---|
101 | }
|
---|
102 |
|
---|
103 | #endif
|
---|
104 |
|
---|
105 | /** @}
|
---|
106 | */
|
---|