2020-01-07 22:51:34 +00:00
|
|
|
#ifndef __NCPP_CELL_HH
|
|
|
|
#define __NCPP_CELL_HH
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <mutex>
|
2020-02-18 17:36:16 +00:00
|
|
|
#include <notcurses/notcurses.h>
|
2020-01-07 22:51:34 +00:00
|
|
|
|
|
|
|
#include "Root.hh"
|
|
|
|
#include "CellStyle.hh"
|
|
|
|
|
|
|
|
namespace ncpp
|
|
|
|
{
|
2020-05-24 12:41:18 +00:00
|
|
|
class NotCurses;
|
|
|
|
|
2020-01-07 22:51:34 +00:00
|
|
|
class NCPP_API_EXPORT Cell : public Root
|
|
|
|
{
|
|
|
|
public:
|
2021-07-10 21:51:06 +00:00
|
|
|
static constexpr int AlphaHighContrast = NCALPHA_HIGHCONTRAST;
|
|
|
|
static constexpr int AlphaTransparent = NCALPHA_TRANSPARENT;
|
|
|
|
static constexpr int AlphaBlend = NCALPHA_BLEND;
|
|
|
|
static constexpr int AlphaOpaque = NCALPHA_OPAQUE;
|
2020-01-07 22:51:34 +00:00
|
|
|
|
|
|
|
public:
|
2020-05-24 12:41:18 +00:00
|
|
|
Cell (NotCurses *ncinst = nullptr) noexcept
|
|
|
|
: Root (ncinst)
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
|
|
|
init ();
|
|
|
|
}
|
|
|
|
|
2020-05-24 12:41:18 +00:00
|
|
|
explicit Cell (uint32_t c, NotCurses *ncinst = nullptr) noexcept
|
|
|
|
: Root (ncinst)
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
2020-08-31 23:39:07 +00:00
|
|
|
_cell = CELL_CHAR_INITIALIZER (c);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 23:25:08 +00:00
|
|
|
explicit Cell (uint32_t c, uint16_t a, uint64_t chan, NotCurses *ncinst = nullptr) noexcept
|
2020-05-24 12:41:18 +00:00
|
|
|
: Root (ncinst)
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
|
|
|
_cell = CELL_INITIALIZER (c, a, chan);
|
|
|
|
}
|
|
|
|
|
2020-12-13 05:19:24 +00:00
|
|
|
operator nccell* () noexcept
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
|
|
|
return &_cell;
|
|
|
|
}
|
|
|
|
|
2020-12-13 05:19:24 +00:00
|
|
|
operator nccell const* () const noexcept
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
|
|
|
return &_cell;
|
|
|
|
}
|
|
|
|
|
2020-12-13 05:19:24 +00:00
|
|
|
nccell& get () noexcept
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
|
|
|
return _cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
void init () noexcept
|
|
|
|
{
|
2021-04-14 10:42:14 +00:00
|
|
|
nccell_init (&_cell);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 23:25:08 +00:00
|
|
|
uint16_t get_stylemask () const noexcept
|
2020-02-22 19:01:52 +00:00
|
|
|
{
|
2020-08-15 23:25:08 +00:00
|
|
|
return _cell.stylemask;
|
2020-02-22 19:01:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t get_channels () const noexcept
|
|
|
|
{
|
|
|
|
return _cell.channels;
|
|
|
|
}
|
|
|
|
|
2020-01-07 22:51:34 +00:00
|
|
|
void set_styles (CellStyle styles) noexcept
|
|
|
|
{
|
2021-04-10 13:21:52 +00:00
|
|
|
nccell_set_styles (&_cell, static_cast<unsigned>(styles));
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CellStyle get_styles () noexcept
|
|
|
|
{
|
2021-04-10 13:21:52 +00:00
|
|
|
return static_cast<CellStyle>(nccell_styles (&_cell));
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void styles_on (CellStyle styles) noexcept
|
|
|
|
{
|
2021-04-14 13:05:00 +00:00
|
|
|
nccell_on_styles (&_cell, static_cast<unsigned>(styles));
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void styles_off (CellStyle styles) noexcept
|
|
|
|
{
|
2021-04-14 13:05:00 +00:00
|
|
|
nccell_off_styles (&_cell, static_cast<unsigned>(styles));
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool is_double_wide () const noexcept
|
|
|
|
{
|
2021-04-15 05:31:12 +00:00
|
|
|
return nccell_double_wide_p (&_cell);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-17 19:34:28 +00:00
|
|
|
unsigned get_fg_rgb () const noexcept
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
2021-04-16 02:29:53 +00:00
|
|
|
return nccell_fg_rgb (&_cell);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-17 19:34:28 +00:00
|
|
|
unsigned get_bg_rgb () const noexcept
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
2021-04-16 02:29:53 +00:00
|
|
|
return nccell_bg_rgb (&_cell);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned get_fg_alpha () const noexcept
|
|
|
|
{
|
2021-04-15 05:31:12 +00:00
|
|
|
return nccell_fg_alpha (&_cell);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool is_fg_default () const noexcept
|
|
|
|
{
|
2021-04-15 05:31:12 +00:00
|
|
|
return nccell_fg_default_p (&_cell);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
2020-07-31 20:59:59 +00:00
|
|
|
bool set_fg_alpha (unsigned alpha) noexcept
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
2021-04-14 13:05:00 +00:00
|
|
|
return nccell_set_fg_alpha (&_cell, alpha) != -1;
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned get_bg_alpha () const noexcept
|
|
|
|
{
|
2021-04-15 05:31:12 +00:00
|
|
|
return nccell_bg_alpha (&_cell);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
2020-07-31 20:59:59 +00:00
|
|
|
bool set_bg_alpha (unsigned alpha) noexcept
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
2021-04-14 13:05:00 +00:00
|
|
|
return nccell_set_bg_alpha (&_cell, alpha) != -1;
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-17 19:34:28 +00:00
|
|
|
unsigned get_fg_rgb8 (unsigned *r, unsigned *g, unsigned *b) const noexcept
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
2021-04-14 13:31:50 +00:00
|
|
|
return nccell_fg_rgb8 (&_cell, r, g, b);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-17 19:34:28 +00:00
|
|
|
bool set_fg_rgb8 (int r, int g, int b, bool clipped = false) noexcept
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
|
|
|
if (clipped) {
|
2021-04-14 13:31:50 +00:00
|
|
|
nccell_set_fg_rgb8_clipped (&_cell, r, g, b);
|
2020-01-07 22:51:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-04-14 13:31:50 +00:00
|
|
|
return nccell_set_fg_rgb8 (&_cell, r, g, b) != -1;
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-17 19:34:28 +00:00
|
|
|
void set_fg_rgb (uint32_t channel) noexcept
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
2021-04-14 13:31:50 +00:00
|
|
|
nccell_set_fg_rgb (&_cell, channel);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void set_fg_default () noexcept
|
|
|
|
{
|
2021-04-14 13:05:00 +00:00
|
|
|
nccell_set_fg_default (&_cell);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-17 19:34:28 +00:00
|
|
|
unsigned get_bg_rgb8 (unsigned *r, unsigned *g, unsigned *b) const noexcept
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
2021-04-14 13:31:50 +00:00
|
|
|
return nccell_bg_rgb8 (&_cell, r, g, b);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-17 19:34:28 +00:00
|
|
|
bool set_bg_rgb8 (int r, int g, int b, bool clipped = false) noexcept
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
|
|
|
if (clipped) {
|
2021-04-16 02:29:53 +00:00
|
|
|
nccell_set_bg_rgb8_clipped (&_cell, r, g, b);
|
2020-01-07 22:51:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-04-14 13:31:50 +00:00
|
|
|
return nccell_set_bg_rgb8 (&_cell, r, g, b) != -1;
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-17 19:34:28 +00:00
|
|
|
void set_bg_rgb (uint32_t channel) noexcept
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
2021-04-14 13:31:50 +00:00
|
|
|
nccell_set_bg_rgb (&_cell, channel);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void set_bg_default () noexcept
|
|
|
|
{
|
2021-04-14 13:05:00 +00:00
|
|
|
nccell_set_bg_default (&_cell);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool is_bg_default () const noexcept
|
|
|
|
{
|
2021-04-15 05:31:12 +00:00
|
|
|
return nccell_bg_default_p (&_cell);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool is_wide_right () const noexcept
|
|
|
|
{
|
2021-04-15 05:31:12 +00:00
|
|
|
return nccell_wide_right_p (&_cell);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool is_wide_left () const noexcept
|
|
|
|
{
|
2021-04-15 05:31:12 +00:00
|
|
|
return nccell_wide_left_p (&_cell);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-12-13 05:19:24 +00:00
|
|
|
nccell _cell;
|
2020-01-07 22:51:34 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|