From 945c3a5f4feec318baac2c00e083139fe97804aa Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Sat, 22 Feb 2020 20:01:52 +0100 Subject: [PATCH] [C++] API sync Added: * Cell: get_addrword (`cell.attrword`) * Cell: get_channels (`cell.channels`) * NotCurses: get_stdplane overloads (`notcurses_stddim_yx`) * Plane: putc (support for `ncplane_putsimple_stainable`, `ncplane_putegc_stainable`, `ncplane_putwegc_stainable`) * Plane: format (`ncplane_format`) * Plane: stain (`ncplane_stain`) * Plane: translate (`ncplane_translate`) --- include/ncpp/Cell.hh | 10 ++++++++ include/ncpp/NotCurses.hh | 15 ++++++++++++ include/ncpp/Plane.hh | 50 ++++++++++++++++++++++++++++++++++++--- 3 files changed, 72 insertions(+), 3 deletions(-) diff --git a/include/ncpp/Cell.hh b/include/ncpp/Cell.hh index 1c398b7cb..695a290c7 100644 --- a/include/ncpp/Cell.hh +++ b/include/ncpp/Cell.hh @@ -61,6 +61,16 @@ namespace ncpp cell_init (&_cell); } + uint32_t get_attrword () const noexcept + { + return _cell.attrword; + } + + uint64_t get_channels () const noexcept + { + return _cell.channels; + } + uint64_t set_fchannel (uint32_t channel) noexcept { return cell_set_fchannel (&_cell, channel); diff --git a/include/ncpp/NotCurses.hh b/include/ncpp/NotCurses.hh index a51042ba8..7ab1b21f5 100644 --- a/include/ncpp/NotCurses.hh +++ b/include/ncpp/NotCurses.hh @@ -218,6 +218,21 @@ namespace ncpp return new Plane (notcurses_stdplane (nc), true); } + Plane* get_stdplane (int *y, int *x) + { + if (y == nullptr) + throw invalid_argument ("'y' must be a valid pointer"); + if (x == nullptr) + throw invalid_argument ("'x' must be a valid pointer"); + + return get_stdplane (*y, *x); + } + + Plane* get_stdplane (int &y, int &x) noexcept + { + return new Plane (notcurses_stddim_yx (nc, &y, &x)); + } + Plane* get_top () noexcept; private: diff --git a/include/ncpp/Plane.hh b/include/ncpp/Plane.hh index c4245ff8b..15143e5d9 100644 --- a/include/ncpp/Plane.hh +++ b/include/ncpp/Plane.hh @@ -326,8 +326,10 @@ namespace ncpp return putc (y, x, *c); } - int putc (char c) const noexcept + int putc (char c, bool retain_styling = false) const noexcept { + if (retain_styling) + return ncplane_putsimple_stainable (plane, c); return ncplane_putsimple (plane, c); } @@ -336,8 +338,10 @@ namespace ncpp return ncplane_putsimple_yx (plane, y, x, c); } - int putc (const char *gclust, int *sbytes = nullptr) const noexcept + int putc (const char *gclust, int *sbytes = nullptr, bool retain_styling = false) const noexcept { + if (retain_styling) + return ncplane_putegc_stainable (plane, gclust, sbytes); return ncplane_putegc (plane, gclust, sbytes); } @@ -346,8 +350,10 @@ namespace ncpp return ncplane_putegc_yx (plane, y, x, gclust, sbytes); } - int putc (const wchar_t *gclust, int *sbytes = nullptr) const noexcept + int putc (const wchar_t *gclust, int *sbytes = nullptr, bool retain_styling = false) const noexcept { + if (retain_styling) + return ncplane_putwegc_stainable (plane, gclust, sbytes); return ncplane_putwegc (plane, gclust, sbytes); } @@ -669,6 +675,16 @@ namespace ncpp ncplane_styles_off (plane, static_cast(styles)); } + bool format (int ystop, int xstop, uint32_t attrword) const noexcept + { + return ncplane_format (plane, ystop, xstop, attrword) != -1; + } + + bool 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; + } + Plane* get_below () const noexcept { return map_plane (ncplane_below (plane)); @@ -832,6 +848,34 @@ namespace ncpp return duplicate (*target, source); } + void translate (const Plane *dst, int *y = nullptr, int *x = nullptr) const + { + if (dst == nullptr) + throw invalid_argument ("'dst' must be a valid pointer"); + translate (*this, *dst, y, x); + } + + void translate (const Plane &dst, int *y = nullptr, int *x = nullptr) noexcept + { + translate (*this, dst, y, x); + } + + static void translate (const Plane *src, const Plane *dst, int *y = nullptr, int *x = nullptr) + { + if (src == nullptr) + throw invalid_argument ("'src' must be a valid pointer"); + + if (dst == nullptr) + throw invalid_argument ("'dst' must be a valid pointer"); + + translate (*src, *dst, y, x); + } + + static void translate (const Plane &src, const Plane &dst, int *y = nullptr, int *x = nullptr) noexcept + { + ncplane_translate (src.plane, dst.plane, y, x); + } + // 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 {