diff --git a/src/GUI/CMakeLists.txt b/src/GUI/CMakeLists.txt index cab7722..7b8cf0b 100644 --- a/src/GUI/CMakeLists.txt +++ b/src/GUI/CMakeLists.txt @@ -17,3 +17,5 @@ target_sources( ${CMAKE_CURRENT_SOURCE_DIR}/SideBar.cpp ${CMAKE_CURRENT_SOURCE_DIR}/SettingsPanel.cpp ) + +add_subdirectory(Components) diff --git a/src/GUI/Components/CMakeLists.txt b/src/GUI/Components/CMakeLists.txt new file mode 100644 index 0000000..6c1faab --- /dev/null +++ b/src/GUI/Components/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.27) + +target_sources( + ${PROJECT_NAME} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/CustomColorPicker.cpp +) diff --git a/src/GUI/Components/CustomColorPicker.cpp b/src/GUI/Components/CustomColorPicker.cpp new file mode 100644 index 0000000..572e428 --- /dev/null +++ b/src/GUI/Components/CustomColorPicker.cpp @@ -0,0 +1,67 @@ +#include "Imgui.hpp" +#include "imgui.h" + +namespace Xash +{ + namespace GUI + { + static bool colorLabelClickable(const std::string_view label, const ImVec4 &color) + { + bool isClicked = false; + + ImGui::ColorButton("##ColorPreview", color, ImGuiColorEditFlags_NoPicker); + if (ImGui::IsItemClicked()) + { + isClicked = true; + } + ImGui::SameLine(); + ImGui::Text("%s", label.data()); + if (ImGui::IsItemClicked()) + { + isClicked = true; + } + return isClicked; + } + + static bool drawPopup(const std::string_view label, ImVec4 &color) + { + if (ImGui::BeginPopup(label.data())) + { + ImGui::ColorPicker4( + "##ColorPicker", (float *)&color, + ImGuiColorEditFlags_DisplayRGB | ImGuiColorEditFlags_NoInputs + | ImGuiColorEditFlags_NoSidePreview + ); + // Slider for each color component + ImGui::SliderFloat("##Red", &color.x, 0.0f, 1.0f, "R: %.3f"); + ImGui::SliderFloat("##Green", &color.y, 0.0f, 1.0f, "G: %.3f"); + ImGui::SliderFloat("##Blue", &color.z, 0.0f, 1.0f, "B: %.3f"); + ImGui::SliderFloat("##Alpha", &color.w, 0.0f, 1.0f, "A: %.3f"); + return true; + } + return false; + } + + void Imgui::CustomColorPicker( + const std::string_view label, std::function getter, + std::function setter, ImGuiCol_ colorIndex + ) + { + const auto &settingColor = getter(); + ImVec4 color{settingColor.x, settingColor.y, settingColor.z, settingColor.w}; + bool isClicked = colorLabelClickable(label, color); + + if (isClicked) + { + ImGui::OpenPopup(label.data()); + } + if (drawPopup(label, color)) + { + ImGui::GetStyle().Colors[colorIndex] = + ImVec4(color.x, color.y, color.z, color.w); + setter({color.x, color.y, color.z, color.w}); + ImGui::EndPopup(); + } + } + } // namespace GUI +} // namespace Xash diff --git a/src/GUI/Imgui.hpp b/src/GUI/Imgui.hpp index c068561..2b60d10 100644 --- a/src/GUI/Imgui.hpp +++ b/src/GUI/Imgui.hpp @@ -6,9 +6,11 @@ #include #include #include +#include #include "ModInfos.hpp" #include "MonoModule.hpp" #include "imgui.h" +#include "StyleSettings.hpp" namespace Xash { @@ -29,6 +31,12 @@ namespace Xash void Draw(); void Render(); + // Custom ImGui Widgets + static void CustomColorPicker( + const std::string_view label, std::function getter, + std::function setter, ImGuiCol_ colorIndex + ); + private: enum class ActivePanel : uint8_t { diff --git a/src/settings/CMakeLists.txt b/src/settings/CMakeLists.txt new file mode 100644 index 0000000..55df413 --- /dev/null +++ b/src/settings/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.27) + +target_include_directories( + ${PROJECT_NAME} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_sources( + ${PROJECT_NAME} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/XashSettings.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/StyleSettings.cpp +)