HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
translate2.hpp
1// Copyright Take Vos 2021-2022.
2// Distributed under the Boost Software License, Version float{1}.
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 "point2.hpp"
8#include "aarectangle.hpp"
9#include "../macros.hpp"
10#include <concepts>
11
12namespace hi { inline namespace v1 {
13
15public:
16 using array_type = simd<float, 4>;
17 using value_type = array_type::value_type;
18
19 constexpr translate2(translate2 const&) noexcept = default;
20 constexpr translate2(translate2&&) noexcept = default;
21 constexpr translate2& operator=(translate2 const&) noexcept = default;
22 constexpr translate2& operator=(translate2&&) noexcept = default;
23
24 [[nodiscard]] constexpr translate2() noexcept : _v(0.0f, 0.0f, 0.0f, 0.0f) {}
25
26 [[nodiscard]] constexpr explicit operator array_type() const noexcept
27 {
28 return _v;
29 }
30
31 [[nodiscard]] constexpr explicit translate2(array_type const& other) noexcept : _v(other)
32 {
33 hi_axiom(holds_invariant());
34 }
35
36 [[nodiscard]] constexpr explicit translate2(aarectangle const& other) noexcept :
37 _v(static_cast<array_type>(get<0>(other)).xy00())
38 {
39 }
40
41 [[nodiscard]] constexpr explicit translate2(aarectangle const& other, float z) noexcept :
42 _v(static_cast<array_type>(get<0>(other)).xy00())
43 {
44 _v.z() = z;
45 }
46
47 [[nodiscard]] constexpr explicit translate2(vector2 const& other) noexcept : _v(static_cast<array_type>(other)) {}
48
49 [[nodiscard]] constexpr explicit translate2(point2 const& other) noexcept : _v(static_cast<array_type>(other).xy00()) {}
50
51 [[nodiscard]] constexpr translate2(float x, float y) noexcept : _v(x, y, 0.0f, 0.0f) {}
52
53 [[nodiscard]] constexpr float x() const noexcept
54 {
55 return _v.x();
56 }
57
58 [[nodiscard]] constexpr float y() const noexcept
59 {
60 return _v.y();
61 }
62
63 [[nodiscard]] constexpr float& x() noexcept
64 {
65 return _v.x();
66 }
67
68 [[nodiscard]] constexpr float& y() noexcept
69 {
70 return _v.y();
71 }
72
79 [[nodiscard]] constexpr static translate2
81 {
82 auto x = float{0};
84 x = dst_rectangle.left();
85
87 x = dst_rectangle.right() - src_rectangle.width();
88
90 x = dst_rectangle.center() - src_rectangle.width() * 0.5f;
91
92 } else {
93 hi_no_default();
94 }
95
96 auto y = float{0};
98 y = dst_rectangle.bottom();
99
100 } else if (alignment == vertical_alignment::top) {
101 y = dst_rectangle.top() - src_rectangle.height();
102
104 y = dst_rectangle.middle() - src_rectangle.height() * 0.5f;
105
106 } else {
107 hi_no_default();
108 }
109
110 return translate2{x - src_rectangle.left(), y - src_rectangle.bottom()};
111 }
112
113 [[nodiscard]] constexpr friend bool operator==(translate2 const& lhs, translate2 const& rhs) noexcept
114 {
115 return equal(lhs._v, rhs._v);
116 }
117
118 [[nodiscard]] constexpr translate2 operator~() const noexcept
119 {
120 return translate2{-_v};
121 }
122
123 [[nodiscard]] constexpr bool holds_invariant() const noexcept
124 {
125 return _v.z() == 0.0f and _v.w() == 0.0f;
126 }
127
128 [[nodiscard]] friend constexpr translate2 round(translate2 const& rhs) noexcept
129 {
130 return translate2{round(rhs._v)};
131 }
132
133private:
134 array_type _v;
135};
136
137}} // namespace hi::v1
@ middle
Align to the vertical-middle.
@ bottom
Align to the bottom.
@ top
Align to the top.
@ right
Align the text to the right side.
@ left
Align the text to the left side.
@ center
Align the text in the center.
@ other
The gui_event does not have associated data.
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
Class which represents an axis-aligned rectangle.
Definition aarectangle.hpp:29
Horizontal/Vertical alignment combination.
Definition alignment.hpp:242
Definition translate2.hpp:14
static constexpr translate2 align(aarectangle src_rectangle, aarectangle dst_rectangle, alignment alignment) noexcept
Align a rectangle within another rectangle.
Definition translate2.hpp:80
A high-level geometric vector Part of the high-level vector, point, mat and color types.
Definition vector2.hpp:19