notcurses/include/ncpp/Palette256.hh

69 lines
1.4 KiB
C++
Raw Normal View History

2020-01-07 22:51:34 +00:00
#ifndef __NCPP_PALETTE256_HH
#define __NCPP_PALETTE256_HH
#include "Root.hh"
#include "_helpers.hh"
namespace ncpp
{
class NotCurses;
2020-01-07 22:51:34 +00:00
class NCPP_API_EXPORT Palette256 : public Root
{
public:
Palette256 (NotCurses *ncinst = nullptr)
: Root (ncinst)
2020-01-07 22:51:34 +00:00
{
palette = palette256_new (get_notcurses ());
if (palette == nullptr)
throw init_error ("Notcurses failed to create a new palette");
2020-01-07 22:51:34 +00:00
}
~Palette256 ()
{
palette256_free (palette);
}
operator palette256* () noexcept
{
return palette;
}
operator palette256 const* () const noexcept
{
return palette;
}
bool set (int idx, int r, int g, int b) const NOEXCEPT_MAYBE
2020-01-07 22:51:34 +00:00
{
2020-09-17 19:34:28 +00:00
return error_guard (palette256_set_rgb8 (palette, idx, r, g, b), -1);
2020-01-07 22:51:34 +00:00
}
bool set (int idx, unsigned rgb) const NOEXCEPT_MAYBE
2020-01-07 22:51:34 +00:00
{
return error_guard (palette256_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)
throw invalid_argument ("'r' must be a valid pointer");
2020-01-07 22:51:34 +00:00
if (g == nullptr)
throw invalid_argument ("'g' must be a valid pointer");
2020-01-07 22:51:34 +00:00
if (b == nullptr)
throw invalid_argument ("'b' must be a valid pointer");
2020-01-07 22:51:34 +00:00
return get (idx, *r, *g, *b);
}
bool get (int idx, unsigned &r, unsigned &g, unsigned &b) const NOEXCEPT_MAYBE
2020-01-07 22:51:34 +00:00
{
2020-09-17 19:34:28 +00:00
return error_guard (palette256_get_rgb8 (palette, idx, &r, &g, &b), -1);
2020-01-07 22:51:34 +00:00
}
private:
palette256 *palette;
};
}
#endif