summaryrefslogtreecommitdiff
path: root/Kernel/GUITypes.h
blob: 61aa6587ebfa1320eabe8d45b5ae28c9a37b376c (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
#pragma once

#include <SharedGraphics/Color.h>
#include <SharedGraphics/Rect.h>

// GUI system call API types.

struct GUI_WindowFlags { enum {
    Visible = 1 << 0,
}; };

typedef unsigned GUI_Color;

struct GUI_Point {
    int x;
    int y;
};

struct GUI_Size {
    int width;
    int height;
};

struct GUI_Rect {
    GUI_Point location;
    GUI_Size size;
};

struct GUI_WindowParameters {
    GUI_Rect rect;
    Color background_color;
    unsigned flags { 0 };
    char title[128];
};

struct GUI_WindowBackingStoreInfo {
    void* backing_store_id;
    GUI_Size size;
    size_t bpp;
    size_t pitch;
    RGBA32* pixels;
};

enum class GUI_MouseButton : unsigned char {
    NoButton = 0,
    Left     = 1,
    Right    = 2,
    Middle   = 4,
};

struct GUI_KeyModifiers { enum {
    Shift = 1 << 0,
    Alt   = 1 << 1,
    Ctrl  = 1 << 2,
}; };


struct GUI_Event {
    enum Type : unsigned {
        Invalid,
        Paint,
        MouseMove,
        MouseDown,
        MouseUp,
        KeyDown,
        KeyUp,
        WindowActivated,
        WindowDeactivated,
        WindowCloseRequest,
    };
    Type type { Invalid };
    int window_id { -1 };

    union {
        struct {
            GUI_Rect rect;
        } paint;
        struct {
            GUI_Point position;
            GUI_MouseButton button;
            unsigned buttons;
        } mouse;
        struct {
            char character;
            byte key;
            byte modifiers;
            bool ctrl : 1;
            bool alt : 1;
            bool shift : 1;
        } key;
    };
};

inline Rect::Rect(const GUI_Rect& r) : Rect(r.location, r.size) { }
inline Point::Point(const GUI_Point& p) : Point(p.x, p.y) { }
inline Size::Size(const GUI_Size& s) : Size(s.width, s.height) { }
inline Rect::operator GUI_Rect() const { return { m_location, m_size }; }
inline Point::operator GUI_Point() const { return { m_x, m_y }; }
inline Size::operator GUI_Size() const { return { m_width, m_height }; }