Change write method to accept both String and PoolByteArray

Will print a warning if neither of these types is used as an argument.
This commit is contained in:
Leroy Hopson 2020-09-25 13:12:31 +07:00
parent ada8b1087d
commit 57aed28a0e
3 changed files with 30 additions and 3 deletions

View file

@ -12,3 +12,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Implementation of Terminal node from GDScript to GDNative using [Aetf's patched version of libtsm](https://github.com/Aetf/libtsm).
- Move input handling to the Terminal node itself, rather than handling it in a seperate Control node.
- The Terminal `write()` method now accepts both String and PoolByteArray.

View file

@ -566,8 +566,34 @@ void Terminal::update_size()
update();
}
void Terminal::write(PoolByteArray data)
void Terminal::write(Variant data)
{
tsm_vte_input(vte, (char *)data.read().ptr(), data.size());
const char *u8;
size_t len;
switch (data.get_type())
{
case Variant::Type::POOL_BYTE_ARRAY:
{
PoolByteArray bytes = data;
u8 = (char *)bytes.read().ptr();
len = bytes.size();
break;
}
case Variant::Type::STRING:
{
String string = data;
CharString utf8 = string.utf8();
u8 = utf8.get_data();
len = utf8.length();
break;
}
default:
WARN_PRINT("Method expected a String or PoolByteArray");
return;
}
tsm_vte_input(vte, u8, len);
framebuffer_age = tsm_screen_draw(screen, text_draw_cb, this);
}

View file

@ -58,7 +58,7 @@ namespace godot
void _gui_input(Variant event);
void _draw();
void write(PoolByteArray bytes);
void write(Variant data);
int rows;
int cols;