mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-18 03:25:55 +00:00
[C++] API sync
Added: * Pile: new class derived from Plane, which implements all the `ncpile_*` calls * Plane: `get_parent` (`ncplane_parent`) * Plane: protected constructor for use by `Pile` (or other derived classes which cannot provide a valid `ncplane*` when invoking parent constructor. * Plane: `set_plane` for use by the derived classes above. Changed: * Plane: `to_ncplane` is a `const` method now.
This commit is contained in:
parent
2a45620cd6
commit
c063ce4e36
57
include/ncpp/Pile.hh
Normal file
57
include/ncpp/Pile.hh
Normal file
@ -0,0 +1,57 @@
|
||||
#ifndef __NCPP_PILE_HH
|
||||
#define __NCPP_PILE_HH
|
||||
|
||||
#include <exception>
|
||||
#include <notcurses/notcurses.h>
|
||||
|
||||
#include "NotCurses.hh"
|
||||
#include "Plane.hh"
|
||||
|
||||
namespace ncpp
|
||||
{
|
||||
class NCPP_API_EXPORT Pile : public Plane
|
||||
{
|
||||
public:
|
||||
Pile (ncplane_options const* nopts, NotCurses* ncinst = nullptr)
|
||||
: Plane (ncinst)
|
||||
{
|
||||
if (nopts == nullptr) {
|
||||
throw invalid_argument ("'nopts' must be a valid pointer");
|
||||
}
|
||||
|
||||
notcurses *n;
|
||||
if (ncinst == nullptr) {
|
||||
n = NotCurses::get_instance ();
|
||||
} else {
|
||||
n = *ncinst;
|
||||
}
|
||||
|
||||
ncplane *pile = ncpile_create (n, nopts);
|
||||
if (pile == nullptr) {
|
||||
throw init_error ("Notcurses failed to create a new pile");
|
||||
}
|
||||
|
||||
set_plane (pile);
|
||||
}
|
||||
|
||||
bool render () const NOEXCEPT_MAYBE
|
||||
{
|
||||
return error_guard (ncpile_render (to_ncplane ()), -1);
|
||||
}
|
||||
|
||||
bool rasterize () const NOEXCEPT_MAYBE
|
||||
{
|
||||
return error_guard (ncpile_rasterize (to_ncplane ()), -1);
|
||||
}
|
||||
|
||||
bool show () const NOEXCEPT_MAYBE
|
||||
{
|
||||
if (!render ()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return rasterize ();
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif
|
@ -150,7 +150,7 @@ namespace ncpp
|
||||
ncplane_center_abs (plane, y, x);
|
||||
}
|
||||
|
||||
ncplane* to_ncplane () noexcept
|
||||
ncplane* to_ncplane () const noexcept
|
||||
{
|
||||
return plane;
|
||||
}
|
||||
@ -302,6 +302,16 @@ namespace ncpp
|
||||
get_yx (&y, &x);
|
||||
}
|
||||
|
||||
Plane* get_parent () const noexcept
|
||||
{
|
||||
ncplane *ret = ncplane_parent (plane);
|
||||
if (ret == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return map_plane (ret);
|
||||
}
|
||||
|
||||
Plane* reparent (Plane *newparent = nullptr) const noexcept
|
||||
{
|
||||
ncplane *ret = ncplane_reparent (plane, newparent == nullptr ? nullptr : newparent->plane);
|
||||
@ -1180,6 +1190,29 @@ namespace ncpp
|
||||
throw invalid_argument ("_plane must be a valid pointer");
|
||||
}
|
||||
|
||||
// This is used by child classes which cannot provide a valid ncplane* in their constructor when initializing
|
||||
// the parent class (e.g. Pile)
|
||||
Plane (NotCurses *ncinst = nullptr)
|
||||
: Root (ncinst),
|
||||
plane (nullptr)
|
||||
{}
|
||||
|
||||
// Can be used only once and only if plane == nullptr. Meant to be used by child classes which cannot provide a
|
||||
// valid ncplane* in their constructor when initializing the parent class (e.g. Pile)
|
||||
void set_plane (ncplane *_plane)
|
||||
{
|
||||
if (_plane == nullptr) {
|
||||
throw invalid_argument ("_plane must be a valid pointer");
|
||||
}
|
||||
|
||||
if (plane != nullptr) {
|
||||
throw invalid_state_error ("Plane::set_plane can be called only once");
|
||||
}
|
||||
|
||||
plane = _plane;
|
||||
map_plane (plane, this);
|
||||
}
|
||||
|
||||
void release_native_plane () noexcept
|
||||
{
|
||||
if (plane == nullptr)
|
||||
@ -1221,7 +1254,7 @@ namespace ncpp
|
||||
{
|
||||
ncplane_options nopts = {
|
||||
yoff,
|
||||
{ static_cast<ncalign_e>(align) },
|
||||
static_cast<ncalign_e>(align),
|
||||
rows,
|
||||
cols,
|
||||
opaque,
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <iostream>
|
||||
#include <ncpp/NotCurses.hh>
|
||||
#include <ncpp/Menu.hh>
|
||||
#include <ncpp/Pile.hh>
|
||||
#include <ncpp/Plane.hh>
|
||||
#include <ncpp/Reel.hh>
|
||||
#include <ncpp/MultiSelector.hh>
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <iostream>
|
||||
#include <ncpp/NotCurses.hh>
|
||||
#include <ncpp/Menu.hh>
|
||||
#include <ncpp/Pile.hh>
|
||||
#include <ncpp/Plane.hh>
|
||||
#include <ncpp/Reel.hh>
|
||||
#include <ncpp/MultiSelector.hh>
|
||||
|
Loading…
Reference in New Issue
Block a user