[C++] Sync API changes

Been a while, but here goes, sync to the latest API changes.

Added:

  * Direct:   cursor_{up,left,right,down} (`ncdirect_cursor_{up,left,right,down}`)
  * Plane: constructors to use `ncplane_bound`
  * Plane: reparent (`ncplane_reparent`)
  * Plot: definition of `default_options`

Changed:

  * Plane (breaking): the `*gradient*` functions now return `int`
  * Plane (breaking): `polyfill` returns `int`
  * Plane (breaking): `stain` returns `int`
  * Plane (breaking): `blit_bgrx` takes `const void*` for `data`
  * Plane (breaking): `blit_rgba` takes `const void*` for `data`
  * Plot: `plot_optons` -> `ncplot_options`
  * Plot (breaking): `{add,set}_sample` now return `bool`
pull/471/head
Marek Habersack 4 years ago committed by Nick Black
parent 55195b8ed0
commit 28976dfef2

@ -89,6 +89,26 @@ namespace ncpp
return ncdirect_cursor_move_yx (direct, y, x);
}
int cursor_up (int num) const noexcept
{
return ncdirect_cursor_up (direct, num);
}
int cursor_left (int num) const noexcept
{
return ncdirect_cursor_left (direct, num);
}
int cursor_right (int num) const noexcept
{
return ncdirect_cursor_right (direct, num);
}
int cursor_down (int num) const noexcept
{
return ncdirect_cursor_down (direct, num);
}
bool cursor_enable () const noexcept
{
return ncdirect_cursor_enable (direct) != -1;

@ -31,6 +31,23 @@ namespace ncpp
plane = duplicate_plane (other, opaque);
}
explicit Plane (Plane *n, int rows, int cols, int yoff, int xoff, void *opaque = nullptr)
: Plane (static_cast<const Plane*>(n), rows, cols, yoff, xoff, opaque)
{}
explicit Plane (const Plane *n, int rows, int cols, int yoff, int xoff, void *opaque = nullptr)
{
if (n == nullptr)
throw invalid_argument ("'n' must be a valid pointer");
plane = create_plane (*n, rows, cols, yoff, xoff, opaque);
}
explicit Plane (const Plane &n, int rows, int cols, int yoff, int xoff, void *opaque = nullptr)
{
plane = create_plane (n, rows, cols, yoff, xoff, opaque);
}
explicit Plane (int rows, int cols, int yoff, int xoff, void *opaque = nullptr)
{
plane = ncplane_new (
@ -126,24 +143,24 @@ namespace ncpp
return mergedown(&dst);
}
bool gradient (const char* egc, uint32_t attrword, uint64_t ul, uint64_t ur, uint64_t ll, uint64_t lr, int ystop, int xstop) const noexcept
int gradient (const char* egc, uint32_t attrword, uint64_t ul, uint64_t ur, uint64_t ll, uint64_t lr, int ystop, int xstop) const noexcept
{
return ncplane_gradient (plane, egc, attrword, ul, ur, ll, lr, ystop, xstop) != -1;
return ncplane_gradient (plane, egc, attrword, ul, ur, ll, lr, ystop, xstop);
}
bool gradient_sized (const char* egc, uint32_t attrword, uint64_t ul, uint64_t ur, uint64_t ll, uint64_t lr, int ylen, int xlen) const noexcept
int gradient_sized (const char* egc, uint32_t attrword, uint64_t ul, uint64_t ur, uint64_t ll, uint64_t lr, int ylen, int xlen) const noexcept
{
return ncplane_gradient_sized (plane, egc, attrword, ul, ur, ll, lr, ylen, xlen) != -1;
return ncplane_gradient_sized (plane, egc, attrword, ul, ur, ll, lr, ylen, xlen);
}
bool high_gradient (uint64_t ul, uint64_t ur, uint64_t ll, uint64_t lr, int ylen, int xlen) const noexcept
int high_gradient (uint64_t ul, uint64_t ur, uint64_t ll, uint64_t lr, int ylen, int xlen) const noexcept
{
return ncplane_highgradient (plane, ul, ur, ll, lr, ylen, xlen) != -1;
return ncplane_highgradient (plane, ul, ur, ll, lr, ylen, xlen);
}
bool high_gradient_sized (uint64_t ul, uint64_t ur, uint64_t ll, uint64_t lr, int ylen, int xlen) const noexcept
int high_gradient_sized (uint64_t ul, uint64_t ur, uint64_t ll, uint64_t lr, int ylen, int xlen) const noexcept
{
return ncplane_highgradient_sized (plane, ul, ur, ll, lr, ylen, xlen) != -1;
return ncplane_highgradient_sized (plane, ul, ur, ll, lr, ylen, xlen);
}
void greyscale () const noexcept
@ -236,6 +253,25 @@ namespace ncpp
get_yx (&y, &x);
}
Plane* reparent (Plane *newparent = nullptr) const noexcept
{
ncplane *ret = ncplane_reparent (plane, newparent == nullptr ? nullptr : newparent->plane);
if (ret == nullptr)
return nullptr;
return map_plane (ret);
}
Plane* reparent (const Plane *newparent) const noexcept
{
return reparent (const_cast<Plane*>(newparent));
}
Plane* reparent (const Plane &newparent) const noexcept
{
return reparent (const_cast<Plane*>(&newparent));
}
bool move (int y, int x) const noexcept
{
return ncplane_move_yx (plane, y, x) != -1;
@ -577,9 +613,9 @@ namespace ncpp
return ncplane_perimeter (plane, ul, ur, ll, lr, hline, vline, ctlword) != -1;
}
bool polyfill (int y, int x, const Cell& c) const noexcept
int polyfill (int y, int x, const Cell& c) const noexcept
{
return ncplane_polyfill_yx (plane, y, x, c) != -1;
return ncplane_polyfill_yx (plane, y, x, c);
}
uint64_t get_channels () const noexcept
@ -712,14 +748,14 @@ namespace ncpp
ncplane_styles_off (plane, static_cast<unsigned>(styles));
}
bool format (int ystop, int xstop, uint32_t attrword) const noexcept
int format (int ystop, int xstop, uint32_t attrword) const noexcept
{
return ncplane_format (plane, ystop, xstop, attrword) != -1;
return ncplane_format (plane, ystop, xstop, attrword);
}
bool stain (int ystop, int xstop, uint64_t ul, uint64_t ur, uint64_t ll, uint64_t lr)
int stain (int ystop, int xstop, uint64_t ul, uint64_t ur, uint64_t ll, uint64_t lr)
{
return ncplane_stain (plane, ystop, xstop, ul, ur, ll, lr) != -1;
return ncplane_stain (plane, ystop, xstop, ul, ur, ll, lr);
}
Plane* get_below () const noexcept
@ -942,12 +978,12 @@ namespace ncpp
static Plane* map_plane (ncplane *ncp, Plane *associated_plane = nullptr) noexcept;
#ifdef USE_FFMPEG
bool blit_bgrx (int placey, int placex, int linesize, const unsigned char* data, int begy, int begx, int leny, int lenx) const noexcept
bool blit_bgrx (int placey, int placex, int linesize, const void* data, int begy, int begx, int leny, int lenx) const noexcept
{
return ncblit_bgrx (plane, placey, placex, linesize, data, begy, begx, leny, lenx) >= 0;
}
bool blit_rgba (int placey, int placex, int linesize, const unsigned char* data, int begy, int begx, int leny, int lenx) const noexcept
bool blit_rgba (int placey, int placex, int linesize, const void* data, int begy, int begx, int leny, int lenx) const noexcept
{
return ncblit_rgba (plane, placey, placex, linesize, data, begy, begx, leny, lenx) >= 0;
}
@ -965,6 +1001,25 @@ namespace ncpp
static void unmap_plane (Plane *p) noexcept;
private:
ncplane* create_plane (const Plane &n, int rows, int cols, int yoff, int xoff, void *opaque)
{
ncplane *ret = ncplane_bound (
n.plane,
rows,
cols,
yoff,
xoff,
opaque
);
if (ret == nullptr)
throw init_error ("notcurses failed to create a new plane");
map_plane (plane, this);
return ret;
}
ncplane* create_plane (Plane &n, int rows, int cols, int yoff, NCAlign align, void *opaque)
{
ncplane *ret = ncplane_aligned (

@ -13,26 +13,26 @@ namespace ncpp
class NCPP_API_EXPORT Plot : public Root
{
public:
static plot_options default_options;
static ncplot_options default_options;
public:
explicit Plot (Plane *plane, const plot_options *opts = nullptr)
explicit Plot (Plane *plane, const ncplot_options *opts = nullptr)
: Plot (reinterpret_cast<ncplane*>(plane), opts)
{}
explicit Plot (Plane const* plane, const plot_options *opts = nullptr)
explicit Plot (Plane const* plane, const ncplot_options *opts = nullptr)
: Plot (const_cast<Plane*>(plane), opts)
{}
explicit Plot (Plane &plane, const plot_options *opts = nullptr)
explicit Plot (Plane &plane, const ncplot_options *opts = nullptr)
: Plot (reinterpret_cast<ncplane*>(&plane), opts)
{}
explicit Plot (Plane const& plane, const plot_options *opts = nullptr)
explicit Plot (Plane const& plane, const ncplot_options *opts = nullptr)
: Plot (const_cast<Plane*>(&plane), opts)
{}
explicit Plot (ncplane *plane, const plot_options *opts = nullptr)
explicit Plot (ncplane *plane, const ncplot_options *opts = nullptr)
{
if (plane == nullptr)
throw invalid_argument ("'plane' must be a valid pointer");
@ -48,15 +48,15 @@ namespace ncpp
ncplot_destroy (plot);
}
int add_sample(uint64_t x, uint64_t y)
{
bool add_sample(uint64_t x, uint64_t y)
{
return ncplot_add_sample (plot, x, y) >= 0;
}
}
int set_sample(uint64_t x, uint64_t y)
{
bool set_sample(uint64_t x, uint64_t y)
{
return ncplot_set_sample (plot, x, y) >= 0;
}
}
Plane* get_plane () const noexcept;

@ -0,0 +1,21 @@
#include <ncpp/Plot.hh>
#include <ncpp/Plane.hh>
using namespace ncpp;
ncplot_options Plot::default_options = {
0, // maxchannel
0, // minchannel
ncgridgeom_e::NCPLOT_1x1, // ncgridgeom_e
0, // rangex
0, // miny
0, // maxy
false, // labelaxisd,
false, // exponentialy
false, // verticalindep
};
Plane* Plot::get_plane () const noexcept
{
return Plane::map_plane (ncplot_plane (plot));
}

@ -15,6 +15,7 @@
#include <ncpp/Selector.hh>
#include <ncpp/Visual.hh>
#include <ncpp/Direct.hh>
#include <ncpp/Plot.hh>
using namespace ncpp;

Loading…
Cancel
Save