Lagrange
selection.h
1/*
2 * Copyright 2021 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/Entity.h>
16#include <lagrange/ui/components/Selection.h>
17#include <lagrange/ui/components/SelectionContext.h>
18
19namespace lagrange {
20namespace ui {
21
22class Keybinds;
23
24
25LA_UI_API bool deselect_all(Registry& registry);
26LA_UI_API bool dehover_all(Registry& registry);
27
28
29inline bool is_selected(const Registry& registry, Entity e)
30{
31 return registry.all_of<Selected>(e);
32}
33
34inline bool is_hovered(const Registry& registry, Entity e)
35{
36 return registry.all_of<Hovered>(e);
37}
38
39inline decltype(auto) selected_view(Registry& registry)
40{
41 return registry.view<Selected>();
42}
43
44inline decltype(auto) hovered_view(Registry& registry)
45{
46 return registry.view<Hovered>();
47}
48
49LA_UI_API bool is_child_selected(const Registry& registry, Entity e, bool recursive = true);
50LA_UI_API bool is_child_hovered(const Registry& registry, Entity e, bool recursive = true);
51
52
53LA_UI_API std::vector<Entity> collect_selected(const Registry& registry);
54LA_UI_API std::vector<Entity> collect_hovered(const Registry& registry);
55
56
57LA_UI_API bool set_selected(
58 Registry& registry,
59 Entity e,
60 SelectionBehavior behavior = SelectionBehavior::SET);
61
62LA_UI_API bool set_hovered(Registry& registry, Entity e, SelectionBehavior behavior = SelectionBehavior::SET);
63
64LA_UI_API bool select(Registry& registry, Entity e);
65
66LA_UI_API bool deselect(Registry& registry, Entity e);
67
68LA_UI_API bool hover(Registry& registry, Entity e);
69
70LA_UI_API bool dehover(Registry& registry, Entity e);
71
72
73LA_UI_API SelectionContext& get_selection_context(Registry& r);
74
75LA_UI_API const SelectionContext& get_selection_context(const Registry& r);
76
77/* Utils*/
78
79LA_UI_API SelectionBehavior selection_behavior(const Keybinds& keybinds);
80LA_UI_API bool are_selection_keys_down(const Keybinds& keybinds);
81LA_UI_API bool are_selection_keys_pressed(const Keybinds& keybinds);
82LA_UI_API bool are_selection_keys_released(const Keybinds& keybinds);
83
84
85LA_UI_API SelectionBehavior selection_behavior(const Registry& r);
86LA_UI_API bool are_selection_keys_down(const Registry& r);
87LA_UI_API bool are_selection_keys_pressed(const Registry& r);
88LA_UI_API bool are_selection_keys_released(const Registry& r);
89
90
91} // namespace ui
92} // namespace lagrange
Lagrange UI Viewer and mini 3D engine.
Definition: AcceleratedPicking.h:22
Main namespace for Lagrange.
Definition: AABBIGL.h:30