From 58be10ef0d106242a74130931033bcecc0efb736 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=B5=A9=E5=A4=A9?= <88096545+OVOAOVO@users.noreply.github.com> Date: Sun, 21 Jan 2024 16:31:02 +0800 Subject: [PATCH] add vec4 support for color picker 3/4 (#453) --- Engine/Source/Runtime/ImGui/ImGuiUtils.hpp | 40 ++++++++++++++++------ 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/Engine/Source/Runtime/ImGui/ImGuiUtils.hpp b/Engine/Source/Runtime/ImGui/ImGuiUtils.hpp index a73f2110..d5c589fd 100644 --- a/Engine/Source/Runtime/ImGui/ImGuiUtils.hpp +++ b/Engine/Source/Runtime/ImGui/ImGuiUtils.hpp @@ -263,28 +263,41 @@ static bool ImGuiTransformProperty(const char* pName, cd::Transform& value) return dirty; } -static void ColorPickerProperty(const char* Name, cd::Vec3f& veccolor) +template +static void ColorPickerProperty(const char* pName, T& color) { static std::map showMap; - if (!showMap.count(Name)) + if (!showMap.count(pName)) { - showMap[Name] = false; + showMap[pName] = false; } - ImGui::TextUnformatted(Name); + ImGui::TextUnformatted(pName); ImGui::SameLine(); ImGui::NextColumn(); - ImGui::PushID(Name); + ImGui::PushID(pName); if (ImGui::Button("...")) { - showMap[Name] = true; + showMap[pName] = true; } ImGui::PopID(); ImGui::PushItemWidth(-1); ImGui::SameLine(); ImGui::NextColumn(); - ImGui::DragFloat3("", veccolor.begin(), 0, 0.0f, 1.0f); + if constexpr (std::is_same()) + { + ImGui::DragFloat3("", color.begin(), 0, 0.0f, 1.0f); + } + else if constexpr (std::is_same()) + { + ImGui::DragFloat4("", color.begin(), 0, 0.0f, 1.0f); + } + else + { + static_assert("Unsupported color data type for ImGuiColorPickerProperty."); + } + ImGui::PopItemWidth(); - if (showMap[Name]) + if (showMap[pName]) { ImGuiIO& io = ImGui::GetIO(); ImVec2 mainWindowSize = io.DisplaySize; @@ -293,8 +306,15 @@ static void ColorPickerProperty(const char* Name, cd::Vec3f& veccolor) ImVec2 windowPos(mainWindowSize.x - offsetX, mainWindowSize.y - offsetY); ImGui::SetNextWindowPos(windowPos, ImGuiCond_Always); - ImGui::Begin(Name, &showMap[Name], ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize); - ImGui::ColorPicker3("Color Picker", veccolor.begin()); + ImGui::Begin(pName, &showMap[pName], ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize); + if constexpr (std::is_same()) + { + ImGui::ColorPicker3("Color Picker", color.begin()); + } + else if constexpr (std::is_same()) + { + ImGui::ColorPicker4("Color Picker", color.begin()); + } ImGui::End(); } ImGui::Separator();