mirror of
https://git.shylie.info/shylie/terml.git
synced 2024-11-23 08:30:11 +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
|
||||
);
|
||||
|
||||
struct tcell
|
||||
typedef struct
|
||||
{
|
||||
unsigned int codepoint;
|
||||
int foreground;
|
||||
int background;
|
||||
};
|
||||
} tcell;
|
||||
|
||||
int terml_init();
|
||||
int terml_deinit();
|
||||
@ -27,8 +27,8 @@ int terml_deinit();
|
||||
unsigned int terml_get_width();
|
||||
unsigned int terml_get_height();
|
||||
|
||||
int terml_get(unsigned int x, unsigned int y, tcell* cell);
|
||||
int terml_set(unsigned int x, unsigned int y, tcell cell);
|
||||
tcell terml_get(unsigned int x, unsigned int y);
|
||||
void terml_set(unsigned int x, unsigned int y, tcell cell);
|
||||
void terml_flush();
|
||||
|
||||
void terml_set_main_callback(terml_main_callback);
|
||||
|
@ -118,7 +118,7 @@ terml::~terml()
|
||||
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;
|
||||
}
|
||||
@ -295,8 +295,11 @@ void terml::reset_console_settings()
|
||||
reset_console_settings_impl();
|
||||
}
|
||||
|
||||
static terml* TERML_G;
|
||||
static const char* LAST_ERROR = nullptr;
|
||||
namespace
|
||||
{
|
||||
terml* TERML_G;
|
||||
const char* LAST_ERROR = nullptr;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
@ -358,36 +361,28 @@ extern "C"
|
||||
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())
|
||||
{
|
||||
LAST_ERROR = "Coordinates out of bounds.";
|
||||
return 1;
|
||||
}
|
||||
else if (!cell)
|
||||
{
|
||||
LAST_ERROR = "Null output pointer.";
|
||||
return 1;
|
||||
return { 0, 0, 0 };
|
||||
}
|
||||
else
|
||||
{
|
||||
*cell = TERML_G->get(x, y);
|
||||
return 0;
|
||||
return TERML_G->get(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
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())
|
||||
{
|
||||
LAST_ERROR = "Coordinates out of bounds.";
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
TERML_G->set(x, y, cell);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ public:
|
||||
terml& operator=(const 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 flush() const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user