aboutsummaryrefslogtreecommitdiff
path: root/include/mglpp/window/Event.hpp
blob: bcd1e910c4476dc3b89b54313f2adc8604568b19 (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#ifndef MGLPP_EVENT_HPP
#define MGLPP_EVENT_HPP

#include "Keyboard.hpp"
#include "Mouse.hpp"
#include <stdint.h>

/* These have to match the same structures in mgl event */

namespace mgl {
    class Event {
    public:
        struct SizeEvent {
            int width;
            int height;
        };

        struct TextEvent {
            uint32_t codepoint;
            int size;
            char str[5]; /* utf8, null terminated */
        };

        struct KeyEvent {
            Keyboard::Key code;
            bool alt;
            bool control;
            bool shift;
            bool system;
        };

        struct MouseButtonEvent {
            Mouse::Button button;
            int x; /* mouse position relative to left of the window */
            int y; /* mouse position relative to top of the window */
        };

        struct MouseWheelScrollEvent {
            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 */
        };

        struct MouseMoveEvent {
            int x; /* relative to left of the window */
            int y; /* relative to the top of the window */
        };

        struct MonitorGenericEvent {
            const char *name; /* This name may only be valid until the next time |mgl_window_poll_event| is called */
            int id;
            int x;
            int y;
            int width;
            int height;
            int refresh_rate; /* 0 if unknown */
        };

        using MonitorConnectedEvent = MonitorGenericEvent;
        using MonitorPropertyChangedEvent = MonitorGenericEvent;

        struct MonitorDisconnectedEvent {
            int id;
        };

        enum Type : int {
            Unknown,
            Closed, /* Window closed */
            Resized, /* Window resized */
            LostFocus,
            GainedFocus,
            TextEntered,
            KeyPressed,
            KeyReleased,
            MouseButtonPressed,
            MouseButtonReleased,
            MouseWheelScrolled,
            MouseMoved,
            MonitorConnected,
            MonitorDisconnected,
            MonitorPropertyChanged,
        };

        Type type;

        union {
            SizeEvent size;
            TextEvent text;
            KeyEvent key;
            MouseButtonEvent mouse_button;
            MouseWheelScrollEvent mouse_wheel_scroll;
            MouseMoveEvent mouse_move;
            MonitorConnectedEvent monitor_connected;
            MonitorDisconnectedEvent monitor_disconnected;
            MonitorPropertyChangedEvent monitor_property_changed;
        };
    };
}

#endif /* MGLPP_EVENT_HPP */