mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-02 09:40:15 +00:00
2fabe85e6a
Been a while, apologies :) Added: * Direct: fg_palindex (`ncdirect_fg_palindex`) * Direct: bg_palindex (`ncdirect_bg_palindex`) * Direct: get_palette_size (`ncdirect_palette_size`) * Direct: putstr (`ncdirect_putstr`) * Direct: hline_interp (`ncdirect_hline_interp`) * Direct: vline_interp (`ncdirect_vline_interp`) * Direct: box (`ncdirect_box`) * Direct: rounded_box (`ncdirect_rounded_box`) * Direct: double_box (`ncdirect_double_box`) * Direct: canopen_images (`ncdirect_canopen_images`) * Direct: canutf8 (`ncdirect_canutf8`) * Menu: get_mouse_selected (`ncmenu_mouse_selected`) * NotCurses: version_components (`notcurses_version_components`) * NotCurses: str_blitter (`notcurses_str_blitter`) * NotCurses: str_scalemode (`notcurses_str_scalemode`) * NotCurses: lex_margins (`notcurses_lex_margins`) * NotCurses: lex_blitter (`notcurses_lex_blitter`) * NotCurses: lex_scalemode (`notcurses_lex_scalemode`) * NotCurses: render_to_file (`notcurses_render_to_file`) * Plane: putstr_stainable (`ncplane_putstr_stainable`) * Plane: printf_stainable (`ncplane_printf_stainable`) * Plane: vprintf_stainable (`ncplane_vprintf_stainable`) * Reel: offer_input (`ncreel_offer_input`) Changed: * Direct: set_fg_alpha uses `unsigned alpha` * Direct: set_bg_alpha uses `unsigned alpha` * Plane: set_fg_alpha uses `unsigned alpha` * Plane: set_bg_alpha uses `unsigned alpha` * Root: made `error_guard` and `error_guard_cond` static
149 lines
3.3 KiB
C++
149 lines
3.3 KiB
C++
#ifndef __NCPP_REEL_HH
|
|
#define __NCPP_REEL_HH
|
|
|
|
#include <memory>
|
|
#include <notcurses/notcurses.h>
|
|
|
|
#include "Tablet.hh"
|
|
#include "Plane.hh"
|
|
#include "Utilities.hh"
|
|
|
|
namespace ncpp
|
|
{
|
|
class NCPP_API_EXPORT NcReel : public Root
|
|
{
|
|
public:
|
|
static ncreel_options default_options;
|
|
|
|
explicit NcReel (Plane &plane, const ncreel_options *popts = nullptr)
|
|
: NcReel (static_cast<Plane const&>(plane), popts)
|
|
{}
|
|
|
|
explicit NcReel (Plane const&plane, const ncreel_options *popts = nullptr)
|
|
: Root (Utilities::get_notcurses_cpp (plane))
|
|
{
|
|
common_init (Utilities::to_ncplane (plane), popts);
|
|
}
|
|
|
|
explicit NcReel (Plane *plane, const ncreel_options *popts = nullptr)
|
|
: NcReel (static_cast<const Plane*>(plane), popts)
|
|
{}
|
|
|
|
explicit NcReel (const Plane *plane, const ncreel_options *popts = nullptr)
|
|
: Root (Utilities::get_notcurses_cpp (plane))
|
|
{
|
|
if (plane == nullptr)
|
|
throw invalid_argument ("'plane' must be a valid pointer");
|
|
|
|
common_init (Utilities::to_ncplane (plane), popts);
|
|
}
|
|
|
|
~NcReel ()
|
|
{
|
|
if (!is_notcurses_stopped ())
|
|
ncreel_destroy (reel);
|
|
}
|
|
|
|
operator ncreel* () const noexcept
|
|
{
|
|
return reel;
|
|
}
|
|
|
|
operator ncreel const* () const noexcept
|
|
{
|
|
return reel;
|
|
}
|
|
|
|
// TODO: add an overload using callback that takes NcTablet instance instead of struct tablet
|
|
NcTablet* add (NcTablet *after, NcTablet *before, tabletcb cb, void *opaque = nullptr) const
|
|
{
|
|
nctablet *t = ncreel_add (reel, get_tablet (after), get_tablet (before), cb, opaque);
|
|
if (t == nullptr)
|
|
throw init_error ("Notcurses failed to create a new tablet");
|
|
|
|
return NcTablet::map_tablet (t, get_notcurses_cpp ());
|
|
}
|
|
|
|
NcTablet* add (NcTablet &after, NcTablet &before, tabletcb cb, void *opaque = nullptr) const noexcept
|
|
{
|
|
return add (&after, &before, cb, opaque);
|
|
}
|
|
|
|
int get_tabletcount () const noexcept
|
|
{
|
|
return ncreel_tabletcount (reel);
|
|
}
|
|
|
|
bool del (NcTablet *t) const NOEXCEPT_MAYBE
|
|
{
|
|
return error_guard (ncreel_del (reel, get_tablet (t)), -1);
|
|
}
|
|
|
|
bool del (NcTablet &t) const NOEXCEPT_MAYBE
|
|
{
|
|
return del (&t);
|
|
}
|
|
|
|
bool redraw () const NOEXCEPT_MAYBE
|
|
{
|
|
return error_guard (ncreel_redraw (reel), -1);
|
|
}
|
|
|
|
NcTablet* get_focused () const noexcept
|
|
{
|
|
nctablet *t = ncreel_focused (reel);
|
|
if (t == nullptr)
|
|
return nullptr;
|
|
|
|
return NcTablet::map_tablet (t, get_notcurses_cpp ());
|
|
}
|
|
|
|
NcTablet* next () const noexcept
|
|
{
|
|
nctablet *t = ncreel_next (reel);
|
|
if (t == nullptr)
|
|
return nullptr;
|
|
|
|
return NcTablet::map_tablet (t, get_notcurses_cpp ());
|
|
}
|
|
|
|
NcTablet* prev () const noexcept
|
|
{
|
|
nctablet *t = ncreel_prev (reel);
|
|
if (t == nullptr)
|
|
return nullptr;
|
|
|
|
return NcTablet::map_tablet (t, get_notcurses_cpp ());
|
|
}
|
|
|
|
bool offer_input (const struct ncinput* nci) const NOEXCEPT_MAYBE
|
|
{
|
|
return error_guard<bool, bool> (ncreel_offer_input (reel, nci), false);
|
|
}
|
|
|
|
Plane* get_plane () const noexcept;
|
|
|
|
private:
|
|
nctablet* get_tablet (NcTablet *t) const noexcept
|
|
{
|
|
if (t == nullptr)
|
|
return nullptr;
|
|
|
|
return t->get_tablet ();
|
|
}
|
|
|
|
void common_init (ncplane *plane, const ncreel_options *popts = nullptr)
|
|
{
|
|
reel = ncreel_create (plane, popts == nullptr ? &default_options : popts);
|
|
if (reel == nullptr)
|
|
throw init_error ("Notcurses failed to create a new ncreel");
|
|
}
|
|
|
|
private:
|
|
ncreel *reel = nullptr;
|
|
|
|
friend class Plane;
|
|
};
|
|
}
|
|
#endif
|