diff --git a/include/ncpp/Direct.hh b/include/ncpp/Direct.hh index 09acba90d..bbb28d980 100644 --- a/include/ncpp/Direct.hh +++ b/include/ncpp/Direct.hh @@ -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; diff --git a/include/ncpp/Plane.hh b/include/ncpp/Plane.hh index 42bdb4ad1..bcccef337 100644 --- a/include/ncpp/Plane.hh +++ b/include/ncpp/Plane.hh @@ -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(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(newparent)); + } + + Plane* reparent (const Plane &newparent) const noexcept + { + return reparent (const_cast(&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(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 ( diff --git a/include/ncpp/Plot.hh b/include/ncpp/Plot.hh index 0d1ce8635..480c0c8cd 100644 --- a/include/ncpp/Plot.hh +++ b/include/ncpp/Plot.hh @@ -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(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), opts) {} - explicit Plot (Plane &plane, const plot_options *opts = nullptr) + explicit Plot (Plane &plane, const ncplot_options *opts = nullptr) : Plot (reinterpret_cast(&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), 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; diff --git a/src/libcpp/Plot.cc b/src/libcpp/Plot.cc new file mode 100644 index 000000000..8a5cfe32e --- /dev/null +++ b/src/libcpp/Plot.cc @@ -0,0 +1,21 @@ +#include +#include + +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)); +} diff --git a/src/poc/ncpp_build.cpp b/src/poc/ncpp_build.cpp index 915fbfb07..dee4c346b 100644 --- a/src/poc/ncpp_build.cpp +++ b/src/poc/ncpp_build.cpp @@ -15,6 +15,7 @@ #include #include #include +#include using namespace ncpp;