2020-01-07 22:51:34 +00:00
|
|
|
#ifndef __NCPP_VISUAL_HH
|
|
|
|
#define __NCPP_VISUAL_HH
|
|
|
|
|
2020-02-18 17:36:16 +00:00
|
|
|
#include <notcurses/notcurses.h>
|
2020-01-07 22:51:34 +00:00
|
|
|
|
|
|
|
#include "Root.hh"
|
Fully general ncvisual layer (#647)
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.
2020-05-29 01:16:58 +00:00
|
|
|
#include "Plane.hh"
|
2020-05-22 20:11:59 +00:00
|
|
|
#include "Utilities.hh"
|
Fully general ncvisual layer (#647)
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.
2020-05-29 01:16:58 +00:00
|
|
|
#include "NotCurses.hh"
|
2020-01-07 22:51:34 +00:00
|
|
|
|
|
|
|
namespace ncpp
|
|
|
|
{
|
2020-05-24 12:41:18 +00:00
|
|
|
class NotCurses;
|
2020-01-07 22:51:34 +00:00
|
|
|
class Plane;
|
|
|
|
|
|
|
|
class NCPP_API_EXPORT Visual : public Root
|
|
|
|
{
|
|
|
|
public:
|
2020-08-24 05:23:35 +00:00
|
|
|
explicit Visual (const char *file)
|
2020-06-07 20:01:45 +00:00
|
|
|
: Root (NotCurses::get_instance ())
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
2020-08-24 05:23:35 +00:00
|
|
|
visual = ncvisual_from_file (file);
|
2020-01-07 22:51:34 +00:00
|
|
|
if (visual == nullptr)
|
2020-05-20 04:15:38 +00:00
|
|
|
throw init_error ("Notcurses failed to create a new visual");
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
2020-06-07 20:01:45 +00:00
|
|
|
explicit Visual (const uint32_t* rgba, int rows, int rowstride, int cols)
|
|
|
|
: Root (NotCurses::get_instance ())
|
|
|
|
{
|
2020-05-30 00:14:34 +00:00
|
|
|
visual = ncvisual_from_rgba (rgba, rows, rowstride, cols);
|
|
|
|
if (visual == nullptr)
|
|
|
|
throw init_error ("Notcurses failed to create a new visual");
|
2020-06-07 20:01:45 +00:00
|
|
|
}
|
2020-05-30 00:14:34 +00:00
|
|
|
|
2020-06-07 20:01:45 +00:00
|
|
|
explicit Visual (const Plane& p, ncblitter_e blit, int begy, int begx, int leny, int lenx)
|
|
|
|
: Root (NotCurses::get_instance ())
|
|
|
|
{
|
2020-06-06 09:11:45 +00:00
|
|
|
visual = ncvisual_from_plane (p, blit, begy, begx, leny, lenx);
|
2020-05-30 00:14:34 +00:00
|
|
|
if (visual == nullptr)
|
|
|
|
throw init_error ("Notcurses failed to create a new visual");
|
2020-06-07 20:01:45 +00:00
|
|
|
}
|
2020-05-30 00:14:34 +00:00
|
|
|
|
2020-01-07 22:51:34 +00:00
|
|
|
~Visual () noexcept
|
|
|
|
{
|
|
|
|
if (!is_notcurses_stopped ())
|
|
|
|
ncvisual_destroy (visual);
|
|
|
|
}
|
|
|
|
|
|
|
|
operator ncvisual* () const noexcept
|
|
|
|
{
|
|
|
|
return visual;
|
|
|
|
}
|
|
|
|
|
|
|
|
operator ncvisual const* () const noexcept
|
|
|
|
{
|
|
|
|
return visual;
|
|
|
|
}
|
|
|
|
|
2020-08-24 05:23:35 +00:00
|
|
|
int decode () const noexcept
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
2020-04-24 06:23:06 +00:00
|
|
|
return ncvisual_decode (visual);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
Fully general ncvisual layer (#647)
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.
2020-05-29 01:16:58 +00:00
|
|
|
ncplane* render (const ncvisual_options* vopts) const NOEXCEPT_MAYBE
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
2020-06-07 20:01:45 +00:00
|
|
|
return error_guard<ncplane*, ncplane*> (ncvisual_render (get_notcurses (), visual, vopts), nullptr);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
2020-08-24 05:23:35 +00:00
|
|
|
int stream (const ncvisual_options* vopts, float timescale, streamcb streamer, void *curry = nullptr) const NOEXCEPT_MAYBE
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
2020-08-24 05:23:35 +00:00
|
|
|
return error_guard<int> (ncvisual_stream (get_notcurses (), visual, timescale, streamer, vopts, curry), -1);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
2020-04-12 21:09:03 +00:00
|
|
|
char* subtitle () const noexcept
|
|
|
|
{
|
|
|
|
return ncvisual_subtitle (visual);
|
|
|
|
}
|
2020-01-30 13:55:01 +00:00
|
|
|
|
2020-05-06 09:49:22 +00:00
|
|
|
bool rotate (double rads) const NOEXCEPT_MAYBE
|
2020-05-04 04:51:42 +00:00
|
|
|
{
|
2020-08-24 05:23:35 +00:00
|
|
|
return error_guard (ncvisual_rotate (visual, rads), -1);
|
2020-06-07 20:01:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool simple_streamer (ncvisual_options* vopts, const timespec* tspec, void* curry = nullptr) const NOEXCEPT_MAYBE
|
|
|
|
{
|
|
|
|
return error_guard (ncvisual_simple_streamer (visual, vopts, tspec, curry), -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int polyfill (int y, int x, uint32_t rgba) const NOEXCEPT_MAYBE
|
|
|
|
{
|
|
|
|
return error_guard<int> (ncvisual_polyfill_yx (visual, y, x, rgba), -1);
|
|
|
|
}
|
|
|
|
|
2020-06-22 19:49:13 +00:00
|
|
|
bool geom (const struct ncvisual_options *vopts, int *y, int *x, int *toy, int *tox) const NOEXCEPT_MAYBE
|
|
|
|
{
|
|
|
|
return error_guard (ncvisual_geom (get_notcurses (), visual, vopts, y, x, toy, tox), -1);
|
|
|
|
}
|
|
|
|
|
2020-06-07 20:01:45 +00:00
|
|
|
bool at (int y, int x, uint32_t* pixel) const
|
|
|
|
{
|
|
|
|
if (pixel == nullptr)
|
|
|
|
throw invalid_argument ("'pixel' must be a valid pointer");
|
|
|
|
|
|
|
|
return error_guard (ncvisual_at_yx (visual, y, x, pixel), -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool set (int y, int x, uint32_t pixel) const NOEXCEPT_MAYBE
|
|
|
|
{
|
|
|
|
return error_guard (ncvisual_set_yx (visual, y, x, pixel), -1);
|
2020-05-04 04:51:42 +00:00
|
|
|
}
|
|
|
|
|
2020-09-23 20:48:43 +00:00
|
|
|
static ncblitter_e get_default_blitter (bool utf8, ncscale_e scale) noexcept
|
|
|
|
{
|
|
|
|
return ncvisual_default_blitter (utf8, scale);
|
|
|
|
}
|
|
|
|
|
2020-05-24 12:41:18 +00:00
|
|
|
private:
|
2020-08-24 05:23:35 +00:00
|
|
|
void common_init (ncplane *plane, const char *file)
|
2020-05-24 12:41:18 +00:00
|
|
|
{
|
|
|
|
if (plane == nullptr)
|
|
|
|
throw invalid_argument ("'plane' must be a valid pointer");
|
|
|
|
|
2020-08-24 05:23:35 +00:00
|
|
|
visual = ncvisual_from_file (file);
|
2020-05-24 12:41:18 +00:00
|
|
|
if (visual == nullptr)
|
|
|
|
throw init_error ("Notcurses failed to create a new visual");
|
|
|
|
}
|
|
|
|
|
2020-01-07 22:51:34 +00:00
|
|
|
private:
|
|
|
|
ncvisual *visual = nullptr;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|