mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-06 03:20:26 +00:00
e429724287
Added: * Plane: gradient (`ncplane_gradient`) * Plane: gradient_sized (`ncplane_gradient_sized`) * NotCurses: drop_planes (`ncplane_drop_planes`) * NcReel: constructor which takes `Plane&` * Visual: constructors which take `Plane const*`, `Plane&` and `Plane const&`) * ncpp_build: a nonsensical "demo" which exists purely to test whether the C++ builds and does absolutely nothing interesting. Broke: * All exceptions throw temporary objects instead of allocated instances. Less typing in `catch` :P (and more conventional)
66 lines
1.3 KiB
C++
66 lines
1.3 KiB
C++
#ifndef __NCPP_PALETTE256_HH
|
|
#define __NCPP_PALETTE256_HH
|
|
|
|
#include "Root.hh"
|
|
#include "_helpers.hh"
|
|
|
|
namespace ncpp
|
|
{
|
|
class NCPP_API_EXPORT Palette256 : public Root
|
|
{
|
|
public:
|
|
Palette256 ()
|
|
{
|
|
palette = palette256_new (get_notcurses ());
|
|
if (palette == nullptr)
|
|
throw init_error ("notcurses failed to create a new palette");
|
|
}
|
|
|
|
~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
|
|
{
|
|
return palette256_set_rgb (palette, idx, r, g, b) != -1;
|
|
}
|
|
|
|
bool set (int idx, unsigned rgb) const noexcept
|
|
{
|
|
return palette256_set (palette, idx, rgb) != -1;
|
|
}
|
|
|
|
bool get (int idx, unsigned *r, unsigned *g, unsigned *b) const
|
|
{
|
|
if (r == nullptr)
|
|
throw invalid_argument ("'r' must be a valid pointer");
|
|
if (g == nullptr)
|
|
throw invalid_argument ("'g' must be a valid pointer");
|
|
if (b == nullptr)
|
|
throw invalid_argument ("'b' must be a valid pointer");
|
|
|
|
return get (idx, *r, *g, *b);
|
|
}
|
|
|
|
bool get (int idx, unsigned &r, unsigned &g, unsigned &b) const noexcept
|
|
{
|
|
return palette256_get_rgb (palette, idx, &r, &g, &b) != -1;
|
|
}
|
|
|
|
private:
|
|
palette256 *palette;
|
|
};
|
|
}
|
|
#endif
|