From c3df475de7ae2978f35d26ae6ad0b63e0a368615 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Thu, 21 Sep 2017 00:57:26 +0200 Subject: [PATCH] Draw frames in zone view. --- server/TracyView.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++++ server/TracyView.hpp | 1 + 2 files changed, 82 insertions(+) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 44c4d5df..61a9f9a1 100755 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -445,6 +445,7 @@ void View::DrawImpl() ImGui::SameLine(); ImGui::Text( "Frames: %-7i Time span: %-10s View span: %s", m_frames.size(), TimeToString( GetLastTime() - m_frames[0] ), TimeToString( m_zvEnd - m_zvStart ) ); DrawFrames(); + DrawZones(); ImGui::End(); ImGui::ShowTestWindow(); @@ -617,4 +618,84 @@ void View::DrawFrames() } } +struct TimeScale +{ + uint64_t div; + const char* fmt; +}; + +void View::DrawZones() +{ + if( m_zvStart == m_zvEnd ) return; + assert( m_zvStart < m_zvEnd ); + + ImGuiWindow* window = ImGui::GetCurrentWindow(); + if( window->SkipItems ) return; + + const auto wpos = ImGui::GetCursorScreenPos(); + const auto w = ImGui::GetWindowContentRegionWidth(); + const auto h = ImGui::GetContentRegionAvail().y; + auto draw = ImGui::GetWindowDrawList(); + + enum { TimeHeight = 50 }; + + ImGui::InvisibleButton( "##zones", ImVec2( w, h ) ); + bool hover = ImGui::IsItemHovered(); + + const auto timespan = m_zvEnd - m_zvStart; + const auto pxns = w / double( timespan ); + + const auto zitbegin = std::lower_bound( m_frames.begin(), m_frames.end(), m_zvStart ); + const auto zitend = std::lower_bound( m_frames.begin(), m_frames.end(), m_zvEnd ); + + const auto zbegin = (int)std::distance( m_frames.begin(), zitbegin ); + const auto zend = (int)std::distance( m_frames.begin(), zitend ); + + for( int i=zbegin; i= m_zvStart ) + { + draw->AddLine( wpos + ImVec2( ( fbegin - m_zvStart ) * pxns, 0 ), wpos + ImVec2( ( fbegin - m_zvStart ) * pxns, h ), 0x22FFFFFF ); + } + + if( fsz >= 5 ) + { + if( fbegin >= m_zvStart ) + { + draw->AddLine( wpos + ImVec2( ( fbegin - m_zvStart ) * pxns + 2, 1 ), wpos + ImVec2( ( fbegin - m_zvStart ) * pxns + 2, tsz.y - 1 ), 0xFFFFFFFF ); + } + if( fend <= m_zvEnd ) + { + draw->AddLine( wpos + ImVec2( ( fend - m_zvStart ) * pxns - 2, 1 ), wpos + ImVec2( ( fend - m_zvStart ) * pxns - 2, tsz.y - 1 ), 0xFFFFFFFF ); + } + if( fsz - 5 > tsz.x ) + { + const auto part = ( fsz - 5 - tsz.x ) / 2; + draw->AddLine( wpos + ImVec2( ( fbegin - m_zvStart ) * pxns + 2, tsz.y / 2 ), wpos + ImVec2( ( fbegin - m_zvStart ) * pxns + part, tsz.y / 2 ), 0xFFFFFFFF ); + draw->AddText( wpos + ImVec2( ( fbegin - m_zvStart ) * pxns + 2 + part, 0 ), 0xFFFFFFFF, buf ); + draw->AddLine( wpos + ImVec2( ( fbegin - m_zvStart ) * pxns + 2 + part + tsz.x, tsz.y / 2 ), wpos + ImVec2( ( fend - m_zvStart ) * pxns - 2, tsz.y / 2 ), 0xFFFFFFFF ); + } + else + { + draw->AddLine( wpos + ImVec2( ( fbegin - m_zvStart ) * pxns + 2, tsz.y / 2 ), wpos + ImVec2( ( fend - m_zvStart ) * pxns - 2, tsz.y / 2 ), 0xFFFFFFFF ); + } + } + } + + const auto fend = GetFrameEnd( zend-1 ); + if( fend == m_zvEnd ) + { + draw->AddLine( wpos + ImVec2( ( fend - m_zvStart ) * pxns, 0 ), wpos + ImVec2( ( fend - m_zvStart ) * pxns, h ), 0x22FFFFFF ); + } +} + } diff --git a/server/TracyView.hpp b/server/TracyView.hpp index c2105a6b..7e68fe05 100755 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -56,6 +56,7 @@ private: void DrawImpl(); void DrawFrames(); + void DrawZones(); std::string m_addr;