HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
hitbox.hpp
1// Copyright Take Vos 2020-2021.
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 "../geometry/point.hpp"
8#include "../assert.hpp"
9#include <limits>
10#include <cstdint>
11#include <compare>
12
13namespace hi::inline v1 {
14class widget;
15
16enum class hitbox_type : uint8_t {
17 outside,
18 _default,
19 button,
20 scroll_bar,
21 text_edit,
22 move_area,
23 bottom_resize_border,
24 top_resize_border,
25 left_resize_border,
26 right_resize_border,
27 bottom_left_resize_corner,
28 bottom_right_resize_corner,
29 top_left_resize_corner,
30 top_right_resize_corner,
31 application_icon
32};
33
34class hitbox {
35public:
36 hitbox_type type;
37 widget const *widget;
38
39 constexpr hitbox(hitbox const&) noexcept = default;
40 constexpr hitbox(hitbox&&) noexcept = default;
41 constexpr hitbox& operator=(hitbox const&) noexcept = default;
42 constexpr hitbox& operator=(hitbox&&) noexcept = default;
43
44 constexpr hitbox() noexcept : widget(nullptr), _elevation(-std::numeric_limits<float>::max()), type(hitbox_type::outside) {}
45
46 constexpr hitbox(
47 hi::widget const *widget,
48 float elevation = -std::numeric_limits<float>::max(),
49 hitbox_type type = hitbox_type::_default) noexcept :
50 widget(widget), _elevation(elevation), type(type)
51 {
52 }
53
54 [[nodiscard]] constexpr friend std::strong_ordering operator<=>(hitbox const& lhs, hitbox const& rhs) noexcept
55 {
56 if ((lhs.widget == nullptr) == (rhs.widget == nullptr)) {
57 // Either both are widgets, or both are not widgets.
58 hilet elevation_ordering = lhs._elevation <=> rhs._elevation;
59 if (elevation_ordering == std::partial_ordering::equivalent) {
60 return to_underlying(lhs.type) <=> to_underlying(rhs.type);
61 } else if (elevation_ordering == std::partial_ordering::less) {
62 return std::strong_ordering::less;
63 } else if (elevation_ordering == std::partial_ordering::greater) {
64 return std::strong_ordering::greater;
65 } else {
67 }
68 } else if (lhs.widget == nullptr) {
69 // If lhs is not a widget than it is less.
70 return std::strong_ordering::less;
71 } else {
72 // Otherwise the lhs is greater.
73 return std::strong_ordering::greater;
74 }
75 }
76
77private:
78 float _elevation;
79};
80
81} // namespace hi::inline v1
Utilities to assert and bound check.
#define hi_no_default(...)
This part of the code should not be reachable, unless a programming bug.
Definition assert.hpp:148
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
DOXYGEN BUG.
Definition algorithm.hpp:15
@ outside
The border is drawn outside the edge of a quad.
Definition hitbox.hpp:34
An interactive graphical object as part of the user-interface.
Definition widget.hpp:46