From 5fed86dae7302047a9faef35182ef5b54bb2fac7 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 13 Oct 2019 15:28:52 +0200 Subject: [PATCH] Allow adding annotations to timeline. --- server/TracyEvent.hpp | 9 +++++++++ server/TracyView.cpp | 37 ++++++++++++++++++++++++++++++++++++- server/TracyView.hpp | 1 + 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/server/TracyEvent.hpp b/server/TracyEvent.hpp index 6406d440..8f707303 100644 --- a/server/TracyEvent.hpp +++ b/server/TracyEvent.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include "TracyCharUtil.hpp" @@ -509,6 +510,14 @@ struct CpuThreadData enum { CpuThreadDataSize = sizeof( CpuThreadData ) }; + +struct Annotation +{ + std::string text; + int64_t start; + int64_t end; +}; + } #endif diff --git a/server/TracyView.cpp b/server/TracyView.cpp index c1584f38..e8dbedbc 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -1418,8 +1418,17 @@ void View::HandleZoneViewMouse( int64_t timespan, const ImVec2& wpos, float w, d { m_highlight.end = m_vd.zvStart + ( io.MousePos.x - wpos.x ) * nspx; } - else + else if( m_highlight.active ) { + if( ImGui::GetIO().KeyCtrl && m_highlight.start != m_highlight.end ) + { + auto ann = std::make_unique(); + const auto s = std::min( m_highlight.start, m_highlight.end ); + const auto e = std::max( m_highlight.start, m_highlight.end ); + ann->start = s; + ann->end = e; + m_annotations.emplace_back( std::move( ann ) ); + } m_highlight.active = false; } @@ -2543,6 +2552,32 @@ void View::DrawZones() ImGui::EndChild(); + for( auto& ann : m_annotations ) + { + if( ann->start < m_vd.zvEnd && ann->end > m_vd.zvStart ) + { + draw->AddRectFilled( linepos + ImVec2( ( ann->start - m_vd.zvStart ) * pxns, 0 ), linepos + ImVec2( ( ann->end - m_vd.zvStart ) * pxns, lineh ), 0x22888888 ); + draw->AddRect( linepos + ImVec2( ( ann->start - m_vd.zvStart ) * pxns, 0 ), linepos + ImVec2( ( ann->end - m_vd.zvStart ) * pxns, lineh ), 0x44888888 ); + if( ImGui::IsMouseHoveringRect( linepos + ImVec2( ( ann->start - m_vd.zvStart ) * pxns, 0 ), linepos + ImVec2( ( ann->end - m_vd.zvStart ) * pxns, lineh ) ) ) + { + ImGui::BeginTooltip(); + if( ann->text.empty() ) + { + TextDisabledUnformatted( "Empty annotation" ); + } + else + { + ImGui::TextUnformatted( ann->text.c_str() ); + } + ImGui::Separator(); + TextFocused( "Annotation begin:", TimeToString( ann->start ) ); + TextFocused( "Annotation end:", TimeToString( ann->end ) ); + TextFocused( "Annotation length:", TimeToString( ann->end - ann->start ) ); + ImGui::EndTooltip(); + } + } + } + if( m_gpuStart != 0 && m_gpuEnd != 0 ) { const auto px0 = ( m_gpuStart - m_vd.zvStart ) * pxns; diff --git a/server/TracyView.hpp b/server/TracyView.hpp index df075917..75f57b96 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -364,6 +364,7 @@ private: void* m_frameTexture = nullptr; const void* m_frameTexturePtr = nullptr; + std::vector> m_annotations; UserData m_userData; struct FindZone {