HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
HitBox.hpp
1// Copyright 2020 Pokitec
2// All rights reserved.
3
4#pragma once
5
6#include <limits>
7
8namespace tt {
9
10class Widget;
11
12struct HitBox {
13 enum class Type : uint8_t {
14 Outside,
15 Default,
16 Button,
17 TextEdit,
18 MoveArea,
19 BottomResizeBorder,
20 TopResizeBorder,
21 LeftResizeBorder,
22 RightResizeBorder,
23 BottomLeftResizeCorner,
24 BottomRightResizeCorner,
25 TopLeftResizeCorner,
26 TopRightResizeCorner,
27 ApplicationIcon
28 };
29
30 Widget const *widget;
31 float elevation;
32 Type type;
33
34 HitBox(Widget const *widget=nullptr, float elevation=-std::numeric_limits<float>::max(), Type type=Type::Outside) noexcept :
35 widget(widget), elevation(elevation), type(type) {}
36
37
38 friend bool operator==(HitBox const &lhs, HitBox const &rhs) noexcept {
39 return lhs.widget == rhs.widget && lhs.elevation == rhs.elevation && lhs.type == rhs.type;
40 }
41
42 friend bool operator!=(HitBox const &lhs, HitBox const &rhs) noexcept {
43 return !(lhs == rhs);
44 }
45
46 friend bool operator<(HitBox const &lhs, HitBox const &rhs) noexcept {
47 if ((lhs.widget == nullptr) == (rhs.widget == nullptr)) {
48 if (lhs.elevation == rhs.elevation) {
49 return static_cast<int>(lhs.type) < static_cast<int>(rhs.type);
50 } else {
51 // We actually want to check if a hitbox is above another hitbox;
52 // which means the inverse of depth.
53 return lhs.elevation < rhs.elevation;
54 }
55 } else {
56 return lhs.widget == nullptr;
57 }
58 }
59
60 friend bool operator>(HitBox const &lhs, HitBox const &rhs) noexcept {
61 return rhs < lhs;
62 }
63
64 friend bool operator<=(HitBox const &lhs, HitBox const &rhs) noexcept {
65 return !(lhs > rhs);
66 }
67
68 friend bool operator>=(HitBox const &lhs, HitBox const &rhs) noexcept {
69 return !(lhs < rhs);
70 }
71
72};
73
74}
Definition HitBox.hpp:12
Definition Widget.hpp:64