HistogramGroup.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #ifdef IMGUI_ENABLED
  10. #include <AzCore/Math/Color.h>
  11. #include <AzCore/std/containers/vector.h>
  12. #include <AzCore/std/containers/unordered_map.h>
  13. #include <imgui/imgui.h>
  14. #include <LYImGuiUtils/HistogramContainer.h>
  15. namespace ImGui::LYImGuiUtils
  16. {
  17. //! Helper for a group containing several histograms.
  18. //! The group is shown using collapsible header.
  19. class HistogramGroup
  20. {
  21. public:
  22. HistogramGroup() = default;
  23. HistogramGroup(const char* name, int histogramBinCount);
  24. void OnImGuiUpdate();
  25. void PushHistogramValue(const char* valueName, float value, const AZ::Color& color);
  26. const char* GetName() const { return m_name.c_str(); }
  27. const AZStd::string& GetNameString() const { return m_name; }
  28. void SetName(AZStd::string name) { m_name = name; }
  29. void SetHistogramBinCount(int count) { m_histogramBinCount = count; }
  30. ImGui::LYImGuiUtils::HistogramContainer* FindContainerByName(const char* name);
  31. //! Needs to be public for l-value access for ImGui::MenuItem()
  32. bool m_show = true;
  33. private:
  34. AZStd::string m_name; //< The name shown in the collapsible header.
  35. int m_histogramBinCount = 100; //< The number of bins in the histogram.
  36. using HistogramIndexByNames = AZStd::unordered_map<const char*, size_t>;
  37. HistogramIndexByNames m_histogramIndexByName; //< Look-up table for the histogram index by name.
  38. AZStd::vector<ImGui::LYImGuiUtils::HistogramContainer> m_histograms; //< Owns the histogram containers.
  39. static constexpr float s_histogramHeight = 85.0f;
  40. };
  41. } // namespace ImGui::LYImGuiUtils
  42. #endif // IMGUI_ENABLED