notcurses/include/ncpp/Reel.hh

146 lines
3.2 KiB
C++
Raw Normal View History

2020-02-05 22:29:42 +00:00
#ifndef __NCPP_REEL_HH
#define __NCPP_REEL_HH
2020-01-07 22:51:34 +00:00
#include <memory>
#include <notcurses/notcurses.h>
2020-01-07 22:51:34 +00:00
#include "Tablet.hh"
#include "Plane.hh"
#include "Utilities.hh"
#include "Widget.hh"
2020-01-07 22:51:34 +00:00
namespace ncpp
{
class NCPP_API_EXPORT NcReel : public Widget
2020-01-07 22:51:34 +00:00
{
public:
2020-02-05 22:29:42 +00:00
static ncreel_options default_options;
2020-01-07 22:51:34 +00:00
Tons of work on ncreel (#776) Tons of work on ncreel (#627, #749, #694) Improve reel demo: get input wired up once more, avoid the FPS demo at bottom, print pointer and line count in each tablet, use new ncreel API. Improve notcurses-ncreel explorer: kill memory leaks (#694), draw tablets better, use new ncreel API. Fix bug in ncreel core where cruft could be left on the screen, via a very gross brute force algorithm. I'll likely come back and make this a bit less ghastly in the future #749. Remove weird one-off input system from ncreel, residue from outcurses. Make some of the normalizing changes speced out in #627 * ncreel: give each tablet an index, and print it #749 * reel: eliminate FIXME + param to insert_tabler() #749 * ncreel: label tablets with their adress to correlate against debugging logs #749 * more terminal environment variable notes * TERMS.md: add Sakura, st * ncreel: move legend out of reel proper * ncreel_options: dump min/max_supported_rows/cols #627 * ncreel: remove weird one-off input layer #627 * ncreel: add ncreel_offer_input() * reel demo: call demo_getc() * reel demo: rig up input to demo main * ncreel: drop ncreel_del_focused(), properly bind tablets * reel demo: don't free up necessary plane * ncreel: don't pull absolute locations of tablets * ncreel: place tablets correctly in boundrel * reel demo: add back support for left/right * reel demo: restore thread movement * ncreel: remove a great deal of complexity * reel demo: stay out of FPS graph's way * ncreel: give each tablet an index, and print it #749 * reel: eliminate FIXME + param to insert_tabler() #749 * ncreel: label tablets with their adress to correlate against debugging logs #749 * ncreel: move legend out of reel proper * ncreel_options: dump min/max_supported_rows/cols #627 * ncreel: remove weird one-off input layer #627 * ncreel: add ncreel_offer_input() * reel demo: call demo_getc() * reel demo: rig up input to demo main * ncreel: drop ncreel_del_focused(), properly bind tablets * reel demo: don't free up necessary plane * ncreel: don't pull absolute locations of tablets * ncreel: place tablets correctly in boundrel * reel demo: add back support for left/right * reel demo: restore thread movement * ncreel: remove a great deal of complexity * reel demo: stay out of FPS graph's way * reel: tighten up reel following redraw * reel: fix upper-left corner of topless perimeter * ncreel: print linecount, return clipped value * reel: draw focused tablet relative to reel * reel: brute force decruftification, how embarrassing #749
2020-07-09 06:02:23 +00:00
explicit NcReel (Plane &plane, const ncreel_options *popts = nullptr)
: Widget (Utilities::get_notcurses_cpp (plane))
2020-01-07 22:51:34 +00:00
{
ensure_valid_plane (plane);
Tons of work on ncreel (#776) Tons of work on ncreel (#627, #749, #694) Improve reel demo: get input wired up once more, avoid the FPS demo at bottom, print pointer and line count in each tablet, use new ncreel API. Improve notcurses-ncreel explorer: kill memory leaks (#694), draw tablets better, use new ncreel API. Fix bug in ncreel core where cruft could be left on the screen, via a very gross brute force algorithm. I'll likely come back and make this a bit less ghastly in the future #749. Remove weird one-off input system from ncreel, residue from outcurses. Make some of the normalizing changes speced out in #627 * ncreel: give each tablet an index, and print it #749 * reel: eliminate FIXME + param to insert_tabler() #749 * ncreel: label tablets with their adress to correlate against debugging logs #749 * more terminal environment variable notes * TERMS.md: add Sakura, st * ncreel: move legend out of reel proper * ncreel_options: dump min/max_supported_rows/cols #627 * ncreel: remove weird one-off input layer #627 * ncreel: add ncreel_offer_input() * reel demo: call demo_getc() * reel demo: rig up input to demo main * ncreel: drop ncreel_del_focused(), properly bind tablets * reel demo: don't free up necessary plane * ncreel: don't pull absolute locations of tablets * ncreel: place tablets correctly in boundrel * reel demo: add back support for left/right * reel demo: restore thread movement * ncreel: remove a great deal of complexity * reel demo: stay out of FPS graph's way * ncreel: give each tablet an index, and print it #749 * reel: eliminate FIXME + param to insert_tabler() #749 * ncreel: label tablets with their adress to correlate against debugging logs #749 * ncreel: move legend out of reel proper * ncreel_options: dump min/max_supported_rows/cols #627 * ncreel: remove weird one-off input layer #627 * ncreel: add ncreel_offer_input() * reel demo: call demo_getc() * reel demo: rig up input to demo main * ncreel: drop ncreel_del_focused(), properly bind tablets * reel demo: don't free up necessary plane * ncreel: don't pull absolute locations of tablets * ncreel: place tablets correctly in boundrel * reel demo: add back support for left/right * reel demo: restore thread movement * ncreel: remove a great deal of complexity * reel demo: stay out of FPS graph's way * reel: tighten up reel following redraw * reel: fix upper-left corner of topless perimeter * ncreel: print linecount, return clipped value * reel: draw focused tablet relative to reel * reel: brute force decruftification, how embarrassing #749
2020-07-09 06:02:23 +00:00
common_init (Utilities::to_ncplane (plane), popts);
take_plane_ownership (plane);
2020-01-07 22:51:34 +00:00
}
Tons of work on ncreel (#776) Tons of work on ncreel (#627, #749, #694) Improve reel demo: get input wired up once more, avoid the FPS demo at bottom, print pointer and line count in each tablet, use new ncreel API. Improve notcurses-ncreel explorer: kill memory leaks (#694), draw tablets better, use new ncreel API. Fix bug in ncreel core where cruft could be left on the screen, via a very gross brute force algorithm. I'll likely come back and make this a bit less ghastly in the future #749. Remove weird one-off input system from ncreel, residue from outcurses. Make some of the normalizing changes speced out in #627 * ncreel: give each tablet an index, and print it #749 * reel: eliminate FIXME + param to insert_tabler() #749 * ncreel: label tablets with their adress to correlate against debugging logs #749 * more terminal environment variable notes * TERMS.md: add Sakura, st * ncreel: move legend out of reel proper * ncreel_options: dump min/max_supported_rows/cols #627 * ncreel: remove weird one-off input layer #627 * ncreel: add ncreel_offer_input() * reel demo: call demo_getc() * reel demo: rig up input to demo main * ncreel: drop ncreel_del_focused(), properly bind tablets * reel demo: don't free up necessary plane * ncreel: don't pull absolute locations of tablets * ncreel: place tablets correctly in boundrel * reel demo: add back support for left/right * reel demo: restore thread movement * ncreel: remove a great deal of complexity * reel demo: stay out of FPS graph's way * ncreel: give each tablet an index, and print it #749 * reel: eliminate FIXME + param to insert_tabler() #749 * ncreel: label tablets with their adress to correlate against debugging logs #749 * ncreel: move legend out of reel proper * ncreel_options: dump min/max_supported_rows/cols #627 * ncreel: remove weird one-off input layer #627 * ncreel: add ncreel_offer_input() * reel demo: call demo_getc() * reel demo: rig up input to demo main * ncreel: drop ncreel_del_focused(), properly bind tablets * reel demo: don't free up necessary plane * ncreel: don't pull absolute locations of tablets * ncreel: place tablets correctly in boundrel * reel demo: add back support for left/right * reel demo: restore thread movement * ncreel: remove a great deal of complexity * reel demo: stay out of FPS graph's way * reel: tighten up reel following redraw * reel: fix upper-left corner of topless perimeter * ncreel: print linecount, return clipped value * reel: draw focused tablet relative to reel * reel: brute force decruftification, how embarrassing #749
2020-07-09 06:02:23 +00:00
explicit NcReel (Plane *plane, const ncreel_options *popts = nullptr)
: Widget (Utilities::get_notcurses_cpp (plane))
2020-01-07 22:51:34 +00:00
{
if (plane == nullptr)
throw invalid_argument ("'plane' must be a valid pointer");
2020-01-07 22:51:34 +00:00
ensure_valid_plane (plane);
Tons of work on ncreel (#776) Tons of work on ncreel (#627, #749, #694) Improve reel demo: get input wired up once more, avoid the FPS demo at bottom, print pointer and line count in each tablet, use new ncreel API. Improve notcurses-ncreel explorer: kill memory leaks (#694), draw tablets better, use new ncreel API. Fix bug in ncreel core where cruft could be left on the screen, via a very gross brute force algorithm. I'll likely come back and make this a bit less ghastly in the future #749. Remove weird one-off input system from ncreel, residue from outcurses. Make some of the normalizing changes speced out in #627 * ncreel: give each tablet an index, and print it #749 * reel: eliminate FIXME + param to insert_tabler() #749 * ncreel: label tablets with their adress to correlate against debugging logs #749 * more terminal environment variable notes * TERMS.md: add Sakura, st * ncreel: move legend out of reel proper * ncreel_options: dump min/max_supported_rows/cols #627 * ncreel: remove weird one-off input layer #627 * ncreel: add ncreel_offer_input() * reel demo: call demo_getc() * reel demo: rig up input to demo main * ncreel: drop ncreel_del_focused(), properly bind tablets * reel demo: don't free up necessary plane * ncreel: don't pull absolute locations of tablets * ncreel: place tablets correctly in boundrel * reel demo: add back support for left/right * reel demo: restore thread movement * ncreel: remove a great deal of complexity * reel demo: stay out of FPS graph's way * ncreel: give each tablet an index, and print it #749 * reel: eliminate FIXME + param to insert_tabler() #749 * ncreel: label tablets with their adress to correlate against debugging logs #749 * ncreel: move legend out of reel proper * ncreel_options: dump min/max_supported_rows/cols #627 * ncreel: remove weird one-off input layer #627 * ncreel: add ncreel_offer_input() * reel demo: call demo_getc() * reel demo: rig up input to demo main * ncreel: drop ncreel_del_focused(), properly bind tablets * reel demo: don't free up necessary plane * ncreel: don't pull absolute locations of tablets * ncreel: place tablets correctly in boundrel * reel demo: add back support for left/right * reel demo: restore thread movement * ncreel: remove a great deal of complexity * reel demo: stay out of FPS graph's way * reel: tighten up reel following redraw * reel: fix upper-left corner of topless perimeter * ncreel: print linecount, return clipped value * reel: draw focused tablet relative to reel * reel: brute force decruftification, how embarrassing #749
2020-07-09 06:02:23 +00:00
common_init (Utilities::to_ncplane (plane), popts);
take_plane_ownership (plane);
2020-01-07 22:51:34 +00:00
}
2020-02-05 22:29:42 +00:00
~NcReel ()
2020-01-07 22:51:34 +00:00
{
if (!is_notcurses_stopped ())
2020-02-05 22:29:42 +00:00
ncreel_destroy (reel);
2020-01-07 22:51:34 +00:00
}
2020-02-05 22:29:42 +00:00
operator ncreel* () const noexcept
2020-01-07 22:51:34 +00:00
{
return reel;
}
2020-02-05 22:29:42 +00:00
operator ncreel const* () const noexcept
2020-01-07 22:51:34 +00:00
{
return reel;
}
// TODO: add an overload using callback that takes NcTablet instance instead of struct tablet
NcTablet* add (NcTablet *after, NcTablet *before, tabletcb cb, void *opaque = nullptr) const
2020-01-07 22:51:34 +00:00
{
nctablet *t = ncreel_add (reel, get_tablet (after), get_tablet (before), cb, opaque);
2020-01-07 22:51:34 +00:00
if (t == nullptr)
throw init_error ("Notcurses failed to create a new tablet");
2020-01-07 22:51:34 +00:00
return NcTablet::map_tablet (t, get_notcurses_cpp ());
2020-01-07 22:51:34 +00:00
}
NcTablet* add (NcTablet &after, NcTablet &before, tabletcb cb, void *opaque = nullptr) const noexcept
2020-01-07 22:51:34 +00:00
{
return add (&after, &before, cb, opaque);
}
int get_tabletcount () const noexcept
{
2020-02-05 22:29:42 +00:00
return ncreel_tabletcount (reel);
2020-01-07 22:51:34 +00:00
}
bool del (NcTablet *t) const NOEXCEPT_MAYBE
2020-01-07 22:51:34 +00:00
{
return error_guard (ncreel_del (reel, get_tablet (t)), -1);
2020-01-07 22:51:34 +00:00
}
bool del (NcTablet &t) const NOEXCEPT_MAYBE
2020-01-07 22:51:34 +00:00
{
return del (&t);
}
bool redraw () const NOEXCEPT_MAYBE
2020-01-07 22:51:34 +00:00
{
return error_guard (ncreel_redraw (reel), -1);
2020-01-07 22:51:34 +00:00
}
NcTablet* get_focused () const noexcept
2020-01-07 22:51:34 +00:00
{
nctablet *t = ncreel_focused (reel);
2020-01-07 22:51:34 +00:00
if (t == nullptr)
return nullptr;
return NcTablet::map_tablet (t, get_notcurses_cpp ());
2020-01-07 22:51:34 +00:00
}
NcTablet* next () const noexcept
2020-01-07 22:51:34 +00:00
{
nctablet *t = ncreel_next (reel);
2020-01-07 22:51:34 +00:00
if (t == nullptr)
return nullptr;
return NcTablet::map_tablet (t, get_notcurses_cpp ());
2020-01-07 22:51:34 +00:00
}
NcTablet* prev () const noexcept
2020-01-07 22:51:34 +00:00
{
nctablet *t = ncreel_prev (reel);
2020-01-07 22:51:34 +00:00
if (t == nullptr)
return nullptr;
return NcTablet::map_tablet (t, get_notcurses_cpp ());
2020-01-07 22:51:34 +00:00
}
bool offer_input (const struct ncinput* nci) const NOEXCEPT_MAYBE
{
return error_guard<bool, bool> (ncreel_offer_input (reel, nci), false);
}
2020-01-07 22:51:34 +00:00
Plane* get_plane () const noexcept;
private:
nctablet* get_tablet (NcTablet *t) const noexcept
2020-01-07 22:51:34 +00:00
{
if (t == nullptr)
return nullptr;
return t->get_tablet ();
}
Tons of work on ncreel (#776) Tons of work on ncreel (#627, #749, #694) Improve reel demo: get input wired up once more, avoid the FPS demo at bottom, print pointer and line count in each tablet, use new ncreel API. Improve notcurses-ncreel explorer: kill memory leaks (#694), draw tablets better, use new ncreel API. Fix bug in ncreel core where cruft could be left on the screen, via a very gross brute force algorithm. I'll likely come back and make this a bit less ghastly in the future #749. Remove weird one-off input system from ncreel, residue from outcurses. Make some of the normalizing changes speced out in #627 * ncreel: give each tablet an index, and print it #749 * reel: eliminate FIXME + param to insert_tabler() #749 * ncreel: label tablets with their adress to correlate against debugging logs #749 * more terminal environment variable notes * TERMS.md: add Sakura, st * ncreel: move legend out of reel proper * ncreel_options: dump min/max_supported_rows/cols #627 * ncreel: remove weird one-off input layer #627 * ncreel: add ncreel_offer_input() * reel demo: call demo_getc() * reel demo: rig up input to demo main * ncreel: drop ncreel_del_focused(), properly bind tablets * reel demo: don't free up necessary plane * ncreel: don't pull absolute locations of tablets * ncreel: place tablets correctly in boundrel * reel demo: add back support for left/right * reel demo: restore thread movement * ncreel: remove a great deal of complexity * reel demo: stay out of FPS graph's way * ncreel: give each tablet an index, and print it #749 * reel: eliminate FIXME + param to insert_tabler() #749 * ncreel: label tablets with their adress to correlate against debugging logs #749 * ncreel: move legend out of reel proper * ncreel_options: dump min/max_supported_rows/cols #627 * ncreel: remove weird one-off input layer #627 * ncreel: add ncreel_offer_input() * reel demo: call demo_getc() * reel demo: rig up input to demo main * ncreel: drop ncreel_del_focused(), properly bind tablets * reel demo: don't free up necessary plane * ncreel: don't pull absolute locations of tablets * ncreel: place tablets correctly in boundrel * reel demo: add back support for left/right * reel demo: restore thread movement * ncreel: remove a great deal of complexity * reel demo: stay out of FPS graph's way * reel: tighten up reel following redraw * reel: fix upper-left corner of topless perimeter * ncreel: print linecount, return clipped value * reel: draw focused tablet relative to reel * reel: brute force decruftification, how embarrassing #749
2020-07-09 06:02:23 +00:00
void common_init (ncplane *plane, const ncreel_options *popts = nullptr)
2020-01-07 22:51:34 +00:00
{
Tons of work on ncreel (#776) Tons of work on ncreel (#627, #749, #694) Improve reel demo: get input wired up once more, avoid the FPS demo at bottom, print pointer and line count in each tablet, use new ncreel API. Improve notcurses-ncreel explorer: kill memory leaks (#694), draw tablets better, use new ncreel API. Fix bug in ncreel core where cruft could be left on the screen, via a very gross brute force algorithm. I'll likely come back and make this a bit less ghastly in the future #749. Remove weird one-off input system from ncreel, residue from outcurses. Make some of the normalizing changes speced out in #627 * ncreel: give each tablet an index, and print it #749 * reel: eliminate FIXME + param to insert_tabler() #749 * ncreel: label tablets with their adress to correlate against debugging logs #749 * more terminal environment variable notes * TERMS.md: add Sakura, st * ncreel: move legend out of reel proper * ncreel_options: dump min/max_supported_rows/cols #627 * ncreel: remove weird one-off input layer #627 * ncreel: add ncreel_offer_input() * reel demo: call demo_getc() * reel demo: rig up input to demo main * ncreel: drop ncreel_del_focused(), properly bind tablets * reel demo: don't free up necessary plane * ncreel: don't pull absolute locations of tablets * ncreel: place tablets correctly in boundrel * reel demo: add back support for left/right * reel demo: restore thread movement * ncreel: remove a great deal of complexity * reel demo: stay out of FPS graph's way * ncreel: give each tablet an index, and print it #749 * reel: eliminate FIXME + param to insert_tabler() #749 * ncreel: label tablets with their adress to correlate against debugging logs #749 * ncreel: move legend out of reel proper * ncreel_options: dump min/max_supported_rows/cols #627 * ncreel: remove weird one-off input layer #627 * ncreel: add ncreel_offer_input() * reel demo: call demo_getc() * reel demo: rig up input to demo main * ncreel: drop ncreel_del_focused(), properly bind tablets * reel demo: don't free up necessary plane * ncreel: don't pull absolute locations of tablets * ncreel: place tablets correctly in boundrel * reel demo: add back support for left/right * reel demo: restore thread movement * ncreel: remove a great deal of complexity * reel demo: stay out of FPS graph's way * reel: tighten up reel following redraw * reel: fix upper-left corner of topless perimeter * ncreel: print linecount, return clipped value * reel: draw focused tablet relative to reel * reel: brute force decruftification, how embarrassing #749
2020-07-09 06:02:23 +00:00
reel = ncreel_create (plane, popts == nullptr ? &default_options : popts);
2020-01-07 22:51:34 +00:00
if (reel == nullptr)
throw init_error ("Notcurses failed to create a new ncreel");
2020-01-07 22:51:34 +00:00
}
private:
2020-02-05 22:29:42 +00:00
ncreel *reel = nullptr;
2020-01-07 22:51:34 +00:00
friend class Plane;
};
}
#endif