MGL(Win32)
読み取り中…
検索中…
一致する文字列を見つけられません
mgl_ui_widget.h
[詳解]
1// SPDX-License-Identifier: Zlib
2/* ------------------------------------------------------------------------- */
9/* ------------------------------------------------------------------------- */
10
11#ifndef INCGUARD_MGL_UI_WIDGET_H_1625439573
12#define INCGUARD_MGL_UI_WIDGET_H_1625439573
13
16#include <mgl/mgl_environment.h>
20
21namespace MGL::UI
22{
23class EventContext;
24class EventListener;
25class EventDelegate;
26
28class Widget
29{
30public:
31 /* ------------------------------------------------------------------------- */
35 /* ------------------------------------------------------------------------- */
36 Widget(uint32_t typeIdentifier) noexcept
37 : _typeIdentifier(typeIdentifier)
38 {
39 }
40
41 virtual ~Widget() noexcept = default;
42
43 void Update(const Vector2 &offset = Vector2(0.0f, 0.0f), bool updateEvent = true) noexcept;
44 void Render(const Vector2 &offset = Vector2(0.0f, 0.0f)) noexcept;
45
46 /* ------------------------------------------------------------------------- */
51 /* ------------------------------------------------------------------------- */
52 void Update(bool updateEvent) noexcept
53 {
54 Update(Vector2(), updateEvent);
55 }
56
57 /* ------------------------------------------------------------------------- */
62 /* ------------------------------------------------------------------------- */
63 [[nodiscard]] virtual Rectangle GetRectangle() const noexcept
64 {
65 return {};
66 }
67
68 /* ------------------------------------------------------------------------- */
73 /* ------------------------------------------------------------------------- */
74 [[nodiscard]] constexpr uint32_t GetTypeIdentifier() const noexcept
75 {
76 return _typeIdentifier;
77 }
78
79 void SetVisible(bool isVisible) noexcept;
80 [[nodiscard]] bool IsVisible() const noexcept;
81
82 /* ------------------------------------------------------------------------- */
87 /* ------------------------------------------------------------------------- */
88 [[nodiscard]] constexpr bool GetLocalVisibleFlag() const noexcept
89 {
90 return _isVisible;
91 }
92
93 /* ------------------------------------------------------------------------- */
98 /* ------------------------------------------------------------------------- */
99 constexpr void SetTransparency(float transparency) noexcept
100 {
101 _transparency = transparency;
102 }
103
104 /* ------------------------------------------------------------------------- */
109 /* ------------------------------------------------------------------------- */
110 [[nodiscard]] constexpr float GetLocalTransparency() const noexcept
111 {
112 return _transparency;
113 }
114
115 [[nodiscard]] float GetTransparency() const noexcept;
116
117 [[nodiscard]] Vector2 GetPosition() const noexcept;
118
119 /* ------------------------------------------------------------------------- */
124 /* ------------------------------------------------------------------------- */
125 [[nodiscard]] MGL_MAYBE_CONSTEXPR Vector2 GetSize() const noexcept
126 {
127 return GetRectangle().GetSize();
128 }
129
130 [[nodiscard]] Vector2 GetParentSize() const noexcept;
131
132 bool AddChild(Widget *child) noexcept;
133 bool RemoveChild(Widget *child) noexcept;
134
135 /* ------------------------------------------------------------------------- */
140 /* ------------------------------------------------------------------------- */
141 [[nodiscard]] const Widget *GetParent() const noexcept
142 {
143 return _parent;
144 }
145
146 /* ------------------------------------------------------------------------- */
151 /* ------------------------------------------------------------------------- */
152 [[nodiscard]] const STL::list<Widget *> &GetChildren() const noexcept
153 {
154 return _children;
155 }
156
157 bool ActivateEventContext(EventListener *listener, EventDelegate *delegate) noexcept;
158 bool ActivateEventContext(EventListener *listener) noexcept;
159
160 /* ------------------------------------------------------------------------- */
165 /* ------------------------------------------------------------------------- */
166 constexpr void SetEventIdentifier(EventID identifier) noexcept
167 {
168 _eventIdentifier = identifier;
169 }
170
171 /* ------------------------------------------------------------------------- */
176 /* ------------------------------------------------------------------------- */
177 [[nodiscard]] constexpr EventID GetEventIdentifier() const noexcept
178 {
179 return _eventIdentifier;
180 }
181
182 /* ------------------------------------------------------------------------- */
187 /* ------------------------------------------------------------------------- */
188 constexpr void SetPivot(const Alignment &pivotAlignment) noexcept
189 {
190 _pivotAlignment = pivotAlignment;
191 }
192
193 /* ------------------------------------------------------------------------- */
198 /* ------------------------------------------------------------------------- */
199 [[nodiscard]] constexpr const Alignment &GetPivot() const noexcept
200 {
201 return _pivotAlignment;
202 }
203
204 /* ------------------------------------------------------------------------- */
209 /* ------------------------------------------------------------------------- */
210 constexpr void SetAnchor(const Alignment &anchorAlignment) noexcept
211 {
212 _anchorAlignment = anchorAlignment;
213 }
214
215 /* ------------------------------------------------------------------------- */
220 /* ------------------------------------------------------------------------- */
221 [[nodiscard]] constexpr const Alignment &GetAnchor() const noexcept
222 {
223 return _anchorAlignment;
224 }
225
226 /* ------------------------------------------------------------------------- */
231 /* ------------------------------------------------------------------------- */
232 [[nodiscard]] constexpr EventState GetEventState() const noexcept
233 {
234 return _eventState;
235 }
236
237 /* ------------------------------------------------------------------------- */
242 /* ------------------------------------------------------------------------- */
243 [[nodiscard]] constexpr Input::TouchID GetEventTouchID() const noexcept
244 {
245 return _eventTouchID;
246 }
247
248protected:
249 /* ------------------------------------------------------------------------- */
254 /* ------------------------------------------------------------------------- */
255 virtual void OnUpdate(const Vector2 &position) noexcept
256 {
257 (void)position;
258 }
259
260 /* ------------------------------------------------------------------------- */
265 /* ------------------------------------------------------------------------- */
266 virtual void OnRender(const Vector2 &position) noexcept
267 {
268 (void)position;
269 }
270
271 /* ------------------------------------------------------------------------- */
277 /* ------------------------------------------------------------------------- */
278 virtual void OnNotifiedEvent(EventType eventType, uint32_t argument) noexcept
279 {
280 (void)eventType;
281 (void)argument;
282 }
283
284private:
285 void UpdateEvent(EventContext *eventContext, const Vector2 &offset) noexcept;
286 void ApplyEventResult(EventContext *eventContext, const EventResult &result) noexcept;
287 void SendEvent(EventContext *eventContext, EventType eventType, uint32_t argument = 0, Input::TouchID touchID = Input::TouchID::Invalid) noexcept;
288
289 [[nodiscard]] Vector2 GetAdjustedPosition() const noexcept;
290
291 uint32_t _typeIdentifier;
292
293 Widget *_parent{nullptr};
294 STL::list<Widget *> _children;
295
296 bool _isVisible{true};
297 float _transparency{1.0f};
298
299 STL::unique_ptr<EventContext> _eventContext{nullptr};
300 EventState _eventState{EventState::None};
301 EventID _eventIdentifier{kInvalidEventID};
302 Input::TouchID _eventTouchID{Input::TouchID::Invalid};
303
304 Alignment _pivotAlignment;
305 Alignment _anchorAlignment;
306};
307
308/* ------------------------------------------------------------------------- */
313/* ------------------------------------------------------------------------- */
314template<typename Type>
315class TypedWidget : public Widget
316{
317public:
318 /* ------------------------------------------------------------------------- */
323 /* ------------------------------------------------------------------------- */
324 TypedWidget(Type type) noexcept
325 : Widget(static_cast<uint32_t>(type))
326 {
327 }
328
329 ~TypedWidget() noexcept override = default;
330
331 /* ------------------------------------------------------------------------- */
336 /* ------------------------------------------------------------------------- */
337 constexpr Type GetType() const noexcept
338 {
339 return static_cast<Type>(GetTypeIdentifier());
340 }
341};
342} // namespace MGL::UI
343
344#endif // INCGUARD_MGL_UI_WIDGET_H_1625439573
345
346// vim: et ts=4 sw=4 sts=4
Definition mgl_ui_event_context.h:24
Definition mgl_ui_event_delegate.h:20
イベントリスナーインターフェース
Definition mgl_ui_event_listener.h:21
型情報付きのウィジットクラス
Definition mgl_ui_widget.h:316
TypedWidget(Type type) noexcept
コンストラクタ
Definition mgl_ui_widget.h:324
constexpr Type GetType() const noexcept
識別子を取得
Definition mgl_ui_widget.h:337
UIウィジットクラス
Definition mgl_ui_widget.h:29
constexpr EventState GetEventState() const noexcept
イベントのステートを取得
Definition mgl_ui_widget.h:232
virtual void OnNotifiedEvent(EventType eventType, uint32_t argument) noexcept
イベント通知後の処理
Definition mgl_ui_widget.h:278
void Update(const Vector2 &offset=Vector2(0.0f, 0.0f), bool updateEvent=true) noexcept
更新処理
Definition mgl_ui_widget.cc:24
bool AddChild(Widget *child) noexcept
子ウィジットの追加
Definition mgl_ui_widget.cc:386
bool ActivateEventContext(EventListener *listener, EventDelegate *delegate) noexcept
イベントコンテキストのアクティベート
Definition mgl_ui_widget.cc:212
const Widget * GetParent() const noexcept
親ウィジットの取得
Definition mgl_ui_widget.h:141
virtual Rectangle GetRectangle() const noexcept
矩形の取得
Definition mgl_ui_widget.h:63
float GetTransparency() const noexcept
透過値の取得
Definition mgl_ui_widget.cc:327
constexpr Input::TouchID GetEventTouchID() const noexcept
イベントのタッチIDを取得
Definition mgl_ui_widget.h:243
void SetVisible(bool isVisible) noexcept
可視状態の設定
Definition mgl_ui_widget.cc:274
constexpr void SetTransparency(float transparency) noexcept
透過値の設定
Definition mgl_ui_widget.h:99
const STL::list< Widget * > & GetChildren() const noexcept
子ウィジットの取得
Definition mgl_ui_widget.h:152
virtual void OnRender(const Vector2 &position) noexcept
描画処理
Definition mgl_ui_widget.h:266
Widget(uint32_t typeIdentifier) noexcept
コンストラクタ
Definition mgl_ui_widget.h:36
Vector2 GetPosition() const noexcept
位置を取得
Definition mgl_ui_widget.cc:365
constexpr void SetAnchor(const Alignment &anchorAlignment) noexcept
ウィジットのアンカーを設定
Definition mgl_ui_widget.h:210
bool RemoveChild(Widget *child) noexcept
子ウィジットの削除
Definition mgl_ui_widget.cc:409
constexpr bool GetLocalVisibleFlag() const noexcept
このウィジットに設定された可視状態のフラグを取得
Definition mgl_ui_widget.h:88
constexpr void SetEventIdentifier(EventID identifier) noexcept
イベントIDを設定
Definition mgl_ui_widget.h:166
constexpr EventID GetEventIdentifier() const noexcept
イベントIDを取得
Definition mgl_ui_widget.h:177
constexpr void SetPivot(const Alignment &pivotAlignment) noexcept
ウィジットの中心アライメントを設定
Definition mgl_ui_widget.h:188
Vector2 GetParentSize() const noexcept
親のサイズを取得
Definition mgl_ui_widget.cc:348
constexpr uint32_t GetTypeIdentifier() const noexcept
ウィジットの種類の識別子を取得
Definition mgl_ui_widget.h:74
constexpr const Alignment & GetAnchor() const noexcept
ウィジットのアンカー取得
Definition mgl_ui_widget.h:221
constexpr float GetLocalTransparency() const noexcept
このウィジットに設定された透過値の設定
Definition mgl_ui_widget.h:110
constexpr const Alignment & GetPivot() const noexcept
ウィジットの中心アライメントを取得
Definition mgl_ui_widget.h:199
MGL_MAYBE_CONSTEXPR Vector2 GetSize() const noexcept
サイズを取得
Definition mgl_ui_widget.h:125
bool IsVisible() const noexcept
可視状態の取得
Definition mgl_ui_widget.cc:305
virtual void OnUpdate(const Vector2 &position) noexcept
更新処理
Definition mgl_ui_widget.h:255
MGL 配置情報
MGL 環境定義
MGL STLコンテナの代替
std::list< T, Allocator< T > > list
std::listの代替
Definition mgl_stl_containers.h:47
MGL タッチ状態入力定義
TouchID
タッチ識別番号の型
Definition mgl_touch_state.h:25
EventType
イベントタイプ
Definition mgl_ui_event_defs.h:24
EventState
イベントステート
Definition mgl_ui_event_defs.h:34
MGL UIイベントデリゲート
MGL UIイベントリスナー
配置情報
Definition mgl_alignment.h:21
矩形
Definition mgl_rectangle.h:20
constexpr Vector2 GetSize() const noexcept
サイズを取得
Definition mgl_rectangle.h:135
イベント結果
Definition mgl_ui_event_defs.h:58
2Dベクトル
Definition mgl_vector2.h:23