2022-09-03 14:34:53 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include "TracyImGui.hpp"
|
|
|
|
#include "TracyMouse.hpp"
|
2023-03-18 16:03:23 +00:00
|
|
|
#include "TracyTimelineContext.hpp"
|
2022-09-03 14:34:53 +00:00
|
|
|
#include "TracyTimelineItem.hpp"
|
|
|
|
#include "TracyView.hpp"
|
|
|
|
|
|
|
|
namespace tracy
|
|
|
|
{
|
|
|
|
|
2023-03-14 01:02:21 +00:00
|
|
|
TimelineItem::TimelineItem( View& view, Worker& worker, const void* key, bool wantPreprocess )
|
2022-09-03 14:34:53 +00:00
|
|
|
: m_visible( true )
|
|
|
|
, m_showFull( true )
|
|
|
|
, m_height( 0 )
|
2023-03-14 01:02:21 +00:00
|
|
|
, m_wantPreprocess( wantPreprocess )
|
2023-01-27 19:00:05 +00:00
|
|
|
, m_key( key )
|
2022-09-03 14:34:53 +00:00
|
|
|
, m_view( view )
|
|
|
|
, m_worker( worker )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-03-18 15:07:56 +00:00
|
|
|
void TimelineItem::Draw( bool firstFrame, const TimelineContext& ctx, int yOffset )
|
2022-09-03 14:34:53 +00:00
|
|
|
{
|
2023-01-27 19:00:05 +00:00
|
|
|
const auto yBegin = yOffset;
|
|
|
|
auto yEnd = yOffset;
|
|
|
|
|
2022-09-04 12:22:12 +00:00
|
|
|
if( !IsVisible() )
|
2022-09-03 14:34:53 +00:00
|
|
|
{
|
2023-01-27 19:00:05 +00:00
|
|
|
if( m_height != 0 ) AdjustThreadHeight( firstFrame, yBegin, yEnd );
|
2022-09-03 14:34:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if( IsEmpty() ) return;
|
|
|
|
|
2023-03-14 01:24:23 +00:00
|
|
|
const auto w = ctx.w;
|
|
|
|
const auto ty = ctx.ty;
|
2022-09-03 19:11:36 +00:00
|
|
|
const auto ostep = ty + 1;
|
2023-03-14 01:24:23 +00:00
|
|
|
const auto& wpos = ctx.wpos;
|
2023-01-27 19:00:05 +00:00
|
|
|
const auto yPos = wpos.y + yBegin;
|
2022-09-03 14:34:53 +00:00
|
|
|
const auto dpos = wpos + ImVec2( 0.5f, 0.5f );
|
|
|
|
auto draw = ImGui::GetWindowDrawList();
|
|
|
|
|
|
|
|
ImGui::PushID( this );
|
2023-01-27 19:00:05 +00:00
|
|
|
ImGui::PushClipRect( wpos + ImVec2( 0, yBegin ), wpos + ImVec2( w, yBegin + m_height ), true );
|
2022-09-03 14:34:53 +00:00
|
|
|
|
2023-01-27 19:00:05 +00:00
|
|
|
yEnd += ostep;
|
2022-09-03 19:57:56 +00:00
|
|
|
if( m_showFull )
|
|
|
|
{
|
2023-03-18 15:07:56 +00:00
|
|
|
if( !DrawContents( ctx, yEnd ) && !m_view.GetViewData().drawEmptyLabels )
|
2022-09-03 19:57:56 +00:00
|
|
|
{
|
2023-01-27 19:00:05 +00:00
|
|
|
yEnd = yBegin;
|
|
|
|
AdjustThreadHeight( firstFrame, yBegin, yEnd );
|
2022-09-03 19:57:56 +00:00
|
|
|
ImGui::PopClipRect();
|
|
|
|
ImGui::PopID();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-27 19:00:05 +00:00
|
|
|
DrawOverlay( wpos + ImVec2( 0, yBegin ), wpos + ImVec2( w, yEnd ) );
|
2022-09-03 21:09:23 +00:00
|
|
|
ImGui::PopClipRect();
|
|
|
|
|
2022-09-03 14:34:53 +00:00
|
|
|
float labelWidth;
|
2023-01-27 19:00:05 +00:00
|
|
|
const auto hdrOffset = yBegin;
|
2023-03-15 22:56:57 +00:00
|
|
|
const bool drawHeader = yPos + ty >= ctx.yMin && yPos <= ctx.yMax;
|
2022-09-03 14:34:53 +00:00
|
|
|
if( drawHeader )
|
|
|
|
{
|
|
|
|
const auto color = HeaderColor();
|
|
|
|
const auto colorInactive = HeaderColorInactive();
|
|
|
|
|
|
|
|
if( m_showFull )
|
|
|
|
{
|
2022-09-03 19:57:56 +00:00
|
|
|
DrawTextContrast( draw, wpos + ImVec2( 0, hdrOffset ), color, ICON_FA_CARET_DOWN );
|
2022-09-03 14:34:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-09-03 19:57:56 +00:00
|
|
|
DrawTextContrast( draw, wpos + ImVec2( 0, hdrOffset ), colorInactive, ICON_FA_CARET_RIGHT );
|
2022-09-03 14:34:53 +00:00
|
|
|
}
|
|
|
|
const auto label = HeaderLabel();
|
|
|
|
labelWidth = ImGui::CalcTextSize( label ).x;
|
2022-09-03 19:57:56 +00:00
|
|
|
DrawTextContrast( draw, wpos + ImVec2( ty, hdrOffset ), m_showFull ? color : colorInactive, label );
|
2022-09-03 19:14:56 +00:00
|
|
|
if( m_showFull )
|
|
|
|
{
|
2022-09-03 19:57:56 +00:00
|
|
|
DrawLine( draw, dpos + ImVec2( 0, hdrOffset + ty - 1 ), dpos + ImVec2( w, hdrOffset + ty - 1 ), HeaderLineColor() );
|
2023-03-18 15:07:56 +00:00
|
|
|
HeaderExtraContents( ctx, hdrOffset, labelWidth );
|
2022-09-03 19:14:56 +00:00
|
|
|
}
|
2022-09-03 14:34:53 +00:00
|
|
|
|
2023-03-18 15:07:56 +00:00
|
|
|
if( ctx.hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( 0, hdrOffset ), wpos + ImVec2( ty + labelWidth, hdrOffset + ty ) ) )
|
2022-09-03 14:34:53 +00:00
|
|
|
{
|
|
|
|
HeaderTooltip( label );
|
|
|
|
|
|
|
|
if( IsMouseClicked( 0 ) )
|
|
|
|
{
|
|
|
|
m_showFull = !m_showFull;
|
|
|
|
}
|
|
|
|
if( IsMouseClicked( 2 ) )
|
|
|
|
{
|
2022-09-04 11:16:26 +00:00
|
|
|
const auto t0 = RangeBegin();
|
|
|
|
const auto t1 = RangeEnd();
|
|
|
|
if( t0 < t1 )
|
|
|
|
{
|
|
|
|
m_view.ZoomToRange( t0, t1 );
|
|
|
|
}
|
2022-09-03 14:34:53 +00:00
|
|
|
}
|
|
|
|
if( IsMouseClicked( 1 ) )
|
|
|
|
{
|
|
|
|
ImGui::OpenPopup( "menuPopup" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ImGui::BeginPopup( "menuPopup" ) )
|
|
|
|
{
|
|
|
|
if( ImGui::MenuItem( ICON_FA_EYE_SLASH " Hide" ) )
|
|
|
|
{
|
2022-09-04 12:22:12 +00:00
|
|
|
SetVisible( false );
|
2022-09-03 14:34:53 +00:00
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
}
|
|
|
|
ImGui::EndPopup();
|
|
|
|
}
|
|
|
|
|
2023-01-27 19:00:05 +00:00
|
|
|
yEnd += 0.2f * ostep;
|
|
|
|
AdjustThreadHeight( firstFrame, yBegin, yEnd );
|
2022-09-03 14:34:53 +00:00
|
|
|
|
|
|
|
ImGui::PopID();
|
|
|
|
}
|
|
|
|
|
2023-01-27 19:00:05 +00:00
|
|
|
void TimelineItem::AdjustThreadHeight( bool firstFrame, int yBegin, int yEnd )
|
2022-09-03 14:34:53 +00:00
|
|
|
{
|
2022-12-18 19:09:15 +00:00
|
|
|
const auto speed = 4.0;
|
|
|
|
const auto baseMove = 1.0;
|
2022-12-18 19:06:10 +00:00
|
|
|
|
2023-01-27 19:00:05 +00:00
|
|
|
const auto newHeight = yEnd - yBegin;
|
2022-12-18 19:06:10 +00:00
|
|
|
if( firstFrame )
|
2022-09-03 14:34:53 +00:00
|
|
|
{
|
2023-01-27 19:00:05 +00:00
|
|
|
m_height = newHeight;
|
2022-09-03 14:34:53 +00:00
|
|
|
}
|
2023-01-27 19:00:05 +00:00
|
|
|
else if( m_height != newHeight )
|
2022-09-03 14:34:53 +00:00
|
|
|
{
|
2023-01-27 19:00:05 +00:00
|
|
|
const auto diff = newHeight - m_height;
|
2022-12-18 19:06:10 +00:00
|
|
|
const auto preClampMove = diff * speed * ImGui::GetIO().DeltaTime;
|
|
|
|
if( diff > 0 )
|
2022-09-03 14:34:53 +00:00
|
|
|
{
|
2022-12-18 19:09:15 +00:00
|
|
|
const auto move = preClampMove + baseMove;
|
2023-01-27 19:00:05 +00:00
|
|
|
m_height = int( std::min<double>( m_height + move, newHeight ) );
|
2022-09-03 14:34:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-18 19:09:15 +00:00
|
|
|
const auto move = preClampMove - baseMove;
|
2023-01-27 19:00:05 +00:00
|
|
|
m_height = int( std::max<double>( m_height + move, newHeight ) );
|
2022-09-03 14:34:53 +00:00
|
|
|
}
|
2022-09-27 22:55:08 +00:00
|
|
|
s_wasActive = true;
|
2022-09-03 14:34:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TimelineItem::VisibilityCheckbox()
|
|
|
|
{
|
|
|
|
SmallCheckbox( HeaderLabel(), &m_visible );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|