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"
|
|
|
|
#include "NCScale.hh"
|
|
|
|
|
|
|
|
namespace ncpp
|
|
|
|
{
|
|
|
|
class Plane;
|
|
|
|
|
|
|
|
class NCPP_API_EXPORT Visual : public Root
|
|
|
|
{
|
|
|
|
public:
|
2020-04-24 04:04:23 +00:00
|
|
|
explicit Visual (Plane *plane, const char *file, nc_err_e* ncerr)
|
|
|
|
: Visual (reinterpret_cast<ncplane*>(plane), file, ncerr)
|
2020-01-07 22:51:34 +00:00
|
|
|
{}
|
|
|
|
|
2020-04-24 04:04:23 +00:00
|
|
|
explicit Visual (Plane const* plane, const char *file, nc_err_e* ncerr)
|
|
|
|
: Visual (const_cast<Plane*>(plane), file, ncerr)
|
2020-02-16 19:25:26 +00:00
|
|
|
{}
|
|
|
|
|
2020-04-24 04:04:23 +00:00
|
|
|
explicit Visual (Plane &plane, const char *file, nc_err_e* ncerr)
|
|
|
|
: Visual (reinterpret_cast<ncplane*>(&plane), file, ncerr)
|
2020-02-16 19:25:26 +00:00
|
|
|
{}
|
|
|
|
|
2020-04-24 04:04:23 +00:00
|
|
|
explicit Visual (Plane const& plane, const char *file, nc_err_e* ncerr)
|
|
|
|
: Visual (const_cast<Plane&>(plane), file, ncerr)
|
2020-02-16 19:25:26 +00:00
|
|
|
{}
|
|
|
|
|
2020-04-24 04:04:23 +00:00
|
|
|
explicit Visual (ncplane *plane, const char *file, nc_err_e* ncerr)
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
|
|
|
if (plane == nullptr)
|
2020-02-16 19:25:26 +00:00
|
|
|
throw invalid_argument ("'plane' must be a valid pointer");
|
2020-01-07 22:51:34 +00:00
|
|
|
|
2020-04-24 04:04:23 +00:00
|
|
|
visual = ncplane_visual_open (reinterpret_cast<ncplane*>(plane), file, ncerr);
|
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-04-24 04:04:23 +00:00
|
|
|
explicit Visual (const char *file, nc_err_e* ncerr, int y, int x, NCScale scale)
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
2020-05-04 08:55:10 +00:00
|
|
|
visual = ncvisual_from_file (get_notcurses (), file, ncerr, y, x, static_cast<ncscale_e>(scale));
|
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
|
|
|
}
|
|
|
|
|
|
|
|
~Visual () noexcept
|
|
|
|
{
|
|
|
|
if (!is_notcurses_stopped ())
|
|
|
|
ncvisual_destroy (visual);
|
|
|
|
}
|
|
|
|
|
|
|
|
operator ncvisual* () const noexcept
|
|
|
|
{
|
|
|
|
return visual;
|
|
|
|
}
|
|
|
|
|
|
|
|
operator ncvisual const* () const noexcept
|
|
|
|
{
|
|
|
|
return visual;
|
|
|
|
}
|
|
|
|
|
2020-04-24 06:23:06 +00:00
|
|
|
nc_err_e 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
|
|
|
}
|
|
|
|
|
2020-04-12 21:09:03 +00:00
|
|
|
bool render (int begy, int begx, int leny, int lenx) const NOEXCEPT_MAYBE
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
2020-04-12 21:09:03 +00:00
|
|
|
return error_guard (ncvisual_render (visual, begy, begx, leny, lenx), -1);
|
2020-01-07 22:51:34 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 04:04:23 +00:00
|
|
|
int stream (nc_err_e* ncerr, float timescale, streamcb streamer, void *curry = nullptr) const NOEXCEPT_MAYBE
|
2020-01-07 22:51:34 +00:00
|
|
|
{
|
2020-04-24 04:04:23 +00:00
|
|
|
return error_guard<int> (ncvisual_stream (get_notcurses (), visual, ncerr, timescale, streamer, 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-01-07 22:51:34 +00:00
|
|
|
Plane* get_plane () const noexcept;
|
|
|
|
|
2020-05-06 09:49:22 +00:00
|
|
|
bool rotate (double rads) const NOEXCEPT_MAYBE
|
2020-05-04 04:51:42 +00:00
|
|
|
{
|
2020-05-06 09:49:22 +00:00
|
|
|
return error_guard (ncvisual_rotate (visual, rads), -1);
|
2020-05-04 04:51:42 +00:00
|
|
|
}
|
|
|
|
|
2020-01-07 22:51:34 +00:00
|
|
|
private:
|
|
|
|
ncvisual *visual = nullptr;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|