aboutsummaryrefslogtreecommitdiff
path: root/include/mgl/window/event.h
blob: 31af4f1b3c3c75e0ae0c4187f8f0943e725a012f (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
#ifndef MGL_EVENT_H
#define MGL_EVENT_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 button; /* mgl_mouse_button */
    int x; /* mouse position relative to left of the window */
    int y; /* mouse position relative to top of the window */
} mgl_mouse_button_event;

typedef struct {
    int delta; /* positive = up, negative = down */
    int x; /* mouse position relative to left of the window */
    int y; /* mouse position relative to left of the window */
} mgl_mouse_wheel_scroll_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_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_WHEEL_SCROLLED,
    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_wheel_scroll_event mouse_wheel_scroll;
        mgl_mouse_move_event mouse_move;
    };
};

#endif /* MGL_EVENT_H */