From dd8694350ee10601bcea23a1850fb37cccac54de Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Mon, 27 Nov 2017 22:41:30 +0100 Subject: [PATCH] Add zoom-to-range animation. --- server/TracyView.cpp | 39 +++++++++++++++++++++++++++++---------- server/TracyView.hpp | 13 ++++++++++--- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 1872651d..4eaf20da 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -1597,11 +1597,22 @@ void View::DrawImpl() if( m_showOptions ) DrawOptions(); if( m_showMessages ) DrawMessages(); - if( m_zvStartNext != 0 ) + if( m_zoomAnim.active ) { - m_zvStart = m_zvStartNext; - m_zvEnd = m_zvEndNext; - m_pause = true; + const auto& io = ImGui::GetIO(); + m_zoomAnim.progress += io.DeltaTime * m_zoomAnim.lenMod; + if( m_zoomAnim.progress >= 1.f ) + { + m_zoomAnim.active = false; + m_zvStart = m_zoomAnim.start1; + m_zvEnd = m_zoomAnim.end1; + } + else + { + const auto v = sqrt( sin( M_PI_2 * m_zoomAnim.progress ) ); + m_zvStart = int64_t( m_zoomAnim.start0 + ( m_zoomAnim.start1 - m_zoomAnim.start0 ) * v ); + m_zvEnd = int64_t( m_zoomAnim.end0 + ( m_zoomAnim.end1 - m_zoomAnim.end0 ) * v ); + } } } @@ -2023,8 +2034,6 @@ bool View::DrawZoneFrames() } } - m_zvStartNext = 0; - const auto zitbegin = std::lower_bound( m_frames.begin(), m_frames.end(), m_zvStart ); if( zitbegin == m_frames.end() ) return hover; const auto zitend = std::lower_bound( zitbegin, m_frames.end(), m_zvEnd ); @@ -2541,7 +2550,7 @@ int View::DrawZoneLevel( const Vector& vec, bool hover, double pxns, { ZoneTooltip( ev ); - if( m_zvStartNext == 0 && ImGui::IsMouseClicked( 2 ) ) + if( !m_zoomAnim.active && ImGui::IsMouseClicked( 2 ) ) { ZoomToZone( ev ); } @@ -2709,7 +2718,7 @@ int View::DrawGpuZoneLevel( const Vector& vec, bool hover, double pxn { ZoneTooltip( ev ); - if( m_zvStartNext == 0 && ImGui::IsMouseClicked( 2 ) ) + if( !m_zoomAnim.active && ImGui::IsMouseClicked( 2 ) ) { ZoomToZone( ev ); } @@ -3732,8 +3741,18 @@ void View::ZoomToZone( const GpuEvent& ev ) void View::ZoomToRange( int64_t start, int64_t end ) { - m_zvStartNext = start; - m_zvEndNext = end; + m_pause = true; + m_zoomAnim.active = true; + m_zoomAnim.start0 = m_zvStart; + m_zoomAnim.start1 = start; + m_zoomAnim.end0 = m_zvEnd; + m_zoomAnim.end1 = end; + m_zoomAnim.progress = 0; + + const auto d0 = double( m_zoomAnim.end0 - m_zoomAnim.start0 ); + const auto d1 = double( m_zoomAnim.end1 - m_zoomAnim.start1 ); + const auto diff = d0>d1 ? d0/d1 : d1/d0; + m_zoomAnim.lenMod = 10.0 / log10( diff ); } void View::ZoneTooltip( const ZoneEvent& ev ) diff --git a/server/TracyView.hpp b/server/TracyView.hpp index cc4bd0da..eb48588e 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -36,6 +36,15 @@ class View typedef tracy::power_of_two_hash_policy hash_policy; }; + struct Animation + { + bool active = false; + int64_t start0, start1; + int64_t end0, end1; + double progress; + double lenMod; + }; + public: View() : View( "127.0.0.1" ) {} View( const char* addr ); @@ -228,9 +237,6 @@ private: int64_t m_zvStart; int64_t m_zvEnd; - int64_t m_zvStartNext; - int64_t m_zvEndNext; - int64_t m_delay; int64_t m_resolution; double m_timerMul; @@ -266,6 +272,7 @@ private: bool m_onlyContendedLocks; Namespace m_namespace; + Animation m_zoomAnim; bool m_terminate; };