notcurses/include/ncpp/Direct.hh
Marek Habersack 2fabe85e6a [C++] API sync
Been a while, apologies :)

Added:
  * Direct: fg_palindex (`ncdirect_fg_palindex`)
  * Direct: bg_palindex (`ncdirect_bg_palindex`)
  * Direct: get_palette_size (`ncdirect_palette_size`)
  * Direct: putstr (`ncdirect_putstr`)
  * Direct: hline_interp (`ncdirect_hline_interp`)
  * Direct: vline_interp (`ncdirect_vline_interp`)
  * Direct: box (`ncdirect_box`)
  * Direct: rounded_box (`ncdirect_rounded_box`)
  * Direct: double_box (`ncdirect_double_box`)
  * Direct: canopen_images (`ncdirect_canopen_images`)
  * Direct: canutf8 (`ncdirect_canutf8`)
  * Menu: get_mouse_selected (`ncmenu_mouse_selected`)
  * NotCurses: version_components (`notcurses_version_components`)
  * NotCurses: str_blitter (`notcurses_str_blitter`)
  * NotCurses: str_scalemode (`notcurses_str_scalemode`)
  * NotCurses: lex_margins (`notcurses_lex_margins`)
  * NotCurses: lex_blitter (`notcurses_lex_blitter`)
  * NotCurses: lex_scalemode (`notcurses_lex_scalemode`)
  * NotCurses: render_to_file (`notcurses_render_to_file`)
  * Plane: putstr_stainable (`ncplane_putstr_stainable`)
  * Plane: printf_stainable (`ncplane_printf_stainable`)
  * Plane: vprintf_stainable (`ncplane_vprintf_stainable`)
  * Reel: offer_input (`ncreel_offer_input`)

Changed:
  * Direct: set_fg_alpha uses `unsigned alpha`
  * Direct: set_bg_alpha uses `unsigned alpha`
  * Plane: set_fg_alpha uses `unsigned alpha`
  * Plane: set_bg_alpha uses `unsigned alpha`
  * Root: made `error_guard` and `error_guard_cond` static
2020-08-01 00:27:20 -04:00

193 lines
4.8 KiB
C++

#ifndef __NCPP_DIRECT_HH
#define __NCPP_DIRECT_HH
#include <cstdio>
#include <notcurses/direct.h>
#include <notcurses/notcurses.h>
#include "Root.hh"
#include "Cell.hh"
namespace ncpp
{
class NotCurses;
class NCPP_API_EXPORT Direct : public Root
{
public:
explicit Direct (const char *termtype = nullptr, FILE *fp = nullptr, NotCurses *ncinst = nullptr)
: Root (ncinst)
{
direct = ncdirect_init (termtype, fp == nullptr ? stdout : fp);
if (direct == nullptr)
throw init_error ("Notcurses failed to initialize direct mode");
}
~Direct ()
{
ncdirect_stop (direct);
}
bool clear () const NOEXCEPT_MAYBE
{
return error_guard (ncdirect_clear (direct), -1);
}
bool set_fg_default () const NOEXCEPT_MAYBE
{
return error_guard (ncdirect_fg_default (direct), -1);
}
bool set_fg (unsigned rgb) const NOEXCEPT_MAYBE
{
return error_guard (ncdirect_fg (direct, rgb), -1);
}
bool set_fg (unsigned r, unsigned g, unsigned b) const NOEXCEPT_MAYBE
{
return error_guard (ncdirect_fg_rgb (direct, r, g, b), -1);
}
bool fg_palindex (int pidx) const NOEXCEPT_MAYBE
{
return error_guard (ncdirect_fg_palindex (direct, pidx), -1);
}
bool set_bg_default () const NOEXCEPT_MAYBE
{
return error_guard (ncdirect_bg_default (direct), -1);
}
bool set_bg (unsigned rgb) const NOEXCEPT_MAYBE
{
return error_guard (ncdirect_bg (direct, rgb), -1);
}
bool set_bg (unsigned r, unsigned g, unsigned b) const NOEXCEPT_MAYBE
{
return error_guard (ncdirect_bg_rgb (direct, r, g, b), -1);
}
bool bg_palindex (int pidx) const NOEXCEPT_MAYBE
{
return error_guard (ncdirect_bg_palindex (direct, pidx), -1);
}
int get_dim_x () const NOEXCEPT_MAYBE
{
return error_guard (ncdirect_dim_x (direct), -1);
}
int get_dim_y () const NOEXCEPT_MAYBE
{
return error_guard (ncdirect_dim_y (direct), -1);
}
int get_palette_size () const noexcept
{
return ncdirect_palette_size (direct);
}
void styles_set (CellStyle stylebits) const noexcept
{
ncdirect_styles_set (direct, static_cast<unsigned>(stylebits));
}
void styles_on (CellStyle stylebits) const noexcept
{
ncdirect_styles_on (direct, static_cast<unsigned>(stylebits));
}
void styles_off (CellStyle stylebits) const noexcept
{
ncdirect_styles_off (direct, static_cast<unsigned>(stylebits));
}
bool cursor_move_yx (int y, int x) const NOEXCEPT_MAYBE
{
return error_guard (ncdirect_cursor_move_yx (direct, y, x), -1);
}
bool cursor_up (int num) const NOEXCEPT_MAYBE
{
return error_guard (ncdirect_cursor_up (direct, num), -1);
}
bool cursor_left (int num) const NOEXCEPT_MAYBE
{
return error_guard (ncdirect_cursor_left (direct, num), -1);
}
bool cursor_right (int num) const NOEXCEPT_MAYBE
{
return error_guard (ncdirect_cursor_right (direct, num), -1);
}
bool cursor_down (int num) const NOEXCEPT_MAYBE
{
return error_guard (ncdirect_cursor_down (direct, num), -1);
}
bool cursor_enable () const NOEXCEPT_MAYBE
{
return error_guard (ncdirect_cursor_enable (direct), -1);
}
bool cursor_disable () const NOEXCEPT_MAYBE
{
return error_guard (ncdirect_cursor_disable (direct), -1);
}
nc_err_e render_image (const char* file, ncalign_e align, ncblitter_e blitter, ncscale_e scale) const noexcept
{
return ncdirect_render_image (direct, file, align, blitter, scale);
}
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);
}
bool canopen_images () const noexcept
{
return ncdirect_canopen_images (direct);
}
bool canutf8 () const noexcept
{
return ncdirect_canutf8 (direct);
}
private:
ncdirect *direct;
};
}
#endif