From 8f0c5e867eb70f2432d3370cff4b57d4edbaec5f Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sat, 27 Mar 2021 13:25:21 +0100 Subject: [PATCH] Source tooltip implementation. --- server/TracyView.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++ server/TracyView.hpp | 3 +++ 2 files changed, 49 insertions(+) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 4f69bea6..22a165d0 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -17801,4 +17801,50 @@ const char* View::SourceSubstitution( const char* srcFile ) const return res.c_str(); } +void View::DrawSourceTooltip( const char* filename, uint32_t srcline, int before, int after, bool separateTooltip ) +{ + if( !SourceFileValid( filename, m_worker.GetCaptureTime(), *this, m_worker ) ) return; + m_srcHintCache.Parse( filename, m_worker, *this ); + if( m_srcHintCache.empty() ) return; + if( separateTooltip ) ImGui::BeginTooltip(); + if( m_fixedFont ) ImGui::PushFont( m_fixedFont ); + auto& lines = m_srcHintCache.get(); + const int start = std::max( 0, (int)srcline - ( before+1 ) ); + const int end = std::min( m_srcHintCache.get().size(), srcline + after ); + for( int i=start; ibegin ) + { + ImGui::TextUnformatted( ptr, it->begin ); + ImGui::SameLine( 0, 0 ); + } + TextColoredUnformatted( i == srcline-1 ? SyntaxColors[(int)it->color] : SyntaxColorsDimmed[(int)it->color], it->begin, it->end ); + ImGui::SameLine( 0, 0 ); + ptr = it->end; + ++it; + } + ImGui::ItemSize( ImVec2( 0, 0 ), 0 ); + } + } + if( m_fixedFont ) ImGui::PopFont(); + if( separateTooltip ) ImGui::EndTooltip(); +} + } diff --git a/server/TracyView.hpp b/server/TracyView.hpp index af2418ec..c1b76884 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -14,6 +14,7 @@ #include "TracyDecayValue.hpp" #include "TracyImGui.hpp" #include "TracyShortPtr.hpp" +#include "TracySourceContents.hpp" #include "TracyTexture.hpp" #include "TracyUserData.hpp" #include "TracyVector.hpp" @@ -193,6 +194,7 @@ private: void DrawSampleParents(); void DrawRanges(); void DrawRangeEntry( Range& range, const char* label, uint32_t color, const char* popupLabel, int id ); + void DrawSourceTooltip( const char* filename, uint32_t line, int before = 3, int after = 3, bool separateTooltip = true ); void ListMemData( std::vector& vec, std::function DrawAddress, const char* id = nullptr, int64_t startTime = -1, uint64_t pool = 0 ); @@ -414,6 +416,7 @@ private: Vector m_zoneInfoStack; Vector m_gpuInfoStack; + SourceContents m_srcHintCache; std::unique_ptr m_sourceView; const char* m_sourceViewFile; bool m_uarchSet = false;