Lagrange
Loading...
Searching...
No Matches
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
43is_tool_activated(const ui::Registry& r, entt::id_type tool_type, entt::id_type element_type);
44
45
47LA_UI_API bool is_tool_deactivated(const ui::Registry& r, entt::id_type tool_type);
49LA_UI_API bool
50is_tool_deactivated(const ui::Registry& r, entt::id_type tool_type, entt::id_type element_type);
51
52
53template <typename ToolTag>
54bool is_tool_active(const ui::Registry& r)
55{
56 return get_tools(r).get_current_tool_type() == entt::resolve<ToolTag>().id();
57}
58
59template <typename ToolTag, typename ElementTag>
60bool is_tool_active(const ui::Registry& r)
61{
62 return is_tool_active<ToolTag>(r) &&
63 get_tools(r).get_current_element_type() == entt::resolve<ElementTag>().id();
64}
65
66template <typename ToolTag>
67bool is_tool_activated(const ui::Registry& r)
68{
69 return is_tool_activated(r, entt::resolve<ToolTag>().id());
70}
71
72template <typename ToolTag, typename ElementTag>
73bool is_tool_activated(const ui::Registry& r)
74{
75 const auto idt = entt::resolve<ToolTag>().id();
76 const auto ide = entt::resolve<ElementTag>().id();
77 return is_tool_activated(r, idt, ide);
78}
79
80template <typename ToolTag>
81bool is_tool_deactivated(const ui::Registry& r)
82{
83 return is_tool_deactivated(r, entt::resolve<ToolTag>().id());
84}
85
86template <typename ToolTag, typename ElementTag>
87bool is_tool_deactivated(const ui::Registry& r)
88{
89 const auto idt = entt::resolve<ToolTag>().id();
90 const auto ide = entt::resolve<ElementTag>().id();
91 return is_tool_deactivated(r, idt, ide);
92}
93
94} // namespace ui
95} // namespace lagrange
Definition Tools.h:42
Lagrange UI Viewer and mini 3D engine.
Definition AcceleratedPicking.h:23
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.