source: mainline/uspace/lib/c/include/io/charfield.h@ cd1e3fc0

Last change on this file since cd1e3fc0 was d7f7a4a, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 3 years ago

Replace some license headers with SPDX identifier

Headers are replaced using tools/transorm-copyright.sh only
when it can be matched verbatim with the license header used
throughout most of the codebase.

  • Property mode set to 100644
File size: 1.5 KB
RevLine 
[7c014d1]1/*
[d7f7a4a]2 * SPDX-FileCopyrightText: 2006 Josef Cejka
3 * SPDX-FileCopyrightText: 2011 Petr Koupy
[7c014d1]4 *
[d7f7a4a]5 * SPDX-License-Identifier: BSD-3-Clause
[7c014d1]6 */
7
8/** @addtogroup libc
9 * @{
10 */
11/** @file
12 */
13
[4805495]14#ifndef _LIBC_IO_CHARFIELD_H_
15#define _LIBC_IO_CHARFIELD_H_
[7c014d1]16
[3e6a98c5]17#include <stdbool.h>
[28a5ebd]18#include <uchar.h>
[7c014d1]19#include <io/color.h>
20#include <io/style.h>
[6d5e378]21#include <io/pixel.h>
[7c014d1]22
23typedef enum {
[6d5e378]24 CHAR_FLAG_NONE = 0,
25 CHAR_FLAG_DIRTY = 1
26} char_flags_t;
[7c014d1]27
28typedef enum {
29 CHAR_ATTR_STYLE,
30 CHAR_ATTR_INDEX,
31 CHAR_ATTR_RGB
32} char_attr_type_t;
33
34typedef struct {
35 console_color_t bgcolor;
36 console_color_t fgcolor;
37 console_color_attr_t attr;
38} char_attr_index_t;
39
40typedef struct {
[6d5e378]41 pixel_t bgcolor;
42 pixel_t fgcolor;
[7c014d1]43} char_attr_rgb_t;
44
45typedef union {
46 console_style_t style;
47 char_attr_index_t index;
48 char_attr_rgb_t rgb;
49} char_attr_val_t;
50
51typedef struct {
52 char_attr_type_t type;
53 char_attr_val_t val;
54} char_attrs_t;
55
56typedef struct {
[28a5ebd]57 char32_t ch;
[6d5e378]58 char_attrs_t attrs;
59 char_flags_t flags;
[7c014d1]60} charfield_t;
61
62static inline bool attrs_same(char_attrs_t a1, char_attrs_t a2)
63{
64 if (a1.type != a2.type)
65 return false;
[a35b458]66
[7c014d1]67 switch (a1.type) {
68 case CHAR_ATTR_STYLE:
69 return (a1.val.style == a2.val.style);
70 case CHAR_ATTR_INDEX:
[3bacee1]71 return (a1.val.index.bgcolor == a2.val.index.bgcolor) &&
72 (a1.val.index.fgcolor == a2.val.index.fgcolor) &&
73 (a1.val.index.attr == a2.val.index.attr);
[7c014d1]74 case CHAR_ATTR_RGB:
[3bacee1]75 return (a1.val.rgb.bgcolor == a2.val.rgb.bgcolor) &&
76 (a1.val.rgb.fgcolor == a2.val.rgb.fgcolor);
[7c014d1]77 }
[a35b458]78
[7c014d1]79 return false;
80}
81
82#endif
83
84/** @}
85 */
Note: See TracBrowser for help on using the repository browser.