2020-02-15 22:04:39 +00:00
|
|
|
#ifndef __NCPP_DIRECT_HH
|
|
|
|
#define __NCPP_DIRECT_HH
|
|
|
|
|
|
|
|
#include <cstdio>
|
2020-07-10 19:51:28 +00:00
|
|
|
#include <notcurses/direct.h>
|
2020-02-18 17:36:16 +00:00
|
|
|
#include <notcurses/notcurses.h>
|
2020-02-15 22:04:39 +00:00
|
|
|
|
|
|
|
#include "Root.hh"
|
|
|
|
#include "Cell.hh"
|
|
|
|
|
|
|
|
namespace ncpp
|
|
|
|
{
|
2020-05-24 12:41:18 +00:00
|
|
|
class NotCurses;
|
|
|
|
|
2020-02-15 22:04:39 +00:00
|
|
|
class NCPP_API_EXPORT Direct : public Root
|
|
|
|
{
|
|
|
|
public:
|
2020-05-24 12:41:18 +00:00
|
|
|
explicit Direct (const char *termtype = nullptr, FILE *fp = nullptr, NotCurses *ncinst = nullptr)
|
|
|
|
: Root (ncinst)
|
2020-02-15 22:04:39 +00:00
|
|
|
{
|
2020-08-30 17:00:41 +00:00
|
|
|
direct = ncdirect_init (termtype, fp == nullptr ? stdout : fp, 0);
|
2020-02-15 22:04:39 +00:00
|
|
|
if (direct == nullptr)
|
2020-05-20 04:15:38 +00:00
|
|
|
throw init_error ("Notcurses failed to initialize direct mode");
|
2020-02-15 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~Direct ()
|
|
|
|
{
|
|
|
|
ncdirect_stop (direct);
|
|
|
|
}
|
|
|
|
|
2020-04-12 21:09:03 +00:00
|
|
|
bool clear () const NOEXCEPT_MAYBE
|
2020-02-15 22:04:39 +00:00
|
|
|
{
|
2020-04-12 21:09:03 +00:00
|
|
|
return error_guard (ncdirect_clear (direct), -1);
|
2020-02-15 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
2020-04-12 21:09:03 +00:00
|
|
|
bool set_fg_default () const NOEXCEPT_MAYBE
|
2020-02-15 22:04:39 +00:00
|
|
|
{
|
2020-12-28 18:38:05 +00:00
|
|
|
return error_guard (ncdirect_set_fg_default (direct), -1);
|
2020-02-15 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
2020-09-17 19:34:28 +00:00
|
|
|
bool set_fg_rgb (unsigned rgb) const NOEXCEPT_MAYBE
|
2020-02-15 22:04:39 +00:00
|
|
|
{
|
2020-12-28 18:52:58 +00:00
|
|
|
return error_guard (ncdirect_set_fg_rgb (direct, rgb), -1);
|
2020-02-15 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
2020-09-17 19:34:28 +00:00
|
|
|
bool set_fg_rgb (unsigned r, unsigned g, unsigned b) const NOEXCEPT_MAYBE
|
2020-02-15 22:04:39 +00:00
|
|
|
{
|
2020-12-28 18:52:58 +00:00
|
|
|
return error_guard (ncdirect_set_fg_rgb8 (direct, r, g, b), -1);
|
2020-02-15 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
2020-07-31 20:59:59 +00:00
|
|
|
bool fg_palindex (int pidx) const NOEXCEPT_MAYBE
|
|
|
|
{
|
2020-12-28 18:57:13 +00:00
|
|
|
return error_guard (ncdirect_set_fg_palindex (direct, pidx), -1);
|
2020-07-31 20:59:59 +00:00
|
|
|
}
|
|
|
|
|
2020-04-12 21:09:03 +00:00
|
|
|
bool set_bg_default () const NOEXCEPT_MAYBE
|
2020-02-15 22:04:39 +00:00
|
|
|
{
|
2020-12-28 18:38:05 +00:00
|
|
|
return error_guard (ncdirect_set_bg_default (direct), -1);
|
2020-02-15 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
2020-09-17 19:34:28 +00:00
|
|
|
bool set_bg_rgb (unsigned rgb) const NOEXCEPT_MAYBE
|
2020-02-15 22:04:39 +00:00
|
|
|
{
|
2020-12-28 18:52:58 +00:00
|
|
|
return error_guard (ncdirect_set_bg_rgb (direct, rgb), -1);
|
2020-02-15 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
2020-09-17 19:34:28 +00:00
|
|
|
bool set_bg_rgb (unsigned r, unsigned g, unsigned b) const NOEXCEPT_MAYBE
|
2020-02-15 22:04:39 +00:00
|
|
|
{
|
2020-12-28 18:52:58 +00:00
|
|
|
return error_guard (ncdirect_set_bg_rgb8 (direct, r, g, b), -1);
|
2020-02-15 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
2020-07-31 20:59:59 +00:00
|
|
|
bool bg_palindex (int pidx) const NOEXCEPT_MAYBE
|
|
|
|
{
|
2020-12-28 18:57:13 +00:00
|
|
|
return error_guard (ncdirect_set_bg_palindex (direct, pidx), -1);
|
2020-07-31 20:59:59 +00:00
|
|
|
}
|
|
|
|
|
2020-04-12 21:09:03 +00:00
|
|
|
int get_dim_x () const NOEXCEPT_MAYBE
|
2020-02-15 22:04:39 +00:00
|
|
|
{
|
2020-04-12 21:09:03 +00:00
|
|
|
return error_guard (ncdirect_dim_x (direct), -1);
|
2020-02-15 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
2020-04-12 21:09:03 +00:00
|
|
|
int get_dim_y () const NOEXCEPT_MAYBE
|
2020-02-15 22:04:39 +00:00
|
|
|
{
|
2020-04-12 21:09:03 +00:00
|
|
|
return error_guard (ncdirect_dim_y (direct), -1);
|
2020-02-15 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
2020-08-16 04:27:27 +00:00
|
|
|
unsigned get_palette_size () const noexcept
|
2020-07-31 20:59:59 +00:00
|
|
|
{
|
|
|
|
return ncdirect_palette_size (direct);
|
|
|
|
}
|
|
|
|
|
2020-02-15 22:04:39 +00:00
|
|
|
void styles_set (CellStyle stylebits) const noexcept
|
|
|
|
{
|
2020-12-28 07:21:37 +00:00
|
|
|
ncdirect_set_styles (direct, static_cast<unsigned>(stylebits));
|
2020-02-15 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void styles_on (CellStyle stylebits) const noexcept
|
|
|
|
{
|
2020-12-28 07:21:37 +00:00
|
|
|
ncdirect_on_styles (direct, static_cast<unsigned>(stylebits));
|
2020-02-15 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void styles_off (CellStyle stylebits) const noexcept
|
|
|
|
{
|
2020-12-28 07:21:37 +00:00
|
|
|
ncdirect_off_styles (direct, static_cast<unsigned>(stylebits));
|
2020-02-15 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
2020-04-12 21:09:03 +00:00
|
|
|
bool cursor_move_yx (int y, int x) const NOEXCEPT_MAYBE
|
2020-03-14 23:35:54 +00:00
|
|
|
{
|
2020-04-12 21:09:03 +00:00
|
|
|
return error_guard (ncdirect_cursor_move_yx (direct, y, x), -1);
|
2020-03-14 23:35:54 +00:00
|
|
|
}
|
|
|
|
|
2020-04-12 21:09:03 +00:00
|
|
|
bool cursor_up (int num) const NOEXCEPT_MAYBE
|
2020-04-11 22:20:11 +00:00
|
|
|
{
|
2020-04-12 21:09:03 +00:00
|
|
|
return error_guard (ncdirect_cursor_up (direct, num), -1);
|
2020-04-11 22:20:11 +00:00
|
|
|
}
|
|
|
|
|
2020-04-12 21:09:03 +00:00
|
|
|
bool cursor_left (int num) const NOEXCEPT_MAYBE
|
2020-04-11 22:20:11 +00:00
|
|
|
{
|
2020-04-12 21:09:03 +00:00
|
|
|
return error_guard (ncdirect_cursor_left (direct, num), -1);
|
2020-04-11 22:20:11 +00:00
|
|
|
}
|
|
|
|
|
2020-04-12 21:09:03 +00:00
|
|
|
bool cursor_right (int num) const NOEXCEPT_MAYBE
|
2020-04-11 22:20:11 +00:00
|
|
|
{
|
2020-04-12 21:09:03 +00:00
|
|
|
return error_guard (ncdirect_cursor_right (direct, num), -1);
|
2020-04-11 22:20:11 +00:00
|
|
|
}
|
|
|
|
|
2020-04-12 21:09:03 +00:00
|
|
|
bool cursor_down (int num) const NOEXCEPT_MAYBE
|
2020-04-11 22:20:11 +00:00
|
|
|
{
|
2020-04-12 21:09:03 +00:00
|
|
|
return error_guard (ncdirect_cursor_down (direct, num), -1);
|
2020-04-11 22:20:11 +00:00
|
|
|
}
|
|
|
|
|
2020-04-12 21:09:03 +00:00
|
|
|
bool cursor_enable () const NOEXCEPT_MAYBE
|
2020-03-14 23:35:54 +00:00
|
|
|
{
|
2020-04-12 21:09:03 +00:00
|
|
|
return error_guard (ncdirect_cursor_enable (direct), -1);
|
2020-03-14 23:35:54 +00:00
|
|
|
}
|
|
|
|
|
2020-04-12 21:09:03 +00:00
|
|
|
bool cursor_disable () const NOEXCEPT_MAYBE
|
2020-03-14 23:35:54 +00:00
|
|
|
{
|
2020-04-12 21:09:03 +00:00
|
|
|
return error_guard (ncdirect_cursor_disable (direct), -1);
|
2020-03-14 23:35:54 +00:00
|
|
|
}
|
2020-02-24 21:56:51 +00:00
|
|
|
|
2020-08-24 05:23:35 +00:00
|
|
|
int render_image (const char* file, ncalign_e align, ncblitter_e blitter, ncscale_e scale) const noexcept
|
2020-06-22 19:49:13 +00:00
|
|
|
{
|
2020-07-03 23:38:53 +00:00
|
|
|
return ncdirect_render_image (direct, file, align, blitter, scale);
|
2020-06-22 19:49:13 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 20:29:51 +00:00
|
|
|
ncdirectv* prep_image (const char* file, ncblitter_e blitter, ncscale_e scale) const noexcept
|
2020-12-18 20:28:24 +00:00
|
|
|
{
|
|
|
|
return ncdirect_render_frame (direct, file, blitter, scale);
|
|
|
|
}
|
|
|
|
|
2020-12-28 07:41:22 +00:00
|
|
|
int raster_image (ncdirectv* faken, ncalign_e align) const noexcept
|
2020-12-18 20:28:24 +00:00
|
|
|
{
|
2020-12-28 07:41:22 +00:00
|
|
|
return ncdirect_raster_frame (direct, faken, align);
|
2020-12-18 20:28:24 +00:00
|
|
|
}
|
|
|
|
|
2020-07-31 20:59:59 +00:00
|
|
|
bool putstr (uint64_t channels, const char* utf8) const NOEXCEPT_MAYBE
|
|
|
|
{
|
|
|
|
return error_guard (ncdirect_putstr (direct, channels, utf8), -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: ncdirect_printf_aligned (will need a version which takes vargs)
|
|
|
|
|
|
|
|
int hline_interp (const char* egc, int len, uint64_t h1, uint64_t h2) const noexcept
|
|
|
|
{
|
|
|
|
return ncdirect_hline_interp (direct, egc, len, h1, h2);
|
|
|
|
}
|
|
|
|
|
|
|
|
int vline_interp (const char* egc, int len, uint64_t h1, uint64_t h2) const noexcept
|
|
|
|
{
|
|
|
|
return ncdirect_vline_interp (direct, egc, len, h1, h2);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool box (uint64_t ul, uint64_t ur, uint64_t ll, uint64_t lr, const wchar_t* wchars, int ylen, int xlen, unsigned ctlword) const NOEXCEPT_MAYBE
|
|
|
|
{
|
|
|
|
return error_guard (ncdirect_box (direct, ul, ur, ll, lr, wchars, ylen, xlen, ctlword), -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool rounded_box (uint64_t ul, uint64_t ur, uint64_t ll, uint64_t lr, int ylen, int xlen, unsigned ctlword) const NOEXCEPT_MAYBE
|
|
|
|
{
|
|
|
|
return error_guard (ncdirect_rounded_box (direct, ul, ur, ll, lr, ylen, xlen, ctlword), -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool double_box (uint64_t ul, uint64_t ur, uint64_t ll, uint64_t lr, int ylen, int xlen, unsigned ctlword) const NOEXCEPT_MAYBE
|
|
|
|
{
|
|
|
|
return error_guard (ncdirect_double_box (direct, ul, ur, ll, lr, ylen, xlen, ctlword), -1);
|
|
|
|
}
|
|
|
|
|
2020-09-23 20:48:43 +00:00
|
|
|
bool flush () const NOEXCEPT_MAYBE
|
|
|
|
{
|
|
|
|
return error_guard (ncdirect_flush (direct), -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
char32_t getc (ncinput *ni, bool blocking) const noexcept
|
|
|
|
{
|
|
|
|
if (blocking)
|
|
|
|
return ncdirect_getc_blocking (direct, ni);
|
|
|
|
return ncdirect_getc_nblock (direct, ni);
|
|
|
|
}
|
|
|
|
|
|
|
|
char32_t getc (const struct timespec *ts, sigset_t *sigmask, ncinput *ni) const noexcept
|
|
|
|
{
|
|
|
|
return ncdirect_getc (direct, ts, sigmask, ni);
|
|
|
|
}
|
|
|
|
|
|
|
|
int get_inputready_fd () const noexcept
|
|
|
|
{
|
|
|
|
return ncdirect_inputready_fd (direct);
|
|
|
|
}
|
|
|
|
|
2020-07-31 20:59:59 +00:00
|
|
|
bool canopen_images () const noexcept
|
|
|
|
{
|
|
|
|
return ncdirect_canopen_images (direct);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool canutf8 () const noexcept
|
|
|
|
{
|
|
|
|
return ncdirect_canutf8 (direct);
|
|
|
|
}
|
|
|
|
|
2020-02-15 22:04:39 +00:00
|
|
|
private:
|
|
|
|
ncdirect *direct;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|