Files
o3de/Gems/ImGui/Code/Include/LYImGuiUtils/HistogramContainer.h
T
2021-03-08 14:30:57 -08:00

99 lines
3.5 KiB
C++

/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#ifdef IMGUI_ENABLED
#include <AzCore/std/containers/deque.h>
#include "imgui/imgui.h"
#include <ISystem.h>
namespace ImGui
{
namespace LYImGuiUtils
{
/**
* A small class to help manage values for an ImGui Histogram ( ImGui doesn't want to manage the values itself ).
* Nothing crazy, just helps reduce boiler plate if you are ImGui::PlotHistogram()'ing
*/
class HistogramContainer
{
public:
HistogramContainer() = default;
~HistogramContainer() = default;
// An Enumeration of different ViewTypes for this histogram
enum class ViewType : AZ::u8
{
FIRST = 0,
Histogram = FIRST,
Lines,
COUNT
};
// Static Type to String function
static const char* ViewTypeToString(ViewType viewType);
// Do all of the set up via Init
void Init(const char* histogramName, int maxValueCountSize, ViewType viewType, bool displayOverlays, float minScale, float maxScale
, bool autoExpandScale, bool startCollapsed = false, bool drawMostRecentValue = true);
// How many values are in the container currently
int GetSize() { return m_values.size(); }
// What is the max size of the container
int GetMaxSize() { return m_maxSize; }
// Set the Max Size and clear the container
void SetMaxSize(int size) { m_values.clear(); m_maxSize = size; }
// Push a value to this histogram container
void PushValue(float val);
// Get the last value pushed
float GetLastValue() { return GetValue(m_values.size() - 1); }
// Get a Values at a particular index
float GetValue(int index) { return index < m_values.size() ? m_values.at(index) : 0.0f; }
// Draw this histogram with ImGui
void Draw(float histogramWidth, float histogramHeight);
private:
AZStd::string m_histogramName;
AZStd::deque<float> m_values;
int m_maxSize = 60;
ViewType m_viewType = ViewType::Histogram;
float m_minScale;
float m_maxScale;
bool m_dispalyOverlays;
bool m_autoExpandScale;
bool m_collapsed;
bool m_drawMostRecentValueText;
};
// Getter function lambda. Can be used directly with ImGui if the user would like to skip our cool Draw function and just use the class as a cache
static auto s_histogramContainerGetter = [](void* histContainerPtr, int idx)
{
ImGui::LYImGuiUtils::HistogramContainer* histContainer = static_cast<ImGui::LYImGuiUtils::HistogramContainer*>(histContainerPtr);
if (histContainer != nullptr)
{
return histContainer->GetValue(idx);
}
return 0.0f;
};
}
}
#endif // #ifdef IMGUI_ENABLED