From e3c90b41386986ef53e512994d6e2f7ceadfc177 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 8 Nov 2021 02:07:23 +0100 Subject: Add window function to get key state, allow invalid utf8 --- include/mgl/graphics/text.h | 1 - include/mgl/system/utf8.h | 8 +------- include/mgl/window/key.h | 5 ++++- include/mgl/window/window.h | 2 ++ 4 files changed, 7 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/include/mgl/graphics/text.h b/include/mgl/graphics/text.h index aca0650..2311d23 100644 --- a/include/mgl/graphics/text.h +++ b/include/mgl/graphics/text.h @@ -34,7 +34,6 @@ void mgl_text_deinit(mgl_text *self); /* Note: keeps a reference to |text|. |text| needs to be valid as long as |self| is used. |text| may be NULL. - |str| will be checked if its a valid utf8 string. */ int mgl_text_set_string(mgl_text *self, const char *str, size_t str_size); /* |font| may be NULL */ diff --git a/include/mgl/system/utf8.h b/include/mgl/system/utf8.h index 663e7e3..f745be7 100644 --- a/include/mgl/system/utf8.h +++ b/include/mgl/system/utf8.h @@ -5,13 +5,7 @@ #include #include -bool mgl_utf8_is_valid(const unsigned char *str, size_t size); - -/* - Returns the byte length of the decoded codepoint. - Note: does not validate if the input |str| is a valid utf8 string. -*/ -size_t mgl_utf8_decode(const unsigned char *str, uint32_t *decoded_codepoint); +bool mgl_utf8_decode(const unsigned char *str, size_t size, uint32_t *decoded_codepoint, size_t *codepoint_length); #endif /* MGL_UTF8_H */ diff --git a/include/mgl/window/key.h b/include/mgl/window/key.h index 90a3366..0cd3c03 100644 --- a/include/mgl/window/key.h +++ b/include/mgl/window/key.h @@ -103,7 +103,10 @@ typedef enum { MGL_KEY_F13, MGL_KEY_F14, MGL_KEY_F15, - MGL_KEY_PAUSE + MGL_KEY_PAUSE, + + /* This should always be the last key */ + __MGL_NUM_KEYS__ } mgl_key; #endif /* _MGL_KEY_H_ */ diff --git a/include/mgl/window/window.h b/include/mgl/window/window.h index 9d7086c..c6fce87 100644 --- a/include/mgl/window/window.h +++ b/include/mgl/window/window.h @@ -3,6 +3,7 @@ #include "../graphics/color.h" #include "../system/vec.h" +#include "key.h" #include /* Vsync is automatically set for created windows, if supported by the system */ @@ -48,5 +49,6 @@ void mgl_window_set_view(mgl_window *self, mgl_view *new_view); void mgl_window_get_view(mgl_window *self, mgl_view *view); bool mgl_window_is_open(const mgl_window *self); +bool mgl_window_is_key_pressed(const mgl_window *self, mgl_key key); #endif /* MGL_WINDOW_H */ -- cgit v1.2.3