aboutsummaryrefslogtreecommitdiff
path: root/include/mgl/window
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-10-31 12:50:05 +0100
committerdec05eba <dec05eba@protonmail.com>2021-11-02 02:23:54 +0100
commit111f0ba3f4a4f14d39c8e3f7c00f13e852f47a51 (patch)
treefc7317e332c7a56df7738a62110ad76d4fc8511c /include/mgl/window
parent8a316a12481282cb2ab966c4cbc770656c258383 (diff)
Start on syntax highlighting, output correct key button event
Diffstat (limited to 'include/mgl/window')
-rw-r--r--include/mgl/window/event.h54
-rw-r--r--include/mgl/window/key.h109
-rw-r--r--include/mgl/window/window.h3
3 files changed, 165 insertions, 1 deletions
diff --git a/include/mgl/window/event.h b/include/mgl/window/event.h
index 2aea478..020d5c9 100644
--- a/include/mgl/window/event.h
+++ b/include/mgl/window/event.h
@@ -1,10 +1,62 @@
#ifndef MGL_EVENT_H
#define MGL_EVENT_H
+#include "key.h"
+#include <stdbool.h>
+
typedef struct mgl_event mgl_event;
+typedef struct {
+ int width;
+ int height;
+} mgl_size_event;
+
+typedef struct {
+ int code; /* mgl_key */
+ bool alt;
+ bool control;
+ bool shift;
+ bool system;
+} mgl_key_event;
+
+typedef struct {
+ int x; /* relative to left of the window */
+ int y; /* relative to the top of the window */
+} mgl_mouse_move_event;
+
+typedef enum {
+ MGL_BUTTON_UNKNOWN,
+ MGL_BUTTON_LEFT,
+ MGL_BUTTON_RIGHT,
+ MGL_BUTTON_MIDDLE,
+ MGL_BUTTON_XBUTTON1,
+ MGL_BUTTON_XBUTTON2
+} mgl_mouse_button;
+
+typedef struct {
+ int button; /* mgl_mouse_button */
+ int x; /* relative to left of the window */
+ int y; /* relative to top of the window */
+} mgl_mouse_button_event;
+
+typedef enum {
+ MGL_EVENT_UNKNOWN,
+ MGL_EVENT_RESIZED,
+ MGL_EVENT_KEY_PRESSED,
+ MGL_EVENT_KEY_RELEASED,
+ MGL_EVENT_MOUSE_BUTTON_PRESSED,
+ MGL_EVENT_MOUSE_BUTTON_RELEASED,
+ MGL_EVENT_MOUSE_MOVED
+} mgl_event_type;
+
struct mgl_event {
- int type;
+ int type; /* mgl_event_type */
+ union {
+ mgl_size_event size;
+ mgl_key_event key;
+ mgl_mouse_button_event mouse_button;
+ mgl_mouse_move_event mouse_move;
+ };
};
#endif /* MGL_EVENT_H */
diff --git a/include/mgl/window/key.h b/include/mgl/window/key.h
new file mode 100644
index 0000000..90a3366
--- /dev/null
+++ b/include/mgl/window/key.h
@@ -0,0 +1,109 @@
+#ifndef _MGL_KEY_H_
+#define _MGL_KEY_H_
+
+typedef enum {
+ MGL_KEY_UNKNOWN,
+ MGL_KEY_A,
+ MGL_KEY_B,
+ MGL_KEY_C,
+ MGL_KEY_D,
+ MGL_KEY_E,
+ MGL_KEY_F,
+ MGL_KEY_G,
+ MGL_KEY_H,
+ MGL_KEY_I,
+ MGL_KEY_J,
+ MGL_KEY_K,
+ MGL_KEY_L,
+ MGL_KEY_M,
+ MGL_KEY_N,
+ MGL_KEY_O,
+ MGL_KEY_P,
+ MGL_KEY_Q,
+ MGL_KEY_R,
+ MGL_KEY_S,
+ MGL_KEY_T,
+ MGL_KEY_U,
+ MGL_KEY_V,
+ MGL_KEY_W,
+ MGL_KEY_X,
+ MGL_KEY_Y,
+ MGL_KEY_Z,
+ MGL_KEY_NUM0,
+ MGL_KEY_NUM1,
+ MGL_KEY_NUM2,
+ MGL_KEY_NUM3,
+ MGL_KEY_NUM4,
+ MGL_KEY_NUM5,
+ MGL_KEY_NUM6,
+ MGL_KEY_NUM7,
+ MGL_KEY_NUM8,
+ MGL_KEY_NUM9,
+ MGL_KEY_ESCAPE,
+ MGL_KEY_LCONTROL,
+ MGL_KEY_LSHIFT,
+ MGL_KEY_LALT,
+ MGL_KEY_LSYSTEM,
+ MGL_KEY_RCONTROL,
+ MGL_KEY_RSHIFT,
+ MGL_KEY_RALT,
+ MGL_KEY_RSYSTEM,
+ MGL_KEY_MENU,
+ MGL_KEY_LBRACKET,
+ MGL_KEY_RBRACKET,
+ MGL_KEY_SEMICOLON,
+ MGL_KEY_COMMA,
+ MGL_KEY_PERIOD,
+ MGL_KEY_QUOTE,
+ MGL_KEY_SLASH,
+ MGL_KEY_BACKSLASH,
+ MGL_KEY_TILDE,
+ MGL_KEY_EQUAL,
+ MGL_KEY_HYPHEN,
+ MGL_KEY_SPACE,
+ MGL_KEY_ENTER,
+ MGL_KEY_BACKSPACE,
+ MGL_KEY_TAB,
+ MGL_KEY_PAGEUP,
+ MGL_KEY_PAGEDOWN,
+ MGL_KEY_END,
+ MGL_KEY_HOME,
+ MGL_KEY_INSERT,
+ MGL_KEY_DELETE,
+ MGL_KEY_ADD,
+ MGL_KEY_SUBTRACT,
+ MGL_KEY_MULTIPLY,
+ MGL_KEY_DIVIDE,
+ MGL_KEY_LEFT,
+ MGL_KEY_RIGHT,
+ MGL_KEY_UP,
+ MGL_KEY_DOWN,
+ MGL_KEY_NUMPAD0,
+ MGL_KEY_NUMPAD1,
+ MGL_KEY_NUMPAD2,
+ MGL_KEY_NUMPAD3,
+ MGL_KEY_NUMPAD4,
+ MGL_KEY_NUMPAD5,
+ MGL_KEY_NUMPAD6,
+ MGL_KEY_NUMPAD7,
+ MGL_KEY_NUMPAD8,
+ MGL_KEY_NUMPAD9,
+ MGL_KEY_F1,
+ MGL_KEY_F2,
+ MGL_KEY_F3,
+ MGL_KEY_F4,
+ MGL_KEY_F5,
+ MGL_KEY_F6,
+ MGL_KEY_F7,
+ MGL_KEY_F8,
+ MGL_KEY_F9,
+ MGL_KEY_F10,
+ MGL_KEY_F11,
+ MGL_KEY_F12,
+ MGL_KEY_F13,
+ MGL_KEY_F14,
+ MGL_KEY_F15,
+ MGL_KEY_PAUSE
+} mgl_key;
+
+#endif /* _MGL_KEY_H_ */
diff --git a/include/mgl/window/window.h b/include/mgl/window/window.h
index b30583b..297ccb9 100644
--- a/include/mgl/window/window.h
+++ b/include/mgl/window/window.h
@@ -5,6 +5,8 @@
#include "../system/vec.h"
#include <stdbool.h>
+/* Vsync is automatically set for windows created, if supported by the system */
+
typedef struct __GLXcontextRec *GLXContext;
typedef struct mgl_event mgl_event;
/* x11 window handle. TODO: Add others when wayland, etc is added */
@@ -16,6 +18,7 @@ struct mgl_window {
mgl_window_handle window;
GLXContext glx_context;
mgl_vec2i size;
+ /* relative to the top left of the window. only updates when the cursor is inside the window */
mgl_vec2i cursor_position;
};