Notcurses 3.0.13
a blingful library for TUIs and character graphics
Loading...
Searching...
No Matches
Palette.hh
Go to the documentation of this file.
1#ifndef __NCPP_PALETTE_HH
2#define __NCPP_PALETTE_HH
3
4#include "Root.hh"
5#include "_helpers.hh"
6
7namespace ncpp
8{
9 class NotCurses;
10
12 {
13 public:
14 Palette (NotCurses *ncinst = nullptr)
15 : Root (ncinst)
16 {
17 palette = ncpalette_new (get_notcurses ());
18 if (palette == nullptr)
19 throw init_error ("Notcurses failed to create a new palette");
20 }
21
23 {
24 ncpalette_free (palette);
25 }
26
27 operator ncpalette* () noexcept
28 {
29 return palette;
30 }
31
32 operator ncpalette const* () const noexcept
33 {
34 return palette;
35 }
36
37 bool set (int idx, int r, int g, int b) const NOEXCEPT_MAYBE
38 {
39 return error_guard (ncpalette_set_rgb8 (palette, idx, r, g, b), -1);
40 }
41
42 bool set (int idx, unsigned rgb) const NOEXCEPT_MAYBE
43 {
44 return error_guard (ncpalette_set (palette, idx, rgb), -1);
45 }
46
47 bool get (int idx, unsigned *r, unsigned *g, unsigned *b) const
48 {
49 if (r == nullptr)
50 throw invalid_argument ("'r' must be a valid pointer");
51 if (g == nullptr)
52 throw invalid_argument ("'g' must be a valid pointer");
53 if (b == nullptr)
54 throw invalid_argument ("'b' must be a valid pointer");
55
56 return get (idx, *r, *g, *b);
57 }
58
59 bool get (int idx, unsigned &r, unsigned &g, unsigned &b) const NOEXCEPT_MAYBE
60 {
61 return error_guard (ncpalette_get_rgb8 (palette, idx, &r, &g, &b), -1);
62 }
63
64 private:
65 ncpalette *palette;
66 };
67}
68#endif
#define NCPP_API_EXPORT
Definition _helpers.hh:9
#define NOEXCEPT_MAYBE
Definition Root.hh:15
bool set(int idx, int r, int g, int b) const NOEXCEPT_MAYBE
Definition Palette.hh:37
Palette(NotCurses *ncinst=nullptr)
Definition Palette.hh:14
bool get(int idx, unsigned *r, unsigned *g, unsigned *b) const
Definition Palette.hh:47
bool get(int idx, unsigned &r, unsigned &g, unsigned &b) const NOEXCEPT_MAYBE
Definition Palette.hh:59
bool set(int idx, unsigned rgb) const NOEXCEPT_MAYBE
Definition Palette.hh:42
uint32_t idx
Definition egcpool.h:298
int r
Definition fbuf.h:226
void ncpalette_free(ncpalette *p)
Definition notcurses.c:2586
ncpalette * ncpalette_new(notcurses *nc)
Definition notcurses.c:2563