diff --git a/include/terml.h b/include/terml.h index 6aab1ae..9775cf4 100644 --- a/include/terml.h +++ b/include/terml.h @@ -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,9 +27,9 @@ 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); -void terml_flush(); +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); void terml_set_quit_callback(terml_quit_callback); diff --git a/source/terml.cpp b/source/terml.cpp index 7e21e19..56f9293 100644 --- a/source/terml.cpp +++ b/source/terml.cpp @@ -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; } } diff --git a/source/terml_private.h b/source/terml_private.h index 6e36df6..2c6d98c 100644 --- a/source/terml_private.h +++ b/source/terml_private.h @@ -44,9 +44,9 @@ public: terml& operator=(const terml&) = delete; terml& operator=(terml&&) = delete; - const tcell& get(unsigned int x, unsigned int y) const; - void set(unsigned int x, unsigned int y, tcell cell); - void flush() const; + tcell get(unsigned int x, unsigned int y) const; + void set(unsigned int x, unsigned int y, tcell cell); + void flush() const; void set_main_callback(terml_main_callback); void set_quit_callback(terml_quit_callback);