From f1dd4ef3d968b8507e2d84425a5fa37eb7fb5ff5 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Thu, 21 Feb 2019 21:18:41 +0100 Subject: [PATCH] Animate thread position and height. --- server/TracyView.cpp | 72 ++++++++++++++++++++++++++++++++++++++++---- server/TracyView.hpp | 14 +++++---- 2 files changed, 74 insertions(+), 12 deletions(-) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index bc41bd57..7c6d0e0e 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -1691,6 +1691,39 @@ bool View::DrawZoneFrames( const FrameData& frames ) return hover; } +static float AdjustThreadPosition( View::VisData& vis, float wy, int& offset ) +{ + if( vis.offset < offset ) + { + vis.offset = offset; + } + else if( vis.offset > offset ) + { + const auto diff = vis.offset - offset; + const auto move = std::max( 2.0, diff * 10.0 * ImGui::GetIO().DeltaTime ); + offset = vis.offset = int( std::max( vis.offset - move, offset ) ); + } + + return offset + wy; +} + +static void AdjustThreadHeight( View::VisData& vis, int oldOffset, int& offset ) +{ + const auto h = offset - oldOffset; + if( vis.height > h ) + { + vis.height = h; + offset = oldOffset + vis.height; + } + else if( vis.height < h ) + { + const auto diff = h - vis.height; + const auto move = std::max( 2.0, diff * 10.0 * ImGui::GetIO().DeltaTime ); + vis.height = int( std::min( vis.height + move, h ) ); + offset = oldOffset + vis.height; + } +} + void View::DrawZones() { m_msgHighlight.Decay( nullptr ); @@ -1756,10 +1789,17 @@ void View::DrawZones() { const auto& v = m_worker.GetGpuData()[i]; auto& vis = Vis( v ); - if( !vis.visible ) continue; + if( !vis.visible ) + { + vis.height = 0; + vis.offset = 0; + continue; + } bool& showFull = vis.showFull; - const auto yPos = wpos.y + offset; + const auto yPos = AdjustThreadPosition( vis, wpos.y, offset ); + const auto oldOffset = offset; + ImGui::PushClipRect( wpos + ImVec2( 0, offset ), wpos + ImVec2( w, offset + vis.height ), true ); if( yPos + ostep >= yMin && yPos <= yMax ) { draw->AddLine( wpos + ImVec2( 0, offset + ostep - 1 ), wpos + ImVec2( w, offset + ostep - 1 ), 0x33FFFFFF ); @@ -1831,6 +1871,8 @@ void View::DrawZones() offset += ostep * depth; } offset += ostep * 0.2f; + AdjustThreadHeight( vis, oldOffset, offset ); + ImGui::PopClipRect(); } } @@ -1840,10 +1882,17 @@ void View::DrawZones() for( const auto& v : m_worker.GetThreadData() ) { auto& vis = Vis( v ); - if( !vis.visible ) continue; + if( !vis.visible ) + { + vis.height = 0; + vis.offset = 0; + continue; + } bool& showFull = vis.showFull; - const auto yPos = wpos.y + offset; + const auto yPos = AdjustThreadPosition( vis, wpos.y, offset ); + const auto oldOffset = offset; + ImGui::PushClipRect( wpos + ImVec2( 0, offset ), wpos + ImVec2( w, offset + vis.height ), true ); if( yPos + ostep >= yMin && yPos <= yMax ) { draw->AddLine( wpos + ImVec2( 0, offset + ostep - 1 ), wpos + ImVec2( w, offset + ostep - 1 ), 0x33FFFFFF ); @@ -2009,6 +2058,8 @@ void View::DrawZones() } } offset += ostep * 0.2f; + AdjustThreadHeight( vis, oldOffset, offset ); + ImGui::PopClipRect(); } m_lockHighlight = nextLockHighlight; @@ -3371,12 +3422,19 @@ int View::DrawPlots( int offset, double pxns, const ImVec2& wpos, bool hover, fl for( const auto& v : m_worker.GetPlots() ) { auto& vis = Vis( v ); - if( !vis.visible ) continue; + if( !vis.visible ) + { + vis.height = 0; + vis.offset = 0; + continue; + } assert( !v->data.empty() ); bool& showFull = vis.showFull; float txtx = 0; - auto yPos = wpos.y + offset; + const auto yPos = AdjustThreadPosition( vis, wpos.y, offset ); + const auto oldOffset = offset; + ImGui::PushClipRect( wpos + ImVec2( 0, offset ), wpos + ImVec2( w, offset + vis.height ), true ); if( yPos + ty >= yMin && yPos <= yMax ) { if( showFull ) @@ -3597,6 +3655,8 @@ int View::DrawPlots( int offset, double pxns, const ImVec2& wpos, bool hover, fl } } offset += 0.2 * ty; + AdjustThreadHeight( vis, oldOffset, offset ); + ImGui::PopClipRect(); } return offset; diff --git a/server/TracyView.hpp b/server/TracyView.hpp index ef341e9c..3af91b9b 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -43,6 +43,14 @@ class View }; public: + struct VisData + { + bool visible = true; + bool showFull = true; + int offset = 0; + int height = 0; + }; + using SetTitleCallback = void(*)( const char* ); View( ImFont* fixedWidth = nullptr, SetTitleCallback stcb = nullptr ) : View( "127.0.0.1", fixedWidth, stcb ) {} @@ -77,12 +85,6 @@ private: uint64_t mem; }; - struct VisData - { - bool visible = true; - bool showFull = true; - }; - void InitTextEditor(); const char* ShortenNamespace( const char* name ) const;