summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-05-26 06:35:28 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-05-26 06:35:28 +0200
commitc2da6e265b059cc21fd1aa9f1e975f99a940d6a3 (patch)
treec4d52e3fbef719f5b0b0676d3b25e45f93c2f5e7
parent9a9c253cd7fad715740bfa0c722a8b17015cc95a (diff)
editor/inspect: add widget for color types
-rw-r--r--editor/inspect-types.cpp8
-rw-r--r--editor/inspect.cpp15
2 files changed, 19 insertions, 4 deletions
diff --git a/editor/inspect-types.cpp b/editor/inspect-types.cpp
index 421194bc..9465b4af 100644
--- a/editor/inspect-types.cpp
+++ b/editor/inspect-types.cpp
@@ -205,10 +205,10 @@ struct entity_accessors<light> {
using E = Entity<light>;
auto tuple0 = entity_accessors<entity>::accessors();
auto tuple = std::tuple{
- E::type<Vector3ub>::field{"color"_s,
- [](const light& x) { return Vector3ub(x.color); },
- [](light& x, Vector3ub value) { x.color = Color3ub{value}; },
- constantly(constraints::range<Vector3ub>{{0, 0, 0}, {255, 255, 255}}),
+ E::type<Color3ub>::field{"color"_s,
+ [](const light& x) { return x.color; },
+ [](light& x, Color3ub value) { x.color = value; },
+ constantly(constraints::range<Color3ub>{{0, 0, 0}, {255, 255, 255}}),
},
E::type<light_falloff>::field{"falloff"_s,
[](const light& x) { return x.falloff; },
diff --git a/editor/inspect.cpp b/editor/inspect.cpp
index 0b707882..bfd2e3dc 100644
--- a/editor/inspect.cpp
+++ b/editor/inspect.cpp
@@ -10,6 +10,7 @@
#include <Magnum/Math/Vector2.h>
#include <Magnum/Math/Vector3.h>
#include <Magnum/Math/Vector4.h>
+#include <Magnum/Math/Color.h>
#include <algorithm>
namespace floormat::entities {
@@ -96,6 +97,18 @@ bool do_inspect_field(void* datum, const erased_accessor& accessor, field_repr r
}
else if constexpr(std::is_same_v<T, bool>)
ret = ImGui::Checkbox(label, &value);
+ else if constexpr (std::is_same_v<T, Color3ub>)
+ {
+ auto vec = Vector3(value) * (1.f/255);
+ ret = ImGui::ColorEdit3(label, vec.data());
+ value = Color3ub(vec * 255);
+ }
+ else if constexpr (std::is_same_v<T, Color4ub>)
+ {
+ auto vec = Vector4(value) * (1.f/255);
+ ret = ImGui::ColorEdit4(label, vec.data());
+ value = Color4ub(vec * 255);
+ }
else if constexpr (!Math::IsVector<T>())
{
auto [min, max] = accessor.get_range(datum).convert<T>();
@@ -214,5 +227,7 @@ MAKE_SPEC_REPRS2(float)
MAKE_SPEC(bool, field_repr::input)
MAKE_SPEC(String, field_repr::input)
MAKE_SPEC(StringView, field_repr::input)
+MAKE_SPEC(Color3ub, field_repr::input)
+MAKE_SPEC(Color4ub, field_repr::input)
} // namespace floormat::entities