aboutsummaryrefslogtreecommitdiff
path: root/CruUI/ui/ui_base.h
blob: 8dfbf53de02d7b98424100fa9ea4ec3173d2d5fe (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
101
102
103
104
105
#pragma once

namespace cru
{
    namespace ui
    {
        struct Point
        {
            static const Point zero;

            Point() = default;
            Point(const float x, const float y) : x(x), y(y) { }

            float x;
            float y;
        };

        struct Size
        {
            static const Size zero;

            Size() = default;
            Size(const float width, const float height) : width(width), height(height) { }

            float width;
            float height;
        };

        struct Rect 
        {
            Rect() = default;
            Rect(const float left, const float top, const float width, const float height)
                : left(left), top(top), width(width), height(height) { }
            Rect(const Point& lefttop, const Size& size)
                : left(lefttop.x), top(lefttop.y), width(size.width), height(size.height) { }

            static Rect FromVertices(const float left, const float top, const float right, const float bottom)
            {
                return Rect(left, top, right - left, bottom - top);
            }

            float GetRight() const
            {
                return left + width;
            }

            float GetBottom() const
            {
                return top + height;
            }

            Point GetLeftTop() const
            {
                return Point(left, top);
            }

			Point GetRightBottom() const
            {
				return Point(left + width, top + height);
			}

            Size GetSize() const
            {
                return Size(width, height);
            }

            bool IsPointInside(const Point& point) const
            {
                return
                    point.x >= left         &&
                    point.x < GetRight()    &&
                    point.y >= top          &&
                    point.y < GetBottom();
            }

            float left = 0.0f;
            float top = 0.0f;
            float width = 0.0f;
            float height = 0.0f;
        };

        struct Thickness
        {
            Thickness() : Thickness(0) { }
            explicit Thickness(const float width)
                : left(width), top(width), right(width), bottom(width) { }

            Thickness(const float left, const float top, const float right, const float bottom)
                : left(left), top(top), right(right), bottom(bottom) { }


            float left;
            float top;
            float right;
            float bottom;
        };

        enum class MouseButton
        {
            Left,
            Right,
            Middle
        };
    }
}