Notcurses 3.0.16
a blingful library for TUIs and character graphics
Loading...
Searching...
No Matches
Cell.hh
Go to the documentation of this file.
1#ifndef __NCPP_CELL_HH
2#define __NCPP_CELL_HH
3
4#include <map>
5#include <mutex>
7
8#include "Root.hh"
9#include "CellStyle.hh"
10
11namespace ncpp
12{
13 class NotCurses;
14
15 class NCPP_API_EXPORT Cell : public Root
16 {
17 public:
18 static constexpr int AlphaHighContrast = NCALPHA_HIGHCONTRAST;
19 static constexpr int AlphaTransparent = NCALPHA_TRANSPARENT;
20 static constexpr int AlphaBlend = NCALPHA_BLEND;
21 static constexpr int AlphaOpaque = NCALPHA_OPAQUE;
22
23 public:
24 Cell (NotCurses *ncinst = nullptr) noexcept
25 : Root (ncinst)
26 {
27 init ();
28 }
29
30 explicit Cell (uint32_t c, NotCurses *ncinst = nullptr) noexcept
31 : Root (ncinst)
32 {
33 _cell = NCCELL_CHAR_INITIALIZER (c);
34 }
35
36 explicit Cell (uint32_t c, uint16_t a, uint64_t chan, NotCurses *ncinst = nullptr) noexcept
37 : Root (ncinst)
38 {
39 _cell = NCCELL_INITIALIZER (c, a, chan);
40 }
41
42 operator nccell* () noexcept
43 {
44 return &_cell;
45 }
46
47 operator nccell const* () const noexcept
48 {
49 return &_cell;
50 }
51
52 nccell& get () noexcept
53 {
54 return _cell;
55 }
56
57 void init () noexcept
58 {
59 nccell_init (&_cell);
60 }
61
62 uint16_t get_stylemask () const noexcept
63 {
64 return _cell.stylemask;
65 }
66
67 uint64_t get_channels () const noexcept
68 {
69 return _cell.channels;
70 }
71
72 void set_styles (CellStyle styles) noexcept
73 {
74 nccell_set_styles (&_cell, static_cast<unsigned>(styles));
75 }
76
78 {
79 return static_cast<CellStyle>(nccell_styles (&_cell));
80 }
81
82 void styles_on (CellStyle styles) noexcept
83 {
84 nccell_on_styles (&_cell, static_cast<unsigned>(styles));
85 }
86
87 void styles_off (CellStyle styles) noexcept
88 {
89 nccell_off_styles (&_cell, static_cast<unsigned>(styles));
90 }
91
92 bool is_double_wide () const noexcept
93 {
94 return nccell_double_wide_p (&_cell);
95 }
96
97 unsigned get_fg_rgb () const noexcept
98 {
99 return nccell_fg_rgb (&_cell);
100 }
101
102 unsigned get_bg_rgb () const noexcept
103 {
104 return nccell_bg_rgb (&_cell);
105 }
106
107 unsigned get_fg_alpha () const noexcept
108 {
109 return nccell_fg_alpha (&_cell);
110 }
111
112 bool is_fg_default () const noexcept
113 {
114 return nccell_fg_default_p (&_cell);
115 }
116
117 bool set_fg_alpha (unsigned alpha) noexcept
118 {
119 return nccell_set_fg_alpha (&_cell, alpha) != -1;
120 }
121
122 unsigned get_bg_alpha () const noexcept
123 {
124 return nccell_bg_alpha (&_cell);
125 }
126
127 bool set_bg_alpha (unsigned alpha) noexcept
128 {
129 return nccell_set_bg_alpha (&_cell, alpha) != -1;
130 }
131
132 unsigned get_fg_rgb8 (unsigned *r, unsigned *g, unsigned *b) const noexcept
133 {
134 return nccell_fg_rgb8 (&_cell, r, g, b);
135 }
136
137 bool set_fg_rgb8 (int r, int g, int b, bool clipped = false) noexcept
138 {
139 if (clipped) {
140 nccell_set_fg_rgb8_clipped (&_cell, r, g, b);
141 return true;
142 }
143
144 return nccell_set_fg_rgb8 (&_cell, r, g, b) != -1;
145 }
146
147 void set_fg_rgb (uint32_t channel) noexcept
148 {
149 nccell_set_fg_rgb (&_cell, channel);
150 }
151
152 void set_fg_default () noexcept
153 {
154 nccell_set_fg_default (&_cell);
155 }
156
157 unsigned get_bg_rgb8 (unsigned *r, unsigned *g, unsigned *b) const noexcept
158 {
159 return nccell_bg_rgb8 (&_cell, r, g, b);
160 }
161
162 bool set_bg_rgb8 (int r, int g, int b, bool clipped = false) noexcept
163 {
164 if (clipped) {
165 nccell_set_bg_rgb8_clipped (&_cell, r, g, b);
166 return true;
167 }
168
169 return nccell_set_bg_rgb8 (&_cell, r, g, b) != -1;
170 }
171
172 void set_bg_rgb (uint32_t channel) noexcept
173 {
174 nccell_set_bg_rgb (&_cell, channel);
175 }
176
177 void set_bg_default () noexcept
178 {
179 nccell_set_bg_default (&_cell);
180 }
181
182 bool is_bg_default () const noexcept
183 {
184 return nccell_bg_default_p (&_cell);
185 }
186
187 bool is_wide_right () const noexcept
188 {
189 return nccell_wide_right_p (&_cell);
190 }
191
192 bool is_wide_left () const noexcept
193 {
194 return nccell_wide_left_p (&_cell);
195 }
196
197 private:
198 nccell _cell;
199 };
200}
201
202#endif
#define NCPP_API_EXPORT
Definition _helpers.hh:9
void set_fg_rgb(uint32_t channel) noexcept
Definition Cell.hh:147
uint16_t get_stylemask() const noexcept
Definition Cell.hh:62
bool set_bg_rgb8(int r, int g, int b, bool clipped=false) noexcept
Definition Cell.hh:162
Cell(uint32_t c, NotCurses *ncinst=nullptr) noexcept
Definition Cell.hh:30
unsigned get_fg_rgb() const noexcept
Definition Cell.hh:97
bool is_double_wide() const noexcept
Definition Cell.hh:92
unsigned get_bg_alpha() const noexcept
Definition Cell.hh:122
bool set_fg_alpha(unsigned alpha) noexcept
Definition Cell.hh:117
bool is_fg_default() const noexcept
Definition Cell.hh:112
unsigned get_fg_alpha() const noexcept
Definition Cell.hh:107
bool is_wide_right() const noexcept
Definition Cell.hh:187
bool set_bg_alpha(unsigned alpha) noexcept
Definition Cell.hh:127
void set_fg_default() noexcept
Definition Cell.hh:152
nccell & get() noexcept
Definition Cell.hh:52
bool is_bg_default() const noexcept
Definition Cell.hh:182
void styles_off(CellStyle styles) noexcept
Definition Cell.hh:87
void set_bg_default() noexcept
Definition Cell.hh:177
bool is_wide_left() const noexcept
Definition Cell.hh:192
bool set_fg_rgb8(int r, int g, int b, bool clipped=false) noexcept
Definition Cell.hh:137
unsigned get_bg_rgb() const noexcept
Definition Cell.hh:102
Cell(uint32_t c, uint16_t a, uint64_t chan, NotCurses *ncinst=nullptr) noexcept
Definition Cell.hh:36
unsigned get_fg_rgb8(unsigned *r, unsigned *g, unsigned *b) const noexcept
Definition Cell.hh:132
void styles_on(CellStyle styles) noexcept
Definition Cell.hh:82
unsigned get_bg_rgb8(unsigned *r, unsigned *g, unsigned *b) const noexcept
Definition Cell.hh:157
void set_bg_rgb(uint32_t channel) noexcept
Definition Cell.hh:172
CellStyle get_styles() noexcept
Definition Cell.hh:77
void init() noexcept
Definition Cell.hh:57
Cell(NotCurses *ncinst=nullptr) noexcept
Definition Cell.hh:24
void set_styles(CellStyle styles) noexcept
Definition Cell.hh:72
uint64_t get_channels() const noexcept
Definition Cell.hh:67
const nccell * c
Definition egcpool.h:207
int r
Definition fbuf.h:226
CellStyle
Definition CellStyle.hh:13
#define NCALPHA_OPAQUE
Definition notcurses.h:108
#define NCCELL_CHAR_INITIALIZER(c)
Definition notcurses.h:734
#define NCALPHA_TRANSPARENT
Definition notcurses.h:106
#define NCALPHA_BLEND
Definition notcurses.h:107
#define NCCELL_INITIALIZER(c, s, chan)
Definition notcurses.h:731
#define NCALPHA_HIGHCONTRAST
Definition notcurses.h:105