mirror of
https://git.shylie.info/shylie/terml.git
synced 2024-12-22 14:40:04 +00:00
Refactor terml_get and terml_set
This commit is contained in:
parent
98097d7540
commit
1712c1b1e8
@ -14,12 +14,12 @@ typedef void (*terml_resize_callback)(
|
|||||||
unsigned int previous_height
|
unsigned int previous_height
|
||||||
);
|
);
|
||||||
|
|
||||||
struct tcell
|
typedef struct
|
||||||
{
|
{
|
||||||
unsigned int codepoint;
|
unsigned int codepoint;
|
||||||
int foreground;
|
int foreground;
|
||||||
int background;
|
int background;
|
||||||
};
|
} tcell;
|
||||||
|
|
||||||
int terml_init();
|
int terml_init();
|
||||||
int terml_deinit();
|
int terml_deinit();
|
||||||
@ -27,9 +27,9 @@ int terml_deinit();
|
|||||||
unsigned int terml_get_width();
|
unsigned int terml_get_width();
|
||||||
unsigned int terml_get_height();
|
unsigned int terml_get_height();
|
||||||
|
|
||||||
int terml_get(unsigned int x, unsigned int y, tcell* cell);
|
tcell terml_get(unsigned int x, unsigned int y);
|
||||||
int terml_set(unsigned int x, unsigned int y, tcell cell);
|
void terml_set(unsigned int x, unsigned int y, tcell cell);
|
||||||
void terml_flush();
|
void terml_flush();
|
||||||
|
|
||||||
void terml_set_main_callback(terml_main_callback);
|
void terml_set_main_callback(terml_main_callback);
|
||||||
void terml_set_quit_callback(terml_quit_callback);
|
void terml_set_quit_callback(terml_quit_callback);
|
||||||
|
@ -118,7 +118,7 @@ terml::~terml()
|
|||||||
if (cells) { delete[] cells; }
|
if (cells) { delete[] cells; }
|
||||||
}
|
}
|
||||||
|
|
||||||
const tcell& terml::get(unsigned int x, unsigned int y) const
|
tcell terml::get(unsigned int x, unsigned int y) const
|
||||||
{
|
{
|
||||||
return cells[x + y * width].cell;
|
return cells[x + y * width].cell;
|
||||||
}
|
}
|
||||||
@ -295,8 +295,11 @@ void terml::reset_console_settings()
|
|||||||
reset_console_settings_impl();
|
reset_console_settings_impl();
|
||||||
}
|
}
|
||||||
|
|
||||||
static terml* TERML_G;
|
namespace
|
||||||
static const char* LAST_ERROR = nullptr;
|
{
|
||||||
|
terml* TERML_G;
|
||||||
|
const char* LAST_ERROR = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
@ -358,36 +361,28 @@ extern "C"
|
|||||||
return TERML_G->get_height();
|
return TERML_G->get_height();
|
||||||
}
|
}
|
||||||
|
|
||||||
int terml_get(unsigned int x, unsigned int y, tcell* cell)
|
tcell terml_get(unsigned int x, unsigned int y)
|
||||||
{
|
{
|
||||||
if (x >= TERML_G->get_width() || y >= TERML_G->get_height())
|
if (x >= TERML_G->get_width() || y >= TERML_G->get_height())
|
||||||
{
|
{
|
||||||
LAST_ERROR = "Coordinates out of bounds.";
|
LAST_ERROR = "Coordinates out of bounds.";
|
||||||
return 1;
|
return { 0, 0, 0 };
|
||||||
}
|
|
||||||
else if (!cell)
|
|
||||||
{
|
|
||||||
LAST_ERROR = "Null output pointer.";
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*cell = TERML_G->get(x, y);
|
return TERML_G->get(x, y);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int terml_set(unsigned int x, unsigned int y, tcell cell)
|
void terml_set(unsigned int x, unsigned int y, tcell cell)
|
||||||
{
|
{
|
||||||
if (x >= TERML_G->get_width() || y >= TERML_G->get_height())
|
if (x >= TERML_G->get_width() || y >= TERML_G->get_height())
|
||||||
{
|
{
|
||||||
LAST_ERROR = "Coordinates out of bounds.";
|
LAST_ERROR = "Coordinates out of bounds.";
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TERML_G->set(x, y, cell);
|
TERML_G->set(x, y, cell);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,9 +44,9 @@ public:
|
|||||||
terml& operator=(const terml&) = delete;
|
terml& operator=(const terml&) = delete;
|
||||||
terml& operator=(terml&&) = delete;
|
terml& operator=(terml&&) = delete;
|
||||||
|
|
||||||
const tcell& get(unsigned int x, unsigned int y) const;
|
tcell get(unsigned int x, unsigned int y) const;
|
||||||
void set(unsigned int x, unsigned int y, tcell cell);
|
void set(unsigned int x, unsigned int y, tcell cell);
|
||||||
void flush() const;
|
void flush() const;
|
||||||
|
|
||||||
void set_main_callback(terml_main_callback);
|
void set_main_callback(terml_main_callback);
|
||||||
void set_quit_callback(terml_quit_callback);
|
void set_quit_callback(terml_quit_callback);
|
||||||
|
Loading…
Reference in New Issue
Block a user