Unravel Engine C++ Reference
Loading...
Searching...
No Matches
inspector_physics_shape.cpp
Go to the documentation of this file.
2#include "imgui/imgui.h"
3#include "inspectors.h"
4
5namespace unravel
6{
7
9 entt::meta_any& var,
10 const meta_any_proxy& var_proxy,
11 const var_info& info,
12 const entt::meta_custom& custom) -> inspect_result
13{
14 auto& data = var.cast<physics_compound_shape&>();
15
16 inspect_result result{};
17
18 auto variant_types = entt::get_attribute_as<std::vector<entt::meta_type>>(var.type().custom(), "variant_types");
19
20 size_t item_current_idx = data.shape.index();
21
22 const auto& combo_preview_value = variant_types[item_current_idx];
23
24 auto name = entt::get_pretty_name(combo_preview_value);
25
26 if(ImGui::BeginCombo("##Type", name.c_str()))
27 {
28 for(int n = 0; n < variant_types.size(); n++)
29 {
30 const bool is_selected = (item_current_idx == n);
31
32 auto name = entt::get_pretty_name(variant_types[n]);
33
34 if(ImGui::Selectable(name.c_str(), is_selected))
35 {
36 item_current_idx = n;
37 result.changed = true;
38 }
39
40 result.edit_finished |= ImGui::IsItemDeactivatedAfterEdit();
41
42
43 ImGui::DrawItemActivityOutline();
44
45
46 if(is_selected)
47 ImGui::SetItemDefaultFocus();
48 }
49 ImGui::EndCombo();
50 }
51 result.edit_finished |= ImGui::IsItemDeactivatedAfterEdit();
52
53 ImGui::DrawItemActivityOutline();
54
55 property_layout::get_current()->pop_layout();
56
57 if(result.changed)
58 {
59 const auto type = variant_types[item_current_idx];
60 if(type == entt::resolve<physics_box_shape>())
61 {
62 data.shape = physics_box_shape{};
63 }
64 else if(type == entt::resolve<physics_sphere_shape>())
65 {
66 data.shape = physics_sphere_shape{};
67 }
68 else if(type == entt::resolve<physics_capsule_shape>())
69 {
70 data.shape = physics_capsule_shape{};
71 }
72 else if(type == entt::resolve<physics_cylinder_shape>())
73 {
74 data.shape = physics_cylinder_shape{};
75 }
76 }
77
78 if(hpp::holds_alternative<physics_box_shape>(data.shape))
79 {
80 auto& shape = hpp::get<physics_box_shape>(data.shape);
81 result |= ::unravel::inspect(ctx, shape);
82 }
83 else if(hpp::holds_alternative<physics_sphere_shape>(data.shape))
84 {
85 auto& shape = hpp::get<physics_sphere_shape>(data.shape);
86 result |= ::unravel::inspect(ctx, shape);
87 }
88 else if(hpp::holds_alternative<physics_capsule_shape>(data.shape))
89 {
90 auto& shape = hpp::get<physics_capsule_shape>(data.shape);
91 result |= ::unravel::inspect(ctx, shape);
92 }
93 else if(hpp::holds_alternative<physics_cylinder_shape>(data.shape))
94 {
95 auto& shape = hpp::get<physics_cylinder_shape>(data.shape);
96 result |= ::unravel::inspect(ctx, shape);
97 }
98 else
99 {
100 ImGui::LabelText("Unknown", "%s", "test");
101 }
102
103 return result;
104}
105
106} // namespace unravel
manifold_type type
static auto get_current() -> property_layout *
Gets the currently active property layout from the global stack.
Definition inspector.cpp:20
std::string name
Definition hub.cpp:27
auto get_pretty_name(const meta_type &t) -> std::string
auto get_attribute_as(const meta_custom &custom, const char *name) -> T
Definition reflection.h:24
auto inspect(rtti::context &ctx, T &obj) -> inspect_result
Convenience template function for inspecting objects of known type.
Definition inspectors.h:393
Result of an inspection operation indicating what changes occurred.
Definition inspector.h:146
auto inspect(rtti::context &ctx, entt::meta_any &var, const meta_any_proxy &var_proxy, const var_info &info, const entt::meta_custom &custom) -> inspect_result override
Safe deferred property access proxy for arbitrary object properties.
Definition inspector.h:198
Represents a box shape for physics calculations.
Represents a capsule shape for physics calculations.
Represents a compound shape that can contain multiple types of shapes.
Represents a cylinder shape for physics calculations.
Represents a sphere shape for physics calculations.
Metadata about a variable being inspected.
Definition inspector.h:133