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 MGL::Vector2 &offset = MGL::Vector2(0.0f, 0.0f), bool updateEvent = true) noexcept;
44 void Render(const MGL::Vector2 &offset = MGL::Vector2(0.0f, 0.0f)) noexcept;
45
46 /* ------------------------------------------------------------------------- */
51 /* ------------------------------------------------------------------------- */
52 void Update(bool updateEvent) noexcept
53 {
54 Update(MGL::Vector2(), updateEvent);
55 }
56
57 /* ------------------------------------------------------------------------- */
62 /* ------------------------------------------------------------------------- */
63 [[nodiscard]] virtual MGL::Rectangle GetRectangle() const noexcept = 0;
64
65 /* ------------------------------------------------------------------------- */
70 /* ------------------------------------------------------------------------- */
71 [[nodiscard]] constexpr uint32_t GetTypeIdentifier() const noexcept
72 {
73 return _typeIdentifier;
74 }
75
76 void SetVisible(bool isVisible) noexcept;
77 [[nodiscard]] bool IsVisible() const noexcept;
78
79 /* ------------------------------------------------------------------------- */
84 /* ------------------------------------------------------------------------- */
85 [[nodiscard]] constexpr bool GetLocalVisibleFlag() const noexcept
86 {
87 return _isVisible;
88 }
89
90 /* ------------------------------------------------------------------------- */
95 /* ------------------------------------------------------------------------- */
96 constexpr void SetTransparency(float transparency) noexcept
97 {
98 _transparency = transparency;
99 }
100
101 /* ------------------------------------------------------------------------- */
106 /* ------------------------------------------------------------------------- */
107 [[nodiscard]] constexpr float GetLocalTransparency() const noexcept
108 {
109 return _transparency;
110 }
111
112 [[nodiscard]] float GetTransparency() const noexcept;
113
114 [[nodiscard]] MGL::Vector2 GetPosition() const noexcept;
115
116 /* ------------------------------------------------------------------------- */
121 /* ------------------------------------------------------------------------- */
122 [[nodiscard]] constexpr MGL::Vector2 GetSize() const noexcept
123 {
124 return GetRectangle().GetSize();
125 }
126
127 [[nodiscard]] MGL::Vector2 GetParentSize() const noexcept;
128
129 bool AddChild(Widget *child) noexcept;
130 bool RemoveChild(Widget *child) noexcept;
131
132 /* ------------------------------------------------------------------------- */
137 /* ------------------------------------------------------------------------- */
138 [[nodiscard]] const Widget *GetParent() const noexcept
139 {
140 return _parent;
141 }
142
143 /* ------------------------------------------------------------------------- */
148 /* ------------------------------------------------------------------------- */
149 [[nodiscard]] const MGL::STL::list<Widget *> &GetChildren() const noexcept
150 {
151 return _children;
152 }
153
154 bool ActivateEventContext(EventListener *listener, EventDelegate *delegate) noexcept;
155 bool ActivateEventContext(EventListener *listener) noexcept;
156
157 /* ------------------------------------------------------------------------- */
162 /* ------------------------------------------------------------------------- */
163 constexpr void SetEventIdentifier(EventID identifier) noexcept
164 {
165 _eventIdentifier = identifier;
166 }
167
168 /* ------------------------------------------------------------------------- */
173 /* ------------------------------------------------------------------------- */
174 [[nodiscard]] constexpr EventID GetEventIdentifier() const noexcept
175 {
176 return _eventIdentifier;
177 }
178
179 /* ------------------------------------------------------------------------- */
184 /* ------------------------------------------------------------------------- */
185 constexpr void SetPivot(const MGL::Alignment &pivotAlignment) noexcept
186 {
187 _pivotAlignment = pivotAlignment;
188 }
189
190 /* ------------------------------------------------------------------------- */
195 /* ------------------------------------------------------------------------- */
196 [[nodiscard]] constexpr const MGL::Alignment &GetPivot() const noexcept
197 {
198 return _pivotAlignment;
199 }
200
201 /* ------------------------------------------------------------------------- */
206 /* ------------------------------------------------------------------------- */
207 constexpr void SetAnchor(const MGL::Alignment &anchorAlignment) noexcept
208 {
209 _anchorAlignment = anchorAlignment;
210 }
211
212 /* ------------------------------------------------------------------------- */
217 /* ------------------------------------------------------------------------- */
218 [[nodiscard]] constexpr const MGL::Alignment &GetAnchor() const noexcept
219 {
220 return _anchorAlignment;
221 }
222
223 /* ------------------------------------------------------------------------- */
228 /* ------------------------------------------------------------------------- */
229 [[nodiscard]] constexpr EventState GetEventState() const noexcept
230 {
231 return _eventState;
232 }
233
234 /* ------------------------------------------------------------------------- */
239 /* ------------------------------------------------------------------------- */
240 [[nodiscard]] constexpr MGL::Input::TouchID GetEventTouchID() const noexcept
241 {
242 return _eventTouchID;
243 }
244
245protected:
246 /* ------------------------------------------------------------------------- */
251 /* ------------------------------------------------------------------------- */
252 virtual void OnUpdate(const MGL::Vector2 &position) noexcept
253 {
254 (void)position;
255 }
256
257 /* ------------------------------------------------------------------------- */
262 /* ------------------------------------------------------------------------- */
263 virtual void OnRender(const MGL::Vector2 &position) noexcept
264 {
265 (void)position;
266 }
267
268 /* ------------------------------------------------------------------------- */
273 /* ------------------------------------------------------------------------- */
274 virtual void OnNotifiedEvent(EventType eventType, uint32_t argument) noexcept
275 {
276 (void)eventType;
277 (void)argument;
278 }
279
280private:
281 void UpdateEvent(EventContext *eventContext, const MGL::Vector2 &offset) noexcept;
282 void ApplyEventResult(EventContext *eventContext, const EventResult &result) noexcept;
283 void SendEvent(EventContext *eventContext, EventType eventType, uint32_t argument = 0, MGL::Input::TouchID touchID = MGL::Input::TouchID::Invalid) noexcept;
284
285 [[nodiscard]] MGL::Vector2 GetAdjustedPosition() const noexcept;
286
287 uint32_t _typeIdentifier;
288
289 Widget *_parent{nullptr};
290 MGL::STL::list<Widget *> _children;
291
292 bool _isVisible{true};
293 float _transparency{1.0f};
294
295 MGL::STL::unique_ptr<EventContext> _eventContext{nullptr};
296 EventState _eventState{EventState::None};
297 EventID _eventIdentifier{kInvalidEventID};
298 MGL::Input::TouchID _eventTouchID{MGL::Input::TouchID::Invalid};
299
300 MGL::Alignment _pivotAlignment;
301 MGL::Alignment _anchorAlignment;
302};
303
304/* ------------------------------------------------------------------------- */
309/* ------------------------------------------------------------------------- */
310template<typename Type>
311class TypedWidget : public Widget
312{
313public:
314 /* ------------------------------------------------------------------------- */
319 /* ------------------------------------------------------------------------- */
320 TypedWidget(Type type) noexcept
321 : Widget(static_cast<uint32_t>(type))
322 {
323 }
324
325 ~TypedWidget() noexcept override = default;
326
327 /* ------------------------------------------------------------------------- */
332 /* ------------------------------------------------------------------------- */
333 constexpr Type GetType() const noexcept
334 {
335 return static_cast<Type>(GetTypeIdentifier());
336 }
337};
338} // namespace MGL::UI
339
340#endif // INCGUARD_MGL_UI_WIDGET_H_1625439573
341
342// 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:312
TypedWidget(Type type) noexcept
コンストラクタ
Definition mgl_ui_widget.h:320
constexpr Type GetType() const noexcept
識別子を取得
Definition mgl_ui_widget.h:333
UIウィジットクラス
Definition mgl_ui_widget.h:29
constexpr EventState GetEventState() const noexcept
イベントのステートを取得
Definition mgl_ui_widget.h:229
virtual void OnNotifiedEvent(EventType eventType, uint32_t argument) noexcept
イベント通知後の処理
Definition mgl_ui_widget.h:274
bool AddChild(Widget *child) noexcept
子ウィジットの追加
Definition mgl_ui_widget.cc:387
virtual MGL::Rectangle GetRectangle() const noexcept=0
矩形の取得
bool ActivateEventContext(EventListener *listener, EventDelegate *delegate) noexcept
イベントコンテキストのアクティベート
Definition mgl_ui_widget.cc:212
const Widget * GetParent() const noexcept
親ウィジットの取得
Definition mgl_ui_widget.h:138
void Update(const MGL::Vector2 &offset=MGL::Vector2(0.0f, 0.0f), bool updateEvent=true) noexcept
更新処理
Definition mgl_ui_widget.cc:24
constexpr void SetAnchor(const MGL::Alignment &anchorAlignment) noexcept
ウィジットのアンカーを設定
Definition mgl_ui_widget.h:207
virtual void OnRender(const MGL::Vector2 &position) noexcept
描画処理
Definition mgl_ui_widget.h:263
float GetTransparency() const noexcept
透過値の取得
Definition mgl_ui_widget.cc:328
virtual void OnUpdate(const MGL::Vector2 &position) noexcept
更新処理
Definition mgl_ui_widget.h:252
void SetVisible(bool isVisible) noexcept
可視状態の設定
Definition mgl_ui_widget.cc:275
constexpr MGL::Vector2 GetSize() const noexcept
サイズを取得
Definition mgl_ui_widget.h:122
constexpr void SetTransparency(float transparency) noexcept
透過値の設定
Definition mgl_ui_widget.h:96
Widget(uint32_t typeIdentifier) noexcept
コンストラクタ
Definition mgl_ui_widget.h:36
MGL::Vector2 GetPosition() const noexcept
位置を取得
Definition mgl_ui_widget.cc:366
bool RemoveChild(Widget *child) noexcept
子ウィジットの削除
Definition mgl_ui_widget.cc:410
constexpr MGL::Input::TouchID GetEventTouchID() const noexcept
イベントのタッチIDを取得
Definition mgl_ui_widget.h:240
constexpr bool GetLocalVisibleFlag() const noexcept
このウィジットに設定された可視状態のフラグを取得
Definition mgl_ui_widget.h:85
constexpr void SetPivot(const MGL::Alignment &pivotAlignment) noexcept
ウィジットの中心アライメントを設定
Definition mgl_ui_widget.h:185
constexpr void SetEventIdentifier(EventID identifier) noexcept
イベントIDを設定
Definition mgl_ui_widget.h:163
constexpr EventID GetEventIdentifier() const noexcept
イベントIDを取得
Definition mgl_ui_widget.h:174
MGL::Vector2 GetParentSize() const noexcept
親のサイズを取得
Definition mgl_ui_widget.cc:349
constexpr uint32_t GetTypeIdentifier() const noexcept
ウィジットの種類の識別子を取得
Definition mgl_ui_widget.h:71
constexpr const MGL::Alignment & GetAnchor() const noexcept
ウィジットのアンカー取得
Definition mgl_ui_widget.h:218
constexpr float GetLocalTransparency() const noexcept
このウィジットに設定された透過値の設定
Definition mgl_ui_widget.h:107
const MGL::STL::list< Widget * > & GetChildren() const noexcept
子ウィジットの取得
Definition mgl_ui_widget.h:149
constexpr const MGL::Alignment & GetPivot() const noexcept
ウィジットの中心アライメントを取得
Definition mgl_ui_widget.h:196
bool IsVisible() const noexcept
可視状態の取得
Definition mgl_ui_widget.cc:306
MGL 配置情報
MGL 環境定義
MGL STLコンテナの代替
std::list< T, Allocator< T > > list
std::listの代替
Definition mgl_stl_containers.h:47
std::unique_ptr< T, Deleter > unique_ptr
MGLのアロケータを利用するユニークポインタ
Definition mgl_stl_memory.h:247
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