GaitGeneration by Graph Search
読み取り中…
検索中…
一致する文字列を見つけられません
dxlib_gui_updater.h
[詳解]
1
3
4// Copyright(c) 2023-2025 Design Engineering Laboratory, Saitama University
5// Released under the MIT license
6// https://opensource.org/licenses/mit-license.php
7
8#ifndef DESIGNLAB_DXLIB_GUI_UPDATER_H_
9#define DESIGNLAB_DXLIB_GUI_UPDATER_H_
10
11#include <map>
12#include <memory>
13#include <optional>
14
15#include "cassert_define.h"
18#include "interface_dxlib_gui.h"
20#include "mouse.h"
21
22
23namespace designlab
24{
25
27template <typename T>
28concept IsDxlibGui = std::is_base_of<IDxlibGui, T>::value;
29
31template <typename T>
32concept IsDxlibClickable = std::is_base_of<IDxlibClickable, T>::value;
33
35template <typename T>
36concept IsDxlibDraggable = std::is_base_of<IDxlibDraggable, T>::value;
37
39template <typename T>
40concept IsDxlibWheelHandler = std::is_base_of<IDxlibWheelHandler, T>::value;
41
44template <typename T>
47
48
56class DxlibGuiUpdater final
57{
58public:
59 static constexpr int kBottomPriority{ 0 };
60 static constexpr int kTopPriority{ 1000000 };
61
69 template <IsDxlibUpdatable T>
70 void Register(const std::shared_ptr<T>& gui_ptr, int priority)
71 {
72 assert(kBottomPriority <= priority);
73 assert(priority <= kTopPriority);
74
75 if constexpr (IsDxlibGui<T>)
76 {
77 RegisterGui(gui_ptr, priority);
78 }
79 if constexpr (IsDxlibClickable<T>)
80 {
81 RegisterClickable(gui_ptr, priority);
82 }
83 if constexpr (IsDxlibDraggable<T>)
84 {
85 RegisterDraggable(gui_ptr, priority);
86 }
87 if constexpr (IsDxlibWheelHandler<T>)
88 {
89 RegisterWheelHandler(gui_ptr, priority);
90 }
91 }
92
97 void OpenTerminal();
98
102 void Activate(const std::shared_ptr<const Mouse>& mouse_ptr);
103
105 void Draw() const;
106
107private:
110 struct Priority final
111 {
112 constexpr Priority(const int p, const int o) noexcept :
113 priority(p),
114 order(o)
115 {
116 }
117
120 bool operator<(const Priority& other) const noexcept
121 {
122 if (priority == other.priority)
123 {
124 return order < other.order;
125 }
126 else
127 {
128 return priority < other.priority;
129 }
130 }
131
132 int priority{ 0 };
133 int order{ 0 };
134 };
135
136 void RegisterGui(const std::shared_ptr<IDxlibGui> gui_ptr, int priority);
137 void RegisterClickable(
138 const std::shared_ptr<IDxlibClickable> clickable_ptr, int priority);
139 void RegisterDraggable(
140 const std::shared_ptr<IDxlibDraggable> draggable_ptr, int priority);
141 void RegisterWheelHandler(
142 const std::shared_ptr<IDxlibWheelHandler> wheel_handler_ptr, int priority);
143
144 void UpdateGui();
145
146 void ActivateClickable(const std::shared_ptr<const Mouse> mouse_ptr);
147 void ActivateDraggable(const std::shared_ptr<const Mouse> mouse_ptr);
148 void ActivateWheelHandler(const std::shared_ptr<const Mouse> mouse_ptr);
149
150 std::map<Priority, std::shared_ptr<IDxlibGui> > gui_ptrs_;
151 std::map<Priority, std::shared_ptr<IDxlibClickable> > clickable_ptrs_;
152 std::map<Priority, std::shared_ptr<IDxlibDraggable> > draggable_ptrs_;
153 std::map<Priority, std::shared_ptr<IDxlibWheelHandler> > wheel_handler_ptrs_;
154
156 std::optional<Priority> now_dragging_gui_key_{ std::nullopt };
157
158 bool is_terminal_opened_{ false };
159};
160
161} // namespace designlab
162
163
164#endif // DESIGNLAB_DXLIB_GUI_UPDATER_H_
クリック判定を行うクラス.
void Register(const std::shared_ptr< T > &gui_ptr, int priority)
UpdateとDrawを行うGUIを登録する. IDxlibClickableまたは,IDxlibDraggable, IDxlibWheelHandlerを継承している場合は,それらも同時に登録す...
void OpenTerminal()
Terminalを開く. 他のGUIをRegisterした後に呼び出すこと. 2回目以降の呼び出しは無視される. また,Terminalは最も優先度が高い.
static constexpr int kBottomPriority
最も優先度が低い.
void Draw() const
登録済みのGUIのDraw関数を実行する.
void Activate(const std::shared_ptr< const Mouse > &mouse_ptr)
GUIのUpdate関数を実行し,クリック,ドラッグなどの判定を行う. 優先度の高いものから順に各種判定を行う.
static constexpr int kTopPriority
最も優先的に処理される.
IDxlibClickableを継承しているかどうかを判定する.
IDxlibDraggableを継承しているかどうかを判定する.
IDxlibGuiを継承しているかどうかを判定する.
IDxlibGui, IDxlibClickable, IDxlibDraggable, IDxlibWheelHandlerのうちいずれかを継承しているかどうかを判定する.
IDxlibWheelHandlerを継承しているかどうかを判定する.