aboutsummaryrefslogtreecommitdiff
path: root/include/mgl/window/event.h
blob: f6bf7fdde66554d45a941d6eaecc3bbee45c12c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef MGL_EVENT_H
#define MGL_EVENT_H

#include "key.h"
#include <stdbool.h>
#include <stdint.h>

typedef struct mgl_event mgl_event;

typedef struct {
    int width;
    int height;
} mgl_size_event;

typedef struct {
    uint32_t codepoint;
    int size;
    char str[5]; /* utf8, null terminated */
} mgl_text_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_CLOSED, /* Window closed */
    MGL_EVENT_RESIZED, /* Window resized */
    MGL_EVENT_LOST_FOCUS,
    MGL_EVENT_GAINED_FOCUS,
    MGL_EVENT_TEXT_ENTERED,
    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; /* mgl_event_type */
    union {
        mgl_size_event size;
        mgl_text_event text;
        mgl_key_event key;
        mgl_mouse_button_event mouse_button;
        mgl_mouse_move_event mouse_move;
    };
};

#endif /* MGL_EVENT_H */