diff --git a/CMakeLists.txt b/CMakeLists.txt index f4009d281..bb2c42e91 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -162,6 +162,7 @@ target_compile_definitions(notcurses-static # libnotcurses++ set(NCPP_SOURCES src/libcpp/Menu.cc + src/libcpp/MultiSelector.cc src/libcpp/NotCurses.cc src/libcpp/Plane.cc src/libcpp/Reel.cc diff --git a/include/ncpp/Direct.hh b/include/ncpp/Direct.hh index d4b392ced..09acba90d 100644 --- a/include/ncpp/Direct.hh +++ b/include/ncpp/Direct.hh @@ -84,10 +84,20 @@ namespace ncpp ncdirect_styles_off (direct, static_cast(stylebits)); } - int cursor_move_yx (int y, int x) const noexcept - { - return ncdirect_cursor_move_yx (direct, y, x); - } + int cursor_move_yx (int y, int x) const noexcept + { + return ncdirect_cursor_move_yx (direct, y, x); + } + + bool cursor_enable () const noexcept + { + return ncdirect_cursor_enable (direct) != -1; + } + + bool cursor_disable () const noexcept + { + return ncdirect_cursor_disable (direct) != -1; + } private: ncdirect *direct; diff --git a/include/ncpp/MultiSelector.hh b/include/ncpp/MultiSelector.hh new file mode 100644 index 000000000..9912ada28 --- /dev/null +++ b/include/ncpp/MultiSelector.hh @@ -0,0 +1,67 @@ +#ifndef __NCPP_MULTI_SELECTOR_HH +#define __NCPP_MULTI_SELECTOR_HH + +#include + +#include "Root.hh" +#include "NCAlign.hh" + +namespace ncpp +{ + class Plane; + + class NCPP_API_EXPORT MultiSelector : public Root + { + public: + static multiselector_options default_options; + + public: + explicit MultiSelector (Plane *plane, int y, int x, const multiselector_options *opts = nullptr) + : MultiSelector (reinterpret_cast(plane), y, x, opts) + {} + + explicit MultiSelector (Plane const* plane, int y, int x, const multiselector_options *opts = nullptr) + : MultiSelector (const_cast(plane), y, x, opts) + {} + + explicit MultiSelector (Plane &plane, int y, int x, const multiselector_options *opts = nullptr) + : MultiSelector (reinterpret_cast(&plane), y, x, opts) + {} + + explicit MultiSelector (Plane const& plane, int y, int x, const multiselector_options *opts = nullptr) + : MultiSelector (const_cast(&plane), y, x, opts) + {} + + explicit MultiSelector (ncplane *plane, int y, int x, const multiselector_options *opts = nullptr) + { + if (plane == nullptr) + throw invalid_argument ("'plane' must be a valid pointer"); + + multiselector = ncmultiselector_create (plane, y, x, opts == nullptr ? &default_options : opts); + if (multiselector == nullptr) + throw init_error ("notcurses failed to create a new multiselector"); + } + + ~MultiSelector () + { + if (!is_notcurses_stopped ()) + ncmultiselector_destroy (multiselector, nullptr); + } + + bool offer_input (const struct ncinput *nc) const noexcept + { + return ncmultiselector_offer_input (multiselector, nc); + } + + const int get_selected (bool *selected, unsigned count) const noexcept + { + return ncmultiselector_selected (multiselector, selected, count); + } + + Plane* get_plane () const noexcept; + + private: + ncmultiselector *multiselector; + }; +} +#endif diff --git a/include/ncpp/Plane.hh b/include/ncpp/Plane.hh index ba06b733f..792e9baa2 100644 --- a/include/ncpp/Plane.hh +++ b/include/ncpp/Plane.hh @@ -128,6 +128,16 @@ namespace ncpp return ncplane_gradient_sized (plane, egc, attrword, ul, ur, ll, lr, ylen, xstop) != -1; } + bool 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; + } + + bool 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; + } + void greyscale () const noexcept { ncplane_greyscale (plane); @@ -876,11 +886,21 @@ namespace ncpp ncplane_translate (src.plane, dst.plane, y, x); } - bool translate_abs (int *y = nullptr, int *x = nullptr) + bool translate_abs (int *y = nullptr, int *x = nullptr) noexcept { return ncplane_translate_abs (*this, y, x); } + bool rotate_cw () const noexcept + { + return ncplane_rotate_cw (plane) != -1; + } + + bool rotate_ccw () const noexcept + { + return ncplane_rotate_ccw (plane) != -1; + } + // Upstream call doesn't take ncplane* but we put it here for parity with has_no_background below bool has_no_foreground (Cell &cell) const noexcept { diff --git a/src/libcpp/MultiSelector.cc b/src/libcpp/MultiSelector.cc new file mode 100644 index 000000000..815477d0d --- /dev/null +++ b/src/libcpp/MultiSelector.cc @@ -0,0 +1,24 @@ +#include +#include + +using namespace ncpp; + +multiselector_options MultiSelector::default_options = { + /* title */ nullptr, + /* secondary */ nullptr, + /* footer */ nullptr, + /* items */ nullptr, + /* itemcount */ 0, + /* maxdisplay */ 0, + /* opchannels */ 0, + /* descchannels */ 0, + /* titlechannels */ 0, + /* footchannels */ 0, + /* boxchannels */ 0, + /* bgchannels */ 0, +}; + +Plane* MultiSelector::get_plane () const noexcept +{ + return Plane::map_plane (ncmultiselector_plane (multiselector)); +} diff --git a/src/libcpp/NotCurses.cc b/src/libcpp/NotCurses.cc index d0d381351..95b1757fe 100644 --- a/src/libcpp/NotCurses.cc +++ b/src/libcpp/NotCurses.cc @@ -12,6 +12,10 @@ notcurses_options NotCurses::default_notcurses_options = { /* no_winch_sighandler */ false, /* renderfp */ nullptr, /* loglevel */ NCLogLevel::Silent, + /* margin_t */ 0, + /* margin_r */ 0, + /* margin_b */ 0, + /* margin_l */ 0, }; NotCurses *NotCurses::_instance = nullptr; diff --git a/src/poc/ncpp_build.cpp b/src/poc/ncpp_build.cpp index 6f258913b..915fbfb07 100644 --- a/src/poc/ncpp_build.cpp +++ b/src/poc/ncpp_build.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include