You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.4 KiB
C++
69 lines
1.4 KiB
C++
4 years ago
|
#ifndef __NCPP_PALETTE_HH
|
||
|
#define __NCPP_PALETTE_HH
|
||
5 years ago
|
|
||
|
#include "Root.hh"
|
||
|
#include "_helpers.hh"
|
||
|
|
||
|
namespace ncpp
|
||
|
{
|
||
4 years ago
|
class NotCurses;
|
||
|
|
||
4 years ago
|
class NCPP_API_EXPORT Palette : public Root
|
||
5 years ago
|
{
|
||
|
public:
|
||
4 years ago
|
Palette (NotCurses *ncinst = nullptr)
|
||
4 years ago
|
: Root (ncinst)
|
||
5 years ago
|
{
|
||
4 years ago
|
palette = ncpalette_new (get_notcurses ());
|
||
5 years ago
|
if (palette == nullptr)
|
||
4 years ago
|
throw init_error ("Notcurses failed to create a new palette");
|
||
5 years ago
|
}
|
||
|
|
||
4 years ago
|
~Palette ()
|
||
5 years ago
|
{
|
||
4 years ago
|
ncpalette_free (palette);
|
||
5 years ago
|
}
|
||
|
|
||
4 years ago
|
operator ncpalette* () noexcept
|
||
5 years ago
|
{
|
||
|
return palette;
|
||
|
}
|
||
|
|
||
4 years ago
|
operator ncpalette const* () const noexcept
|
||
5 years ago
|
{
|
||
|
return palette;
|
||
|
}
|
||
|
|
||
5 years ago
|
bool set (int idx, int r, int g, int b) const NOEXCEPT_MAYBE
|
||
5 years ago
|
{
|
||
4 years ago
|
return error_guard (ncpalette_set_rgb8 (palette, idx, r, g, b), -1);
|
||
5 years ago
|
}
|
||
|
|
||
5 years ago
|
bool set (int idx, unsigned rgb) const NOEXCEPT_MAYBE
|
||
5 years ago
|
{
|
||
4 years ago
|
return error_guard (ncpalette_set (palette, idx, rgb), -1);
|
||
5 years ago
|
}
|
||
|
|
||
|
bool get (int idx, unsigned *r, unsigned *g, unsigned *b) const
|
||
|
{
|
||
|
if (r == nullptr)
|
||
5 years ago
|
throw invalid_argument ("'r' must be a valid pointer");
|
||
5 years ago
|
if (g == nullptr)
|
||
5 years ago
|
throw invalid_argument ("'g' must be a valid pointer");
|
||
5 years ago
|
if (b == nullptr)
|
||
5 years ago
|
throw invalid_argument ("'b' must be a valid pointer");
|
||
5 years ago
|
|
||
|
return get (idx, *r, *g, *b);
|
||
|
}
|
||
|
|
||
5 years ago
|
bool get (int idx, unsigned &r, unsigned &g, unsigned &b) const NOEXCEPT_MAYBE
|
||
5 years ago
|
{
|
||
4 years ago
|
return error_guard (ncpalette_get_rgb8 (palette, idx, &r, &g, &b), -1);
|
||
5 years ago
|
}
|
||
|
|
||
|
private:
|
||
4 years ago
|
ncpalette *palette;
|
||
5 years ago
|
};
|
||
|
}
|
||
|
#endif
|