Notcurses 3.0.13
a blingful library for TUIs and character graphics
Loading...
Searching...
No Matches
Visual.hh
Go to the documentation of this file.
1#ifndef __NCPP_VISUAL_HH
2#define __NCPP_VISUAL_HH
3
5
6#include "Root.hh"
7#include "Plane.hh"
8#include "Utilities.hh"
9#include "NotCurses.hh"
10
11namespace ncpp
12{
13 class NotCurses;
14 class Plane;
15
17 {
18 public:
19 explicit Visual (const char *file)
20 : Root (NotCurses::get_instance ())
21 {
22 visual = ncvisual_from_file (file);
23 if (visual == nullptr)
24 throw init_error ("Notcurses failed to create a new visual");
25 }
26
27 explicit Visual (const uint32_t* rgba, int rows, int rowstride, int cols)
28 : Root (NotCurses::get_instance ())
29 {
30 visual = ncvisual_from_rgba (rgba, rows, rowstride, cols);
31 if (visual == nullptr)
32 throw init_error ("Notcurses failed to create a new visual");
33 }
34
35 explicit Visual (const Plane& p, ncblitter_e blit, unsigned begy, unsigned begx, unsigned leny, unsigned lenx)
36 : Root (NotCurses::get_instance ())
37 {
38 visual = ncvisual_from_plane (p, blit, begy, begx, leny, lenx);
39 if (visual == nullptr)
40 throw init_error ("Notcurses failed to create a new visual");
41 }
42
43 ~Visual () noexcept
44 {
45 if (!is_notcurses_stopped ())
46 ncvisual_destroy (visual);
47 }
48
49 operator ncvisual* () const noexcept
50 {
51 return visual;
52 }
53
54 operator ncvisual const* () const noexcept
55 {
56 return visual;
57 }
58
59 int decode () const noexcept
60 {
61 return ncvisual_decode (visual);
62 }
63
64 int decode_loop () const noexcept
65 {
66 return ncvisual_decode_loop (visual);
67 }
68
70 {
71 return error_guard<ncplane*, ncplane*> (ncvisual_blit (get_notcurses (), visual, vopts), nullptr);
72 }
73
74 int stream (const ncvisual_options* vopts, float timescale, ncstreamcb streamer, void *curry = nullptr) const NOEXCEPT_MAYBE
75 {
76 return error_guard<int> (ncvisual_stream (get_notcurses (), visual, timescale, streamer, vopts, curry), -1);
77 }
78
79 ncplane* subtitle (Plane& parent) noexcept
80 {
81 return ncvisual_subtitle_plane (parent, visual);
82 }
83
84 bool rotate (double rads) const NOEXCEPT_MAYBE
85 {
86 return error_guard (ncvisual_rotate (visual, rads), -1);
87 }
88
89 bool simple_streamer (ncvisual_options* vopts, const timespec* tspec, void* curry = nullptr) const NOEXCEPT_MAYBE
90 {
91 return error_guard (ncvisual_simple_streamer (visual, vopts, tspec, curry), -1);
92 }
93
94 int polyfill (int y, int x, uint32_t rgba) const NOEXCEPT_MAYBE
95 {
96 return error_guard<int> (ncvisual_polyfill_yx (visual, y, x, rgba), -1);
97 }
98
99 bool geom (const struct ncvisual_options *vopts, ncvgeom* geom) const NOEXCEPT_MAYBE
100 {
101 return error_guard (ncvisual_geom (get_notcurses (), visual, vopts, geom), -1);
102 }
103
104 bool at (int y, int x, uint32_t* pixel) const
105 {
106 if (pixel == nullptr)
107 throw invalid_argument ("'pixel' must be a valid pointer");
108
109 return error_guard (ncvisual_at_yx (visual, y, x, pixel), -1);
110 }
111
112 bool set (int y, int x, uint32_t pixel) const NOEXCEPT_MAYBE
113 {
114 return error_guard (ncvisual_set_yx (visual, y, x, pixel), -1);
115 }
116
117 private:
118 void common_init (ncplane *plane, const char *file)
119 {
120 if (plane == nullptr)
121 throw invalid_argument ("'plane' must be a valid pointer");
122
123 visual = ncvisual_from_file (file);
124 if (visual == nullptr)
125 throw init_error ("Notcurses failed to create a new visual");
126 }
127
128 private:
129 ncvisual *visual = nullptr;
130 };
131}
132#endif
#define NCPP_API_EXPORT
Definition _helpers.hh:9
#define NOEXCEPT_MAYBE
Definition Root.hh:15
~Visual() noexcept
Definition Visual.hh:43
Visual(const Plane &p, ncblitter_e blit, unsigned begy, unsigned begx, unsigned leny, unsigned lenx)
Definition Visual.hh:35
int decode() const noexcept
Definition Visual.hh:59
bool geom(const struct ncvisual_options *vopts, ncvgeom *geom) const NOEXCEPT_MAYBE
Definition Visual.hh:99
bool at(int y, int x, uint32_t *pixel) const
Definition Visual.hh:104
ncplane * subtitle(Plane &parent) noexcept
Definition Visual.hh:79
int polyfill(int y, int x, uint32_t rgba) const NOEXCEPT_MAYBE
Definition Visual.hh:94
ncplane * blit(const ncvisual_options *vopts) const NOEXCEPT_MAYBE
Definition Visual.hh:69
bool set(int y, int x, uint32_t pixel) const NOEXCEPT_MAYBE
Definition Visual.hh:112
Visual(const char *file)
Definition Visual.hh:19
int decode_loop() const noexcept
Definition Visual.hh:64
int stream(const ncvisual_options *vopts, float timescale, ncstreamcb streamer, void *curry=nullptr) const NOEXCEPT_MAYBE
Definition Visual.hh:74
Visual(const uint32_t *rgba, int rows, int rowstride, int cols)
Definition Visual.hh:27
bool simple_streamer(ncvisual_options *vopts, const timespec *tspec, void *curry=nullptr) const NOEXCEPT_MAYBE
Definition Visual.hh:89
bool rotate(double rads) const NOEXCEPT_MAYBE
Definition Visual.hh:84
int y
Definition notcurses.h:1905
const struct ncplane_options struct ncvisual struct ncvisual_options * vopts
Definition notcurses.h:3484
ncblitter_e
Definition notcurses.h:65
int int x
Definition notcurses.h:1905
int(* ncstreamcb)(struct ncvisual *, struct ncvisual_options *, const struct timespec *, void *)
Definition notcurses.h:3533
ncvisual * ncvisual_from_rgba(const void *rgba, int rows, int rowstride, int cols)
Definition visual.c:776
int ncvisual_decode(ncvisual *nc)
Definition visual.c:39
int ncvisual_set_yx(const struct ncvisual *n, unsigned y, unsigned x, uint32_t pixel)
Definition visual.c:1259
ncvisual * ncvisual_from_file(const char *filename)
Definition visual.c:53
ncplane * ncvisual_subtitle_plane(ncplane *parent, const ncvisual *ncv)
Definition visual.c:77
int ncvisual_decode_loop(ncvisual *nc)
Definition visual.c:46
int ncvisual_rotate(ncvisual *ncv, double rads)
Definition visual.c:704
ncvisual * ncvisual_from_plane(const ncplane *n, ncblitter_e blit, int begy, int begx, unsigned leny, unsigned lenx)
Definition visual.c:1208
int ncvisual_stream(notcurses *nc, ncvisual *ncv, float timescale, ncstreamcb streamer, const struct ncvisual_options *vopts, void *curry)
Definition visual.c:64
void ncvisual_destroy(ncvisual *ncv)
Definition visual.c:1225
int ncvisual_geom(const notcurses *nc, const ncvisual *n, const struct ncvisual_options *vopts, ncvgeom *geom)
Definition visual.c:452
int ncvisual_simple_streamer(ncvisual *ncv, struct ncvisual_options *vopts, const struct timespec *tspec, void *curry)
Definition visual.c:1238
int ncvisual_polyfill_yx(ncvisual *n, unsigned y, unsigned x, uint32_t rgba)
Definition visual.c:1344
int ncvisual_at_yx(const ncvisual *n, unsigned y, unsigned x, uint32_t *pixel)
Definition visual.c:1272
ncplane * ncvisual_blit(notcurses *nc, ncvisual *ncv, const struct ncvisual_options *vopts)
Definition visual.c:1136