mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-04 06:00:30 +00:00
b5d8549bb3
This is to make it possible, in the future, to create multiple instances of `NotCurses` for multiple terminals. The first instance of `NotCurses` becomes the default one, so that any instances of other classes that aren't explicitly created with a pointer to another `NotCurses` instance still work as expected. Note that currently trying to call `notcurses_init` twice results in the following error for me: 0x55555559bfc0 is already registered for signals Couldn't drop signals: 0x55555559bfc0 != 0x5555555b6720 terminate called after throwing an instance of 'ncpp::init_error*' Program received signal SIGABRT, Aborted. The error is signalled by `setup_signals` and the pointer shown in the message points to the first `struct notcurses` instance created.
64 lines
1.1 KiB
C++
64 lines
1.1 KiB
C++
#ifndef __NCPP_TABLET_HH
|
|
#define __NCPP_TABLET_HH
|
|
|
|
#include <map>
|
|
#include <mutex>
|
|
|
|
#include <notcurses/notcurses.h>
|
|
|
|
#include "Root.hh"
|
|
|
|
namespace ncpp
|
|
{
|
|
class Plane;
|
|
class NotCurses;
|
|
|
|
class NCPP_API_EXPORT NcTablet : public Root
|
|
{
|
|
protected:
|
|
explicit NcTablet (nctablet *t, NotCurses *ncinst)
|
|
: Root (ncinst),
|
|
_tablet (t)
|
|
{
|
|
if (t == nullptr)
|
|
throw invalid_argument ("'t' must be a valid pointer");
|
|
};
|
|
|
|
public:
|
|
template<typename T>
|
|
T* get_userptr () const noexcept
|
|
{
|
|
return static_cast<T*>(nctablet_userptr (_tablet));
|
|
}
|
|
|
|
operator nctablet* () const noexcept
|
|
{
|
|
return _tablet;
|
|
}
|
|
|
|
operator nctablet const* () const noexcept
|
|
{
|
|
return _tablet;
|
|
}
|
|
|
|
Plane* get_plane () const noexcept;
|
|
static NcTablet* map_tablet (nctablet *t, NotCurses *ncinst = nullptr) noexcept;
|
|
|
|
protected:
|
|
static void unmap_tablet (NcTablet *p) noexcept;
|
|
|
|
nctablet* get_tablet () const noexcept
|
|
{
|
|
return _tablet;
|
|
}
|
|
|
|
private:
|
|
nctablet *_tablet = nullptr;
|
|
static std::map<nctablet*,NcTablet*> *tablet_map;
|
|
static std::mutex tablet_map_mutex;
|
|
|
|
friend class NcReel;
|
|
};
|
|
}
|
|
#endif
|