HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
hit_box.hpp
1// Copyright Take Vos 2020.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include <limits>
8#include <cstdint>
9#include <memory>
10
11namespace tt {
12
13class widget;
14
15struct hit_box {
16 enum class Type : uint8_t {
17 Outside,
18 Default,
19 Button,
20 TextEdit,
21 MoveArea,
22 BottomResizeBorder,
23 TopResizeBorder,
24 LeftResizeBorder,
25 RightResizeBorder,
26 BottomLeftResizeCorner,
27 BottomRightResizeCorner,
28 TopLeftResizeCorner,
29 TopRightResizeCorner,
30 ApplicationIcon
31 };
32
34 float elevation;
35 Type type;
36
37 hit_box() noexcept : widget({}), elevation(-std::numeric_limits<float>::max()), type(Type::Outside)
38 {
39 }
40
41 hit_box(std::weak_ptr<tt::widget const> widget, float elevation = -std::numeric_limits<float>::max(), Type type = Type::Default) noexcept
42 :
43 widget(widget), elevation(elevation), type(type)
44 {
45 }
46
47 friend bool operator<(hit_box const &lhs, hit_box const &rhs) noexcept {
48 if (lhs.widget.expired() == rhs.widget.expired()) {
49 if (lhs.elevation == rhs.elevation) {
50 return static_cast<int>(lhs.type) < static_cast<int>(rhs.type);
51 } else {
52 // We actually want to check if a hitbox is above another hitbox;
53 // which means the inverse of depth.
54 return lhs.elevation < rhs.elevation;
55 }
56 } else {
57 return lhs.widget.expired();
58 }
59 }
60
61};
62
63}
Definition hit_box.hpp:15
Definition widget.hpp:97