Lagrange
tools.h
1/*
2 * Copyright 2022 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#include <lagrange/ui/api.h>
15#include <lagrange/ui/types/Tools.h>
16
17
18namespace lagrange {
19namespace ui {
20
21
22LA_UI_API Tools& get_tools(ui::Registry& r);
23LA_UI_API const Tools& get_tools(const ui::Registry& r);
24
25
26template <typename T>
27bool is_element_type(entt::id_type elem_type)
28{
29 return elem_type == entt::resolve<T>().id();
30}
31
33LA_UI_API Tools& initialize_tools(ui::Registry& r);
35LA_UI_API void run_current_tool(ui::Registry& r);
37LA_UI_API void update_previous_tool(ui::Registry& r);
38
40LA_UI_API bool is_tool_activated(const ui::Registry& r, entt::id_type tool_type);
42LA_UI_API bool is_tool_activated(const ui::Registry& r, entt::id_type tool_type, entt::id_type element_type);
43
44
46LA_UI_API bool is_tool_deactivated(const ui::Registry& r, entt::id_type tool_type);
48LA_UI_API bool is_tool_deactivated(
49 const ui::Registry& r,
50 entt::id_type tool_type,
51 entt::id_type element_type);
52
53
54template <typename ToolTag>
55bool is_tool_active(const ui::Registry& r)
56{
57 return get_tools(r).get_current_tool_type() == entt::resolve<ToolTag>().id();
58}
59
60template <typename ToolTag, typename ElementTag>
61bool is_tool_active(const ui::Registry& r)
62{
63 return is_tool_active<ToolTag>(r) &&
64 get_tools(r).get_current_element_type() == entt::resolve<ElementTag>().id();
65}
66
67template <typename ToolTag>
68bool is_tool_activated(const ui::Registry& r)
69{
70 return is_tool_activated(r, entt::resolve<ToolTag>().id());
71}
72
73template <typename ToolTag, typename ElementTag>
74bool is_tool_activated(const ui::Registry& r)
75{
76 const auto idt = entt::resolve<ToolTag>().id();
77 const auto ide = entt::resolve<ElementTag>().id();
78 return is_tool_activated(r, idt, ide);
79}
80
81template <typename ToolTag>
82bool is_tool_deactivated(const ui::Registry& r)
83{
84 return is_tool_deactivated(r, entt::resolve<ToolTag>().id());
85}
86
87template <typename ToolTag, typename ElementTag>
88bool is_tool_deactivated(const ui::Registry& r)
89{
90 const auto idt = entt::resolve<ToolTag>().id();
91 const auto ide = entt::resolve<ElementTag>().id();
92 return is_tool_deactivated(r, idt, ide);
93}
94
95} // namespace ui
96} // namespace lagrange
Lagrange UI Viewer and mini 3D engine.
Definition: AcceleratedPicking.h:22
LA_UI_API bool is_tool_activated(const ui::Registry &r, entt::id_type tool_type)
Was tool type activated this frame.
Definition: tools_utils.cpp:54
LA_UI_API Tools & initialize_tools(ui::Registry &r)
Initialize Tools context variable.
Definition: tools_utils.cpp:25
LA_UI_API void run_current_tool(ui::Registry &r)
Run currently selected tool.
Definition: tools_utils.cpp:40
LA_UI_API bool is_tool_deactivated(const ui::Registry &r, entt::id_type tool_type)
Was tool type deactivated this frame.
Definition: tools_utils.cpp:69
LA_UI_API void update_previous_tool(ui::Registry &r)
Update previously used tool - must be called for is_tool_(de)activate to work.
Definition: tools_utils.cpp:46
Main namespace for Lagrange.
Definition: AABBIGL.h:30