2021-04-22 08:11:06 +00:00
|
|
|
#ifndef __NCPP_PALETTE_HH
|
|
|
|
#define __NCPP_PALETTE_HH
|
2020-01-07 22:51:34 +00:00
|
|
|
|
|
|
|
#include "Root.hh"
|
|
|
|
#include "_helpers.hh"
|
|
|
|
|
|
|
|
namespace ncpp
|
|
|
|
{
|
2020-05-24 12:41:18 +00:00
|
|
|
class NotCurses;
|
|
|
|
|
2021-04-22 08:11:06 +00:00
|
|
|
class NCPP_API_EXPORT Palette : public Root
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-04-22 08:11:06 +00:00
|
|
|
Palette (NotCurses *ncinst = nullptr)
|
2020-05-24 12:41:18 +00:00
|
|
|
: Root (ncinst)
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
2021-04-22 08:11:06 +00:00
|
|
|
palette = ncpalette_new (get_notcurses ());
|
2020-01-07 22:51:34 +00:00
|
|
|
if (palette == nullptr)
|
2020-05-20 04:15:38 +00:00
|
|
|
throw init_error ("Notcurses failed to create a new palette");
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
2021-04-22 08:11:06 +00:00
|
|
|
~Palette ()
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
2021-04-22 08:11:06 +00:00
|
|
|
ncpalette_free (palette);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
2021-04-22 08:11:06 +00:00
|
|
|
operator ncpalette* () noexcept
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
|
|
|
return palette;
|
|
|
|
}
|
|
|
|
|
2021-04-22 08:11:06 +00:00
|
|
|
operator ncpalette const* () const noexcept
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
|
|
|
return palette;
|
|
|
|
}
|
|
|
|
|
2020-04-12 21:09:03 +00:00
|
|
|
bool set (int idx, int r, int g, int b) const NOEXCEPT_MAYBE
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
2021-04-22 08:11:06 +00:00
|
|
|
return error_guard (ncpalette_set_rgb8 (palette, idx, r, g, b), -1);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
2020-04-12 21:09:03 +00:00
|
|
|
bool set (int idx, unsigned rgb) const NOEXCEPT_MAYBE
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
2021-04-22 08:11:06 +00:00
|
|
|
return error_guard (ncpalette_set (palette, idx, rgb), -1);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool get (int idx, unsigned *r, unsigned *g, unsigned *b) const
|
|
|
|
{
|
|
|
|
if (r == nullptr)
|
2020-02-16 19:25:26 +00:00
|
|
|
throw invalid_argument ("'r' must be a valid pointer");
|
2020-01-07 22:51:34 +00:00
|
|
|
if (g == nullptr)
|
2020-02-16 19:25:26 +00:00
|
|
|
throw invalid_argument ("'g' must be a valid pointer");
|
2020-01-07 22:51:34 +00:00
|
|
|
if (b == nullptr)
|
2020-02-16 19:25:26 +00:00
|
|
|
throw invalid_argument ("'b' must be a valid pointer");
|
2020-01-07 22:51:34 +00:00
|
|
|
|
|
|
|
return get (idx, *r, *g, *b);
|
|
|
|
}
|
|
|
|
|
2020-04-12 21:09:03 +00:00
|
|
|
bool get (int idx, unsigned &r, unsigned &g, unsigned &b) const NOEXCEPT_MAYBE
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
2021-04-22 08:11:06 +00:00
|
|
|
return error_guard (ncpalette_get_rgb8 (palette, idx, &r, &g, &b), -1);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2021-04-22 08:11:06 +00:00
|
|
|
ncpalette *palette;
|
2020-01-07 22:51:34 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|