MGL(Win32)
読み取り中…
検索中…
一致する文字列を見つけられません
mgl_alignment.h
[詳解]
1// SPDX-License-Identifier: Zlib
2/* ------------------------------------------------------------------------- */
9/* ------------------------------------------------------------------------- */
10
11#ifndef INCGUARD_MGL_ALIGNMENT_H_1625900468
12#define INCGUARD_MGL_ALIGNMENT_H_1625900468
13
16
17namespace MGL
18{
21{
23 enum class Horizontal : uint8_t
24 {
25 Left,
26 Center,
27 Right
28 };
29
31 enum class Vertical : uint8_t
32 {
33 Top,
34 Middle,
35 Bottom
36 };
37
40
41 /* ------------------------------------------------------------------------- */
45 /* ------------------------------------------------------------------------- */
46 constexpr Alignment() noexcept
49 {
50 }
51
52 /* ------------------------------------------------------------------------- */
58 /* ------------------------------------------------------------------------- */
59 constexpr Alignment(Horizontal inHorizontal, Vertical inVertical) noexcept
60 : horizontal(inHorizontal)
61 , vertical(inVertical)
62 {
63 }
64
65 /* ------------------------------------------------------------------------- */
71 /* ------------------------------------------------------------------------- */
72 constexpr Alignment(Vertical inVertical, Horizontal inHorizontal) noexcept
73 : horizontal(inHorizontal)
74 , vertical(inVertical)
75 {
76 }
77
78 /* ------------------------------------------------------------------------- */
85 /* ------------------------------------------------------------------------- */
86 [[nodiscard]] constexpr MGL::Vector2 AdjustPosition(const MGL::Vector2 &baseSize, const MGL::Vector2 &position) const noexcept
87 {
88 MGL::Vector2 adjustedPosition(position);
89
90 switch (horizontal)
91 {
93 break;
94
96 adjustedPosition.x += baseSize.x * 0.5f;
97 break;
98
100 adjustedPosition.x += baseSize.x;
101 break;
102 }
103
104 switch (vertical)
105 {
106 case Vertical::Top:
107 break;
108
109 case Vertical::Middle:
110 adjustedPosition.y += baseSize.y * 0.5f;
111 break;
112
113 case Vertical::Bottom:
114 adjustedPosition.y += baseSize.y;
115 break;
116 }
117
118 return adjustedPosition;
119 }
120
121 /* ------------------------------------------------------------------------- */
127 /* ------------------------------------------------------------------------- */
128 [[nodiscard]] constexpr MGL::Vector2 AdjustRectangle(const MGL::Rectangle &rectangle) const noexcept
129 {
130 MGL::Vector2 adjustedPosition(rectangle.GetPosition());
131
132 switch (horizontal)
133 {
134 case Horizontal::Left:
135 break;
136
138 adjustedPosition.x -= rectangle.width * 0.5f;
139 break;
140
142 adjustedPosition.x -= rectangle.width;
143 break;
144 }
145
146 switch (vertical)
147 {
148 case Vertical::Top:
149 break;
150
151 case Vertical::Middle:
152 adjustedPosition.y -= rectangle.height * 0.5f;
153 break;
154
155 case Vertical::Bottom:
156 adjustedPosition.y -= rectangle.height;
157 break;
158 }
159
160 return adjustedPosition;
161 }
162};
163
173
174} // namespace MGL
175
176#endif // INCGUARD_MGL_ALIGNMENT_H_1625900468
177
178// vim: et ts=4 sw=4 sts=4
constexpr auto kAlignmentTopRight
右上
Definition mgl_alignment.h:166
constexpr auto kAlignmentMiddleLeft
左中央
Definition mgl_alignment.h:167
constexpr auto kAlignmentTopLeft
左上
Definition mgl_alignment.h:164
constexpr auto kAlignmentBottomLeft
左下
Definition mgl_alignment.h:170
constexpr auto kAlignmentTopCenter
中央上
Definition mgl_alignment.h:165
constexpr auto kAlignmentMiddleRight
右中央
Definition mgl_alignment.h:169
constexpr auto kAlignmentBottomCenter
中央下
Definition mgl_alignment.h:171
constexpr auto kAlignmentMiddleCenter
中央
Definition mgl_alignment.h:168
constexpr auto kAlignmentBottomRight
右下
Definition mgl_alignment.h:172
MGL 矩形
MGL 2Dベクトル
配置情報
Definition mgl_alignment.h:21
constexpr MGL::Vector2 AdjustPosition(const MGL::Vector2 &baseSize, const MGL::Vector2 &position) const noexcept
現在の配置情報を元に補正した座標を取得
Definition mgl_alignment.h:86
constexpr Alignment(Vertical inVertical, Horizontal inHorizontal) noexcept
コンストラクタ
Definition mgl_alignment.h:72
constexpr Alignment() noexcept
コンストラクタ
Definition mgl_alignment.h:46
constexpr Alignment(Horizontal inHorizontal, Vertical inVertical) noexcept
コンストラクタ
Definition mgl_alignment.h:59
Vertical vertical
垂直方向の配置情報
Definition mgl_alignment.h:39
Horizontal
水平方向の配置
Definition mgl_alignment.h:24
Vertical
垂直方向の配置
Definition mgl_alignment.h:32
Horizontal horizontal
水平方向の配置情報
Definition mgl_alignment.h:38
constexpr MGL::Vector2 AdjustRectangle(const MGL::Rectangle &rectangle) const noexcept
現在の配置情報を元に補正した矩形の原点を取得
Definition mgl_alignment.h:128
矩形
Definition mgl_rectangle.h:20
2Dベクトル
Definition mgl_vector2.h:23
float y
Y成分
Definition mgl_vector2.h:25
float x
X成分
Definition mgl_vector2.h:24