From e034eabeb8da93bc110c2e55430a22415bbac2c2 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 17 Mar 2019 17:21:30 +0100 Subject: [PATCH] Animate plot ranges. --- server/TracyView.cpp | 27 ++++++++++++++++++++++++++- server/TracyView.hpp | 7 +++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 0b4161de..43687587 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -3692,7 +3692,7 @@ int View::DrawPlots( int offset, double pxns, const ImVec2& wpos, bool hover, fl float txtx = 0; const auto yPos = AdjustThreadPosition( vis, wpos.y, offset ); const auto oldOffset = offset; - ImGui::PushClipRect( wpos, wpos + ImVec2( w, offset + vis.height ), true ); + ImGui::PushClipRect( wpos + ImVec2( 0, offset ), wpos + ImVec2( w, offset + vis.height ), true ); if( yPos + ty >= yMin && yPos <= yMax ) { if( showFull ) @@ -3823,6 +3823,31 @@ int View::DrawPlots( int offset, double pxns, const ImVec2& wpos, bool hover, fl } } + auto pvit = m_plotView.find( v ); + if( pvit == m_plotView.end() ) + { + pvit = m_plotView.emplace( v, PlotView { min, max } ).first; + } + auto& pv = pvit->second; + if( pv.min != min || pv.max != max ) + { + const auto dt = ImGui::GetIO().DeltaTime; + const auto minDiff = min - pv.min; + const auto maxDiff = max - pv.max; + + pv.min += minDiff * 15.0 * dt; + pv.max += maxDiff * 15.0 * dt; + + const auto minDiffNew = min - pv.min; + const auto maxDiffNew = max - pv.max; + + if( minDiff * minDiffNew < 0 ) pv.min = min; + if( maxDiff * maxDiffNew < 0 ) pv.max = max; + + min = pv.min; + max = pv.max; + } + const auto revrange = 1.0 / ( max - min ); if( it == vec.begin() ) diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 3fe83853..e7d51d17 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -51,6 +51,12 @@ public: int height = 0; }; + struct PlotView + { + double min; + double max; + }; + using SetTitleCallback = void(*)( const char* ); View( ImFont* fixedWidth = nullptr, SetTitleCallback stcb = nullptr ) : View( "127.0.0.1", fixedWidth, stcb ) {} @@ -186,6 +192,7 @@ private: flat_hash_map> m_visData; flat_hash_map> m_visibleMsgThread; flat_hash_map> m_gpuDrift; + flat_hash_map> m_plotView; tracy_force_inline VisData& Vis( const void* ptr ) {