mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-29 16:54:35 +00:00
Extract annotations UI from View.
This commit is contained in:
parent
5b451c3557
commit
358148920a
@ -137,6 +137,7 @@
|
|||||||
<ClCompile Include="..\..\..\server\TracyThreadCompress.cpp" />
|
<ClCompile Include="..\..\..\server\TracyThreadCompress.cpp" />
|
||||||
<ClCompile Include="..\..\..\server\TracyUserData.cpp" />
|
<ClCompile Include="..\..\..\server\TracyUserData.cpp" />
|
||||||
<ClCompile Include="..\..\..\server\TracyView.cpp" />
|
<ClCompile Include="..\..\..\server\TracyView.cpp" />
|
||||||
|
<ClCompile Include="..\..\..\server\TracyView_Annotations.cpp" />
|
||||||
<ClCompile Include="..\..\..\server\TracyView_Callstack.cpp" />
|
<ClCompile Include="..\..\..\server\TracyView_Callstack.cpp" />
|
||||||
<ClCompile Include="..\..\..\server\TracyView_Compare.cpp" />
|
<ClCompile Include="..\..\..\server\TracyView_Compare.cpp" />
|
||||||
<ClCompile Include="..\..\..\server\TracyView_ConnectionState.cpp" />
|
<ClCompile Include="..\..\..\server\TracyView_ConnectionState.cpp" />
|
||||||
|
@ -303,6 +303,9 @@
|
|||||||
<ClCompile Include="..\..\..\server\TracyView_Samples.cpp">
|
<ClCompile Include="..\..\..\server\TracyView_Samples.cpp">
|
||||||
<Filter>server</Filter>
|
<Filter>server</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\..\server\TracyView_Annotations.cpp">
|
||||||
|
<Filter>server</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\..\common\tracy_lz4.hpp">
|
<ClInclude Include="..\..\..\common\tracy_lz4.hpp">
|
||||||
|
@ -264,18 +264,6 @@ void View::DrawHelpMarker( const char* desc ) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void View::AddAnnotation( int64_t start, int64_t end )
|
|
||||||
{
|
|
||||||
auto ann = std::make_unique<Annotation>();
|
|
||||||
ann->range.active = true;
|
|
||||||
ann->range.min = start;
|
|
||||||
ann->range.max = end;
|
|
||||||
ann->color = 0x888888;
|
|
||||||
m_selectedAnnotation = ann.get();
|
|
||||||
m_annotations.emplace_back( std::move( ann ) );
|
|
||||||
pdqsort_branchless( m_annotations.begin(), m_annotations.end(), []( const auto& lhs, const auto& rhs ) { return lhs->range.min < rhs->range.min; } );
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char* CompressionName[] = {
|
static const char* CompressionName[] = {
|
||||||
"LZ4",
|
"LZ4",
|
||||||
"LZ4 HC",
|
"LZ4 HC",
|
||||||
@ -5577,137 +5565,6 @@ void View::DrawLockInfoWindow()
|
|||||||
if( !visible ) m_lockInfoWindow = InvalidId;
|
if( !visible ) m_lockInfoWindow = InvalidId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void View::DrawSelectedAnnotation()
|
|
||||||
{
|
|
||||||
assert( m_selectedAnnotation );
|
|
||||||
bool show = true;
|
|
||||||
ImGui::Begin( "Annotation", &show, ImGuiWindowFlags_AlwaysAutoResize );
|
|
||||||
if( !ImGui::GetCurrentWindowRead()->SkipItems )
|
|
||||||
{
|
|
||||||
if( ImGui::Button( ICON_FA_MICROSCOPE " Zoom to annotation" ) )
|
|
||||||
{
|
|
||||||
ZoomToRange( m_selectedAnnotation->range.min, m_selectedAnnotation->range.max );
|
|
||||||
}
|
|
||||||
ImGui::SameLine();
|
|
||||||
if( ImGui::Button( ICON_FA_TRASH_ALT " Remove" ) )
|
|
||||||
{
|
|
||||||
for( auto it = m_annotations.begin(); it != m_annotations.end(); ++it )
|
|
||||||
{
|
|
||||||
if( it->get() == m_selectedAnnotation )
|
|
||||||
{
|
|
||||||
m_annotations.erase( it );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ImGui::End();
|
|
||||||
m_selectedAnnotation = nullptr;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ImGui::Separator();
|
|
||||||
{
|
|
||||||
const auto desc = m_selectedAnnotation->text.c_str();
|
|
||||||
const auto descsz = std::min<size_t>( 1023, m_selectedAnnotation->text.size() );
|
|
||||||
char buf[1024];
|
|
||||||
buf[descsz] = '\0';
|
|
||||||
memcpy( buf, desc, descsz );
|
|
||||||
if( ImGui::InputTextWithHint( "##anndesc", "Describe annotation", buf, 256 ) )
|
|
||||||
{
|
|
||||||
m_selectedAnnotation->text.assign( buf );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ImVec4 col = ImGui::ColorConvertU32ToFloat4( m_selectedAnnotation->color );
|
|
||||||
ImGui::ColorEdit3( "Color", &col.x );
|
|
||||||
m_selectedAnnotation->color = ImGui::ColorConvertFloat4ToU32( col );
|
|
||||||
ImGui::Separator();
|
|
||||||
TextFocused( "Annotation begin:", TimeToStringExact( m_selectedAnnotation->range.min ) );
|
|
||||||
TextFocused( "Annotation end:", TimeToStringExact( m_selectedAnnotation->range.max ) );
|
|
||||||
TextFocused( "Annotation length:", TimeToString( m_selectedAnnotation->range.max - m_selectedAnnotation->range.min ) );
|
|
||||||
}
|
|
||||||
ImGui::End();
|
|
||||||
if( !show ) m_selectedAnnotation = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void View::DrawAnnotationList()
|
|
||||||
{
|
|
||||||
const auto scale = GetScale();
|
|
||||||
ImGui::SetNextWindowSize( ImVec2( 600 * scale, 300 * scale ), ImGuiCond_FirstUseEver );
|
|
||||||
ImGui::Begin( "Annotation list", &m_showAnnotationList );
|
|
||||||
if( ImGui::GetCurrentWindowRead()->SkipItems ) { ImGui::End(); return; }
|
|
||||||
|
|
||||||
if( ImGui::Button( ICON_FA_PLUS " Add annotation" ) )
|
|
||||||
{
|
|
||||||
AddAnnotation( m_vd.zvStart, m_vd.zvEnd );
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::SameLine();
|
|
||||||
ImGui::SeparatorEx( ImGuiSeparatorFlags_Vertical );
|
|
||||||
ImGui::SameLine();
|
|
||||||
|
|
||||||
if( m_annotations.empty() )
|
|
||||||
{
|
|
||||||
ImGui::TextWrapped( "No annotations." );
|
|
||||||
ImGui::Separator();
|
|
||||||
ImGui::End();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
TextFocused( "Annotations:", RealToString( m_annotations.size() ) );
|
|
||||||
ImGui::Separator();
|
|
||||||
ImGui::BeginChild( "##annotationList" );
|
|
||||||
const bool ctrl = ImGui::GetIO().KeyCtrl;
|
|
||||||
int remove = -1;
|
|
||||||
int idx = 0;
|
|
||||||
for( auto& ann : m_annotations )
|
|
||||||
{
|
|
||||||
ImGui::PushID( idx );
|
|
||||||
if( ImGui::Button( ICON_FA_EDIT ) )
|
|
||||||
{
|
|
||||||
m_selectedAnnotation = ann.get();
|
|
||||||
}
|
|
||||||
ImGui::SameLine();
|
|
||||||
if( ImGui::Button( ICON_FA_MICROSCOPE ) )
|
|
||||||
{
|
|
||||||
ZoomToRange( ann->range.min, ann->range.max );
|
|
||||||
}
|
|
||||||
ImGui::SameLine();
|
|
||||||
if( ButtonDisablable( ICON_FA_TRASH_ALT, !ctrl ) )
|
|
||||||
{
|
|
||||||
remove = idx;
|
|
||||||
}
|
|
||||||
if( !ctrl ) TooltipIfHovered( "Press ctrl key to enable removal" );
|
|
||||||
ImGui::SameLine();
|
|
||||||
ImGui::ColorButton( "c", ImGui::ColorConvertU32ToFloat4( ann->color ), ImGuiColorEditFlags_NoTooltip );
|
|
||||||
ImGui::SameLine();
|
|
||||||
if( m_selectedAnnotation == ann.get() )
|
|
||||||
{
|
|
||||||
bool t = true;
|
|
||||||
ImGui::Selectable( "##annSelectable", &t );
|
|
||||||
ImGui::SameLine( 0, 0 );
|
|
||||||
}
|
|
||||||
if( ann->text.empty() )
|
|
||||||
{
|
|
||||||
TextDisabledUnformatted( "Empty annotation" );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ImGui::TextUnformatted( ann->text.c_str() );
|
|
||||||
}
|
|
||||||
ImGui::SameLine();
|
|
||||||
ImGui::Spacing();
|
|
||||||
ImGui::SameLine();
|
|
||||||
ImGui::TextDisabled( "%s - %s (%s)", TimeToStringExact( ann->range.min ), TimeToStringExact( ann->range.max ), TimeToString( ann->range.max - ann->range.min ) );
|
|
||||||
ImGui::PopID();
|
|
||||||
idx++;
|
|
||||||
}
|
|
||||||
if( remove >= 0 )
|
|
||||||
{
|
|
||||||
if( m_annotations[remove].get() == m_selectedAnnotation ) m_selectedAnnotation = nullptr;
|
|
||||||
m_annotations.erase( m_annotations.begin() + remove );
|
|
||||||
}
|
|
||||||
ImGui::EndChild();
|
|
||||||
ImGui::End();
|
|
||||||
}
|
|
||||||
|
|
||||||
void View::DrawRanges()
|
void View::DrawRanges()
|
||||||
{
|
{
|
||||||
ImGui::Begin( "Time range limits", &m_showRanges, ImGuiWindowFlags_AlwaysAutoResize );
|
ImGui::Begin( "Time range limits", &m_showRanges, ImGuiWindowFlags_AlwaysAutoResize );
|
||||||
|
150
server/TracyView_Annotations.cpp
Normal file
150
server/TracyView_Annotations.cpp
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
#include "TracyPrint.hpp"
|
||||||
|
#include "TracyView.hpp"
|
||||||
|
|
||||||
|
namespace tracy
|
||||||
|
{
|
||||||
|
|
||||||
|
void View::AddAnnotation( int64_t start, int64_t end )
|
||||||
|
{
|
||||||
|
auto ann = std::make_unique<Annotation>();
|
||||||
|
ann->range.active = true;
|
||||||
|
ann->range.min = start;
|
||||||
|
ann->range.max = end;
|
||||||
|
ann->color = 0x888888;
|
||||||
|
m_selectedAnnotation = ann.get();
|
||||||
|
m_annotations.emplace_back( std::move( ann ) );
|
||||||
|
pdqsort_branchless( m_annotations.begin(), m_annotations.end(), []( const auto& lhs, const auto& rhs ) { return lhs->range.min < rhs->range.min; } );
|
||||||
|
}
|
||||||
|
|
||||||
|
void View::DrawSelectedAnnotation()
|
||||||
|
{
|
||||||
|
assert( m_selectedAnnotation );
|
||||||
|
bool show = true;
|
||||||
|
ImGui::Begin( "Annotation", &show, ImGuiWindowFlags_AlwaysAutoResize );
|
||||||
|
if( !ImGui::GetCurrentWindowRead()->SkipItems )
|
||||||
|
{
|
||||||
|
if( ImGui::Button( ICON_FA_MICROSCOPE " Zoom to annotation" ) )
|
||||||
|
{
|
||||||
|
ZoomToRange( m_selectedAnnotation->range.min, m_selectedAnnotation->range.max );
|
||||||
|
}
|
||||||
|
ImGui::SameLine();
|
||||||
|
if( ImGui::Button( ICON_FA_TRASH_ALT " Remove" ) )
|
||||||
|
{
|
||||||
|
for( auto it = m_annotations.begin(); it != m_annotations.end(); ++it )
|
||||||
|
{
|
||||||
|
if( it->get() == m_selectedAnnotation )
|
||||||
|
{
|
||||||
|
m_annotations.erase( it );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui::End();
|
||||||
|
m_selectedAnnotation = nullptr;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ImGui::Separator();
|
||||||
|
{
|
||||||
|
const auto desc = m_selectedAnnotation->text.c_str();
|
||||||
|
const auto descsz = std::min<size_t>( 1023, m_selectedAnnotation->text.size() );
|
||||||
|
char buf[1024];
|
||||||
|
buf[descsz] = '\0';
|
||||||
|
memcpy( buf, desc, descsz );
|
||||||
|
if( ImGui::InputTextWithHint( "##anndesc", "Describe annotation", buf, 256 ) )
|
||||||
|
{
|
||||||
|
m_selectedAnnotation->text.assign( buf );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImVec4 col = ImGui::ColorConvertU32ToFloat4( m_selectedAnnotation->color );
|
||||||
|
ImGui::ColorEdit3( "Color", &col.x );
|
||||||
|
m_selectedAnnotation->color = ImGui::ColorConvertFloat4ToU32( col );
|
||||||
|
ImGui::Separator();
|
||||||
|
TextFocused( "Annotation begin:", TimeToStringExact( m_selectedAnnotation->range.min ) );
|
||||||
|
TextFocused( "Annotation end:", TimeToStringExact( m_selectedAnnotation->range.max ) );
|
||||||
|
TextFocused( "Annotation length:", TimeToString( m_selectedAnnotation->range.max - m_selectedAnnotation->range.min ) );
|
||||||
|
}
|
||||||
|
ImGui::End();
|
||||||
|
if( !show ) m_selectedAnnotation = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void View::DrawAnnotationList()
|
||||||
|
{
|
||||||
|
const auto scale = GetScale();
|
||||||
|
ImGui::SetNextWindowSize( ImVec2( 600 * scale, 300 * scale ), ImGuiCond_FirstUseEver );
|
||||||
|
ImGui::Begin( "Annotation list", &m_showAnnotationList );
|
||||||
|
if( ImGui::GetCurrentWindowRead()->SkipItems ) { ImGui::End(); return; }
|
||||||
|
|
||||||
|
if( ImGui::Button( ICON_FA_PLUS " Add annotation" ) )
|
||||||
|
{
|
||||||
|
AddAnnotation( m_vd.zvStart, m_vd.zvEnd );
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::SeparatorEx( ImGuiSeparatorFlags_Vertical );
|
||||||
|
ImGui::SameLine();
|
||||||
|
|
||||||
|
if( m_annotations.empty() )
|
||||||
|
{
|
||||||
|
ImGui::TextWrapped( "No annotations." );
|
||||||
|
ImGui::Separator();
|
||||||
|
ImGui::End();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
TextFocused( "Annotations:", RealToString( m_annotations.size() ) );
|
||||||
|
ImGui::Separator();
|
||||||
|
ImGui::BeginChild( "##annotationList" );
|
||||||
|
const bool ctrl = ImGui::GetIO().KeyCtrl;
|
||||||
|
int remove = -1;
|
||||||
|
int idx = 0;
|
||||||
|
for( auto& ann : m_annotations )
|
||||||
|
{
|
||||||
|
ImGui::PushID( idx );
|
||||||
|
if( ImGui::Button( ICON_FA_EDIT ) )
|
||||||
|
{
|
||||||
|
m_selectedAnnotation = ann.get();
|
||||||
|
}
|
||||||
|
ImGui::SameLine();
|
||||||
|
if( ImGui::Button( ICON_FA_MICROSCOPE ) )
|
||||||
|
{
|
||||||
|
ZoomToRange( ann->range.min, ann->range.max );
|
||||||
|
}
|
||||||
|
ImGui::SameLine();
|
||||||
|
if( ButtonDisablable( ICON_FA_TRASH_ALT, !ctrl ) )
|
||||||
|
{
|
||||||
|
remove = idx;
|
||||||
|
}
|
||||||
|
if( !ctrl ) TooltipIfHovered( "Press ctrl key to enable removal" );
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::ColorButton( "c", ImGui::ColorConvertU32ToFloat4( ann->color ), ImGuiColorEditFlags_NoTooltip );
|
||||||
|
ImGui::SameLine();
|
||||||
|
if( m_selectedAnnotation == ann.get() )
|
||||||
|
{
|
||||||
|
bool t = true;
|
||||||
|
ImGui::Selectable( "##annSelectable", &t );
|
||||||
|
ImGui::SameLine( 0, 0 );
|
||||||
|
}
|
||||||
|
if( ann->text.empty() )
|
||||||
|
{
|
||||||
|
TextDisabledUnformatted( "Empty annotation" );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ImGui::TextUnformatted( ann->text.c_str() );
|
||||||
|
}
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::Spacing();
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::TextDisabled( "%s - %s (%s)", TimeToStringExact( ann->range.min ), TimeToStringExact( ann->range.max ), TimeToString( ann->range.max - ann->range.min ) );
|
||||||
|
ImGui::PopID();
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
|
if( remove >= 0 )
|
||||||
|
{
|
||||||
|
if( m_annotations[remove].get() == m_selectedAnnotation ) m_selectedAnnotation = nullptr;
|
||||||
|
m_annotations.erase( m_annotations.begin() + remove );
|
||||||
|
}
|
||||||
|
ImGui::EndChild();
|
||||||
|
ImGui::End();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user