2020-02-15 23:04:39 +01:00
|
|
|
#ifndef __NCPP_DIRECT_HH
|
|
|
|
#define __NCPP_DIRECT_HH
|
|
|
|
|
|
|
|
#include <cstdio>
|
2020-07-10 15:51:28 -04:00
|
|
|
#include <notcurses/direct.h>
|
2020-02-18 12:36:16 -05:00
|
|
|
#include <notcurses/notcurses.h>
|
2020-02-15 23:04:39 +01:00
|
|
|
|
|
|
|
#include "Root.hh"
|
|
|
|
#include "Cell.hh"
|
|
|
|
|
|
|
|
namespace ncpp
|
|
|
|
{
|
2020-05-24 14:41:18 +02:00
|
|
|
class NotCurses;
|
|
|
|
|
2020-02-15 23:04:39 +01:00
|
|
|
class NCPP_API_EXPORT Direct : public Root
|
|
|
|
{
|
|
|
|
public:
|
2020-05-24 14:41:18 +02:00
|
|
|
explicit Direct (const char *termtype = nullptr, FILE *fp = nullptr, NotCurses *ncinst = nullptr)
|
|
|
|
: Root (ncinst)
|
2020-02-15 23:04:39 +01:00
|
|
|
{
|
2020-03-02 20:19:16 -05:00
|
|
|
direct = ncdirect_init (termtype, fp == nullptr ? stdout : fp);
|
2020-02-15 23:04:39 +01:00
|
|
|
if (direct == nullptr)
|
2020-05-20 00:15:38 -04:00
|
|
|
throw init_error ("Notcurses failed to initialize direct mode");
|
2020-02-15 23:04:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
~Direct ()
|
|
|
|
{
|
|
|
|
ncdirect_stop (direct);
|
|
|
|
}
|
|
|
|
|
2020-04-12 23:09:03 +02:00
|
|
|
bool clear () const NOEXCEPT_MAYBE
|
2020-02-15 23:04:39 +01:00
|
|
|
{
|
2020-04-12 23:09:03 +02:00
|
|
|
return error_guard (ncdirect_clear (direct), -1);
|
2020-02-15 23:04:39 +01:00
|
|
|
}
|
|
|
|
|
2020-04-12 23:09:03 +02:00
|
|
|
bool set_fg_default () const NOEXCEPT_MAYBE
|
2020-02-15 23:04:39 +01:00
|
|
|
{
|
2020-04-12 23:09:03 +02:00
|
|
|
return error_guard (ncdirect_fg_default (direct), -1);
|
2020-02-15 23:04:39 +01:00
|
|
|
}
|
|
|
|
|
2020-04-12 23:09:03 +02:00
|
|
|
bool set_fg (unsigned rgb) const NOEXCEPT_MAYBE
|
2020-02-15 23:04:39 +01:00
|
|
|
{
|
2020-04-12 23:09:03 +02:00
|
|
|
return error_guard (ncdirect_fg (direct, rgb), -1);
|
2020-02-15 23:04:39 +01:00
|
|
|
}
|
|
|
|
|
2020-04-12 23:09:03 +02:00
|
|
|
bool set_fg (unsigned r, unsigned g, unsigned b) const NOEXCEPT_MAYBE
|
2020-02-15 23:04:39 +01:00
|
|
|
{
|
2020-07-01 01:14:42 -04:00
|
|
|
return error_guard (ncdirect_fg_rgb (direct, r, g, b), -1);
|
2020-02-15 23:04:39 +01:00
|
|
|
}
|
|
|
|
|
2020-04-12 23:09:03 +02:00
|
|
|
bool set_bg_default () const NOEXCEPT_MAYBE
|
2020-02-15 23:04:39 +01:00
|
|
|
{
|
2020-04-12 23:09:03 +02:00
|
|
|
return error_guard (ncdirect_bg_default (direct), -1);
|
2020-02-15 23:04:39 +01:00
|
|
|
}
|
|
|
|
|
2020-04-12 23:09:03 +02:00
|
|
|
bool set_bg (unsigned rgb) const NOEXCEPT_MAYBE
|
2020-02-15 23:04:39 +01:00
|
|
|
{
|
2020-04-12 23:09:03 +02:00
|
|
|
return error_guard (ncdirect_bg (direct, rgb), -1);
|
2020-02-15 23:04:39 +01:00
|
|
|
}
|
|
|
|
|
2020-04-12 23:09:03 +02:00
|
|
|
bool set_bg (unsigned r, unsigned g, unsigned b) const NOEXCEPT_MAYBE
|
2020-02-15 23:04:39 +01:00
|
|
|
{
|
2020-07-01 01:14:42 -04:00
|
|
|
return error_guard (ncdirect_bg_rgb (direct, r, g, b), -1);
|
2020-02-15 23:04:39 +01:00
|
|
|
}
|
|
|
|
|
2020-04-12 23:09:03 +02:00
|
|
|
int get_dim_x () const NOEXCEPT_MAYBE
|
2020-02-15 23:04:39 +01:00
|
|
|
{
|
2020-04-12 23:09:03 +02:00
|
|
|
return error_guard (ncdirect_dim_x (direct), -1);
|
2020-02-15 23:04:39 +01:00
|
|
|
}
|
|
|
|
|
2020-04-12 23:09:03 +02:00
|
|
|
int get_dim_y () const NOEXCEPT_MAYBE
|
2020-02-15 23:04:39 +01:00
|
|
|
{
|
2020-04-12 23:09:03 +02:00
|
|
|
return error_guard (ncdirect_dim_y (direct), -1);
|
2020-02-15 23:04:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2020-04-12 23:09:03 +02:00
|
|
|
bool cursor_move_yx (int y, int x) const NOEXCEPT_MAYBE
|
2020-03-15 00:35:54 +01:00
|
|
|
{
|
2020-04-12 23:09:03 +02:00
|
|
|
return error_guard (ncdirect_cursor_move_yx (direct, y, x), -1);
|
2020-03-15 00:35:54 +01:00
|
|
|
}
|
|
|
|
|
2020-04-12 23:09:03 +02:00
|
|
|
bool cursor_up (int num) const NOEXCEPT_MAYBE
|
2020-04-12 00:20:11 +02:00
|
|
|
{
|
2020-04-12 23:09:03 +02:00
|
|
|
return error_guard (ncdirect_cursor_up (direct, num), -1);
|
2020-04-12 00:20:11 +02:00
|
|
|
}
|
|
|
|
|
2020-04-12 23:09:03 +02:00
|
|
|
bool cursor_left (int num) const NOEXCEPT_MAYBE
|
2020-04-12 00:20:11 +02:00
|
|
|
{
|
2020-04-12 23:09:03 +02:00
|
|
|
return error_guard (ncdirect_cursor_left (direct, num), -1);
|
2020-04-12 00:20:11 +02:00
|
|
|
}
|
|
|
|
|
2020-04-12 23:09:03 +02:00
|
|
|
bool cursor_right (int num) const NOEXCEPT_MAYBE
|
2020-04-12 00:20:11 +02:00
|
|
|
{
|
2020-04-12 23:09:03 +02:00
|
|
|
return error_guard (ncdirect_cursor_right (direct, num), -1);
|
2020-04-12 00:20:11 +02:00
|
|
|
}
|
|
|
|
|
2020-04-12 23:09:03 +02:00
|
|
|
bool cursor_down (int num) const NOEXCEPT_MAYBE
|
2020-04-12 00:20:11 +02:00
|
|
|
{
|
2020-04-12 23:09:03 +02:00
|
|
|
return error_guard (ncdirect_cursor_down (direct, num), -1);
|
2020-04-12 00:20:11 +02:00
|
|
|
}
|
|
|
|
|
2020-04-12 23:09:03 +02:00
|
|
|
bool cursor_enable () const NOEXCEPT_MAYBE
|
2020-03-15 00:35:54 +01:00
|
|
|
{
|
2020-04-12 23:09:03 +02:00
|
|
|
return error_guard (ncdirect_cursor_enable (direct), -1);
|
2020-03-15 00:35:54 +01:00
|
|
|
}
|
|
|
|
|
2020-04-12 23:09:03 +02:00
|
|
|
bool cursor_disable () const NOEXCEPT_MAYBE
|
2020-03-15 00:35:54 +01:00
|
|
|
{
|
2020-04-12 23:09:03 +02:00
|
|
|
return error_guard (ncdirect_cursor_disable (direct), -1);
|
2020-03-15 00:35:54 +01:00
|
|
|
}
|
2020-02-24 16:56:51 -05:00
|
|
|
|
2020-07-03 19:38:53 -04:00
|
|
|
nc_err_e render_image (const char* file, ncalign_e align, ncblitter_e blitter, ncscale_e scale) const noexcept
|
2020-06-22 21:49:13 +02:00
|
|
|
{
|
2020-07-03 19:38:53 -04:00
|
|
|
return ncdirect_render_image (direct, file, align, blitter, scale);
|
2020-06-22 21:49:13 +02:00
|
|
|
}
|
|
|
|
|
2020-02-15 23:04:39 +01:00
|
|
|
private:
|
|
|
|
ncdirect *direct;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|