mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-02 09:40:15 +00:00
ebcba82d4b
This represents an essentially complete rewrite of ncvisual and associated code. It had two major goals: Improve the ncvisual API based off lessons learned, pursuant to the upcoming API freeze. In particular, I wanted to: decouple ncvisuals from ncplanes. It should be possible to render a ncvisual to multiple planes, with different scaling each time. It should be possible to create an ncvisual without a plane, etc. normalize the various ways of constructing an ncvisual -- file, memory, plane, etc. Support multiple blitters, from 7-bit ASCII to Sixel. This required writing the blitters in several cases, and they're not yet in their final implementations (but the API is fine) I have not yet unified Plots and Visuals, and might not, given that the Plot code works fine. We could at this point implement Plots in terms of Visuals, though -- the blitter backend range has been unified. Sixel is not yet implemented, though it is listed. There is a new POC tool, blitter. It renders its arguments using all possible blitter+scaling combinations. Another new POC, resize, displays its argument, then resizes it to the screen size and displays that, explicitly making use of ncvisual_resize() rather than a scaling parameter to ncvisual_render(). This also eliminates some memory leaks and bugs we were seeing in trunk, and brings in Sixel scaffolding. The C++ wrapper will also need patching back up; I cut most of it down while wrestling with this crap, urk. Closes #638, #562, and #622.
84 lines
1.8 KiB
C++
84 lines
1.8 KiB
C++
#ifndef __NCPP_VISUAL_HH
|
|
#define __NCPP_VISUAL_HH
|
|
|
|
#include <notcurses/notcurses.h>
|
|
|
|
#include "Root.hh"
|
|
#include "Plane.hh"
|
|
#include "Utilities.hh"
|
|
#include "NotCurses.hh"
|
|
|
|
namespace ncpp
|
|
{
|
|
class NotCurses;
|
|
class Plane;
|
|
|
|
class NCPP_API_EXPORT Visual : public Root
|
|
{
|
|
public:
|
|
explicit Visual (const char *file, nc_err_e *ncerr)
|
|
: Root(NotCurses::get_instance())
|
|
{
|
|
visual = ncvisual_from_file (file, ncerr);
|
|
if (visual == nullptr)
|
|
throw init_error ("Notcurses failed to create a new visual");
|
|
}
|
|
|
|
~Visual () noexcept
|
|
{
|
|
if (!is_notcurses_stopped ())
|
|
ncvisual_destroy (visual);
|
|
}
|
|
|
|
operator ncvisual* () const noexcept
|
|
{
|
|
return visual;
|
|
}
|
|
|
|
operator ncvisual const* () const noexcept
|
|
{
|
|
return visual;
|
|
}
|
|
|
|
nc_err_e decode () const noexcept
|
|
{
|
|
return ncvisual_decode (visual);
|
|
}
|
|
|
|
ncplane* render (const ncvisual_options* vopts) const NOEXCEPT_MAYBE
|
|
{
|
|
return ncvisual_render (get_notcurses (), visual, vopts); // FIXME error_guard
|
|
}
|
|
|
|
int stream (const ncvisual_options* vopts, nc_err_e* ncerr, float timescale, streamcb streamer, void *curry = nullptr) const NOEXCEPT_MAYBE
|
|
{
|
|
return error_guard<int> (ncvisual_stream (get_notcurses (), visual, ncerr, timescale, streamer, vopts, curry), -1);
|
|
}
|
|
|
|
char* subtitle () const noexcept
|
|
{
|
|
return ncvisual_subtitle (visual);
|
|
}
|
|
|
|
bool rotate (double rads) const NOEXCEPT_MAYBE
|
|
{
|
|
return error_guard (ncvisual_rotate (visual, rads), NCERR_SUCCESS); // FIXME invert case
|
|
}
|
|
|
|
private:
|
|
void common_init (ncplane *plane, const char *file, nc_err_e* ncerr)
|
|
{
|
|
if (plane == nullptr)
|
|
throw invalid_argument ("'plane' must be a valid pointer");
|
|
|
|
visual = ncvisual_from_file (file, ncerr);
|
|
if (visual == nullptr)
|
|
throw init_error ("Notcurses failed to create a new visual");
|
|
}
|
|
|
|
private:
|
|
ncvisual *visual = nullptr;
|
|
};
|
|
}
|
|
#endif
|