HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
hitbox.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
10namespace tt {
11
12class widget;
13
14class hitbox {
15public:
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
33 Type type;
34 widget const *widget;
35
36 constexpr hitbox(hitbox const &) noexcept = default;
37 constexpr hitbox(hitbox &&) noexcept = default;
38 constexpr hitbox &operator=(hitbox const &) noexcept = default;
39 constexpr hitbox &operator=(hitbox &&) noexcept = default;
40
41 constexpr hitbox() noexcept : widget(nullptr), _elevation(-std::numeric_limits<float>::max()), type(Type::Outside)
42 {
43 }
44
45 constexpr hitbox(
46 tt::widget const *widget,
47 float elevation = -std::numeric_limits<float>::max(),
48 Type type = Type::Default) noexcept
49 :
50 widget(widget), _elevation(elevation), type(type)
51 {
52 }
53
54 friend bool operator<(hitbox const &lhs, hitbox const &rhs) noexcept {
55 if ((lhs.widget == nullptr) == (rhs.widget == nullptr)) {
56 if (lhs._elevation == rhs._elevation) {
57 return static_cast<int>(lhs.type) < static_cast<int>(rhs.type);
58 } else {
59 // We actually want to check if a hitbox is above another hitbox;
60 // which means the inverse of depth.
61 return lhs._elevation < rhs._elevation;
62 }
63 } else {
64 return lhs.widget == nullptr;
65 }
66 }
67private:
68 float _elevation;
69};
70
71}
Definition hitbox.hpp:14
An interactive graphical object as part of the user-interface.
Definition widget.hpp:37