aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-11-06 15:55:42 +0100
committerdec05eba <dec05eba@protonmail.com>2021-11-06 15:55:42 +0100
commitcb679636f77fe2a03e8dab3a511e28e1ab898316 (patch)
treeb03cada4a37a50eb50cef1e21c75c56d938868a8 /include
parente2e7c0bf0747d55967c4be6374f3611cd96babb6 (diff)
Fix exit being called when closing window, respond to wm ping, add is_open function to window
Diffstat (limited to 'include')
-rw-r--r--include/mgl/graphics/text.h20
-rw-r--r--include/mgl/mgl.h1
-rw-r--r--include/mgl/system/utf8.h17
-rw-r--r--include/mgl/window/event.h3
-rw-r--r--include/mgl/window/window.h3
5 files changed, 30 insertions, 14 deletions
diff --git a/include/mgl/graphics/text.h b/include/mgl/graphics/text.h
index f832605..aca0650 100644
--- a/include/mgl/graphics/text.h
+++ b/include/mgl/graphics/text.h
@@ -16,33 +16,27 @@ typedef struct mgl_font mgl_font;
typedef struct mgl_context mgl_context;
typedef struct {
- /* Optional */
- void (*before_syntax_highlight)(void *userdata);
- /* Return true if the text format should be changed. Optional */
- bool (*syntax_highlight)(void *userdata, const char *str, size_t size, mgl_color *color);
- void *userdata;
-} mgl_text_options;
-
-typedef struct {
mgl_font *font; /* nullable */
const char *text; /* nullable */
size_t text_size;
mgl_color color;
mgl_vec2f position;
mgl_vec2f bounds;
- mgl_text_options options;
} mgl_text;
/*
Note: keeps a reference to |text|. |text| needs to be valid as long as |self| is used.
|font| and |text| may be NULL.
- |load_options| can be NULL, in which case the default options are used.
*/
-int mgl_text_init(mgl_text *self, mgl_font *font, const char *str, size_t str_size, mgl_text_options *options);
+int mgl_text_init(mgl_text *self, mgl_font *font, const char *str, size_t str_size);
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. */
-void mgl_text_set_string(mgl_text *self, const char *str, size_t str_size);
+/*
+ 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 */
void mgl_text_set_font(mgl_text *self, mgl_font *font);
void mgl_text_set_position(mgl_text *self, mgl_vec2f position);
diff --git a/include/mgl/mgl.h b/include/mgl/mgl.h
index b9d007e..7b02ceb 100644
--- a/include/mgl/mgl.h
+++ b/include/mgl/mgl.h
@@ -12,6 +12,7 @@ struct mgl_context {
mgl_gl gl;
_XVisualInfo *visual_info;
unsigned long wm_delete_window_atom;
+ unsigned long net_wm_ping_atom;
};
/*
diff --git a/include/mgl/system/utf8.h b/include/mgl/system/utf8.h
new file mode 100644
index 0000000..663e7e3
--- /dev/null
+++ b/include/mgl/system/utf8.h
@@ -0,0 +1,17 @@
+#ifndef MGL_UTF8_H
+#define MGL_UTF8_H
+
+#include <stddef.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+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);
+
+#endif /* MGL_UTF8_H */
+
diff --git a/include/mgl/window/event.h b/include/mgl/window/event.h
index 020d5c9..c928d0e 100644
--- a/include/mgl/window/event.h
+++ b/include/mgl/window/event.h
@@ -41,7 +41,8 @@ typedef struct {
typedef enum {
MGL_EVENT_UNKNOWN,
- MGL_EVENT_RESIZED,
+ MGL_EVENT_CLOSED, /* Window closed */
+ MGL_EVENT_RESIZED, /* Window resized */
MGL_EVENT_KEY_PRESSED,
MGL_EVENT_KEY_RELEASED,
MGL_EVENT_MOUSE_BUTTON_PRESSED,
diff --git a/include/mgl/window/window.h b/include/mgl/window/window.h
index ad8e1dd..cb8baf6 100644
--- a/include/mgl/window/window.h
+++ b/include/mgl/window/window.h
@@ -26,6 +26,7 @@ struct mgl_window {
/* relative to the top left of the window. only updates when the cursor is inside the window */
mgl_vec2i cursor_position;
mgl_view view;
+ bool open;
};
int mgl_window_create(mgl_window *self, const char *title, int width, int height);
@@ -47,4 +48,6 @@ void mgl_window_display(mgl_window *self);
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);
+
#endif /* MGL_WINDOW_H */