24 if (is_terminal_opened_)
30 std::vector<std::shared_ptr<IDxlibGui> > gui_list;
32 for (
const auto& i : gui_ptrs_)
34 gui_list.push_back(i.second);
38 const auto terminal_ptr = std::make_shared<DxlibGuiTerminal>(gui_list);
41 RegisterGui(terminal_ptr, terminal_priority);
42 RegisterClickable(terminal_ptr, terminal_priority);
44 is_terminal_opened_ =
true;
49 assert(mouse_ptr !=
nullptr);
52 ActivateClickable(mouse_ptr);
53 ActivateDraggable(mouse_ptr);
54 ActivateWheelHandler(mouse_ptr);
60 for (
auto i = gui_ptrs_.begin(); i != gui_ptrs_.end(); ++i)
62 if ((*i).second->IsVisible())
70void DxlibGuiUpdater::RegisterGui(
71 const std::shared_ptr<IDxlibGui> gui_ptr,
int priority)
73 assert(gui_ptr !=
nullptr);
76 for (
const auto& i : gui_ptrs_)
78 if (i.second == gui_ptr)
85 Priority p{ priority, 0 };
87 while (gui_ptrs_.find(p) != gui_ptrs_.end())
93 gui_ptrs_[p] = gui_ptr;
96void DxlibGuiUpdater::RegisterClickable(
97 const std::shared_ptr<IDxlibClickable> clickable_ptr,
int priority)
99 assert(clickable_ptr !=
nullptr);
102 for (
const auto& i : clickable_ptrs_)
104 if (i.second == clickable_ptr)
111 Priority p{ priority, 0 };
113 while (clickable_ptrs_.find(p) != clickable_ptrs_.end())
119 clickable_ptrs_[p] = clickable_ptr;
122void DxlibGuiUpdater::RegisterDraggable(
123 const std::shared_ptr<IDxlibDraggable> draggable_ptr,
int priority)
125 assert(draggable_ptr !=
nullptr);
128 for (
const auto& i : draggable_ptrs_)
130 if (i.second == draggable_ptr)
137 Priority p{ priority, 0 };
139 while (draggable_ptrs_.find(p) != draggable_ptrs_.end())
145 draggable_ptrs_[p] = draggable_ptr;
148void DxlibGuiUpdater::RegisterWheelHandler(
149 const std::shared_ptr<IDxlibWheelHandler> wheel_handler_ptr,
int priority)
151 assert(wheel_handler_ptr !=
nullptr);
154 for (
const auto& i : wheel_handler_ptrs_)
156 if (i.second == wheel_handler_ptr)
163 Priority p{ priority, 0 };
165 while (wheel_handler_ptrs_.find(p) != wheel_handler_ptrs_.end())
171 wheel_handler_ptrs_[p] = wheel_handler_ptr;
174void DxlibGuiUpdater::UpdateGui()
177 for (
auto i = gui_ptrs_.rbegin(); i != gui_ptrs_.rend(); ++i)
179 (*i).second->Update();
183void DxlibGuiUpdater::ActivateClickable(
const std::shared_ptr<const Mouse> mouse_ptr)
188 for (
auto i = clickable_ptrs_.rbegin(); i != clickable_ptrs_.rend(); ++i)
190 if ((*i).second->CursorOnGui(
191 mouse_ptr->GetCursorPosX(),
192 mouse_ptr->GetCursorPosY()))
194 (*i).second->ClickedAction({
195 .cursor_x = mouse_ptr->GetCursorPosX(),
196 .cursor_y = mouse_ptr->GetCursorPosY(),
197 .left_pushing_count =
198 mouse_ptr->GetPressingCount(MOUSE_INPUT_LEFT),
199 .middle_pushing_count =
200 mouse_ptr->GetReleasingCount(MOUSE_INPUT_MIDDLE),
201 .right_pushing_count =
202 mouse_ptr->GetPressingCount(MOUSE_INPUT_RIGHT) });
209void DxlibGuiUpdater::ActivateDraggable(
const std::shared_ptr<const Mouse> mouse_ptr)
211 unsigned int mouse_key{ 0 };
212 int pressing_count{ 0 };
213 std::array<unsigned int, 3> mouse_keys = {
214 MOUSE_INPUT_LEFT, MOUSE_INPUT_MIDDLE, MOUSE_INPUT_RIGHT };
216 for (
auto i : mouse_keys)
218 if (mouse_ptr->GetPressingCount(i) > 0)
222 (std::max)(mouse_ptr->GetPressingCount(i), pressing_count);
227 if (pressing_count == 0)
230 for (
auto& i : draggable_ptrs_)
232 i.second->SetDragged(
false);
235 now_dragging_gui_key_ = std::nullopt;
237 else if (pressing_count == 1)
240 for (
auto i = draggable_ptrs_.rbegin(); i != draggable_ptrs_.rend(); ++i)
242 if ((*i).second->IsDraggable(
243 mouse_ptr->GetCursorPosX(),
244 mouse_ptr->GetCursorPosY()))
246 (*i).second->SetDragged(
true);
247 now_dragging_gui_key_ = (*i).first;
252 else if (pressing_count > 0)
255 if (now_dragging_gui_key_.has_value() &&
256 draggable_ptrs_.count(now_dragging_gui_key_.value()) == 1)
258 draggable_ptrs_[now_dragging_gui_key_.value()]->DraggedAction(
259 mouse_ptr->GetDiffPosX(), mouse_ptr->GetDiffPosY(), mouse_key);
268void DxlibGuiUpdater::ActivateWheelHandler(
269 const std::shared_ptr<const Mouse> mouse_ptr)
271 if (mouse_ptr->GetWheelRot() == 0) {
return; }
276 for (
auto i = wheel_handler_ptrs_.rbegin(); i != wheel_handler_ptrs_.rend(); ++i)
278 if ((*i).second->CanHandleWheel(
279 mouse_ptr->GetCursorPosX(),
280 mouse_ptr->GetCursorPosY()))
282 (*i).second->RotMouseWheel(mouse_ptr->GetWheelRot());
void OpenTerminal()
Terminalを開く. 他のGUIをRegisterした後に呼び出すこと. 2回目以降の呼び出しは無視される. また,Terminalは最も優先度が高い.
void Draw() const
登録済みのGUIのDraw関数を実行する.
void Activate(const std::shared_ptr< const Mouse > &mouse_ptr)
GUIのUpdate関数を実行し,クリック,ドラッグなどの判定を行う. 優先度の高いものから順に各種判定を行う.
static constexpr int kTopPriority
最も優先的に処理される.