diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-11-07 08:24:55 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-11-07 08:24:55 +0100 |
commit | 16b0ce3748f1b3ea788bbaf4caaeb342a8f58d6f (patch) | |
tree | 32f0b62f1b4c21d8f7c38bbcda9658e468a28113 | |
parent | b3b9e8c2b8068ce2566a9be2a813b2f04088f3ce (diff) |
Use char array for text entered str, reset text fields on deinit
-rw-r--r-- | include/mgl/window/event.h | 2 | ||||
-rw-r--r-- | src/graphics/text.c | 6 | ||||
-rw-r--r-- | src/window/window.c | 6 | ||||
-rw-r--r-- | tests/main.c | 1 |
4 files changed, 10 insertions, 5 deletions
diff --git a/include/mgl/window/event.h b/include/mgl/window/event.h index 4a3ba71..a47568b 100644 --- a/include/mgl/window/event.h +++ b/include/mgl/window/event.h @@ -15,7 +15,7 @@ typedef struct { typedef struct { uint32_t codepoint; int size; - unsigned char str[5]; /* utf8, null terminated */ + char str[5]; /* utf8, null terminated */ } mgl_text_event; typedef struct { diff --git a/src/graphics/text.c b/src/graphics/text.c index 9804ab2..2f410d4 100644 --- a/src/graphics/text.c +++ b/src/graphics/text.c @@ -52,7 +52,11 @@ int mgl_text_init(mgl_text *self, mgl_font *font, const char *str, size_t str_si } void mgl_text_deinit(mgl_text *self) { - (void)self; + self->font = NULL; + self->position = (mgl_vec2f){ 0.0f, 0.0f }; + self->text = NULL; + self->text_size = 0; + self->bounds = (mgl_vec2f){ 0.0f, 0.0f }; } int mgl_text_set_string(mgl_text *self, const char *str, size_t str_size) { diff --git a/src/window/window.c b/src/window/window.c index b53c4a1..05cd5f5 100644 --- a/src/window/window.c +++ b/src/window/window.c @@ -8,6 +8,8 @@ #include <errno.h> #include <stdio.h> +/* TODO: Handle XIM better. Set XIM position to text position on screen (for text input) and reset input when selecting a new text input, etc */ + /* Should be in range [2,] */ #define MAX_STACKED_EVENTS 32 @@ -353,7 +355,7 @@ static void mgl_window_handle_text_event(mgl_window *self, XEvent *xev) { text_event.type = MGL_EVENT_TEXT_ENTERED; text_event.text.codepoint = codepoint; text_event.text.size = clen; - memcpy(text_event.text.str, (const unsigned char*)&buf[i], clen); + memcpy(text_event.text.str, &buf[i], clen); text_event.text.str[clen] = '\0'; if(!x11_context_append_event(x11_context, &text_event)) break; @@ -367,14 +369,12 @@ static void mgl_window_on_receive_event(mgl_window *self, XEvent *xev, mgl_event /* TODO: Handle wm_delete_window event */ switch(xev->type) { case KeyPress: { - /* TODO: Fill with correct data */ event->type = MGL_EVENT_KEY_PRESSED; mgl_window_handle_key_event(self, &xev->xkey, event, context); mgl_window_handle_text_event(self, xev); return; } case KeyRelease: { - /* TODO: Fill with correct data */ event->type = MGL_EVENT_KEY_RELEASED; mgl_window_handle_key_event(self, &xev->xkey, event, context); return; diff --git a/tests/main.c b/tests/main.c index 2359cda..ad6113c 100644 --- a/tests/main.c +++ b/tests/main.c @@ -240,6 +240,7 @@ int main(int argc, char **argv) { mgl_vertex_buffer_deinit(&vertex_buffer2); mgl_vertex_buffer_deinit(&vertex_buffer1); mgl_shader_program_deinit(&shader_program); + mgl_font_unload(&cjk_font); mgl_font_unload(&font); mgl_texture_unload(&texture); mgl_window_deinit(&window); |