Move hover flag to TimelineContext.

This commit is contained in:
Bartosz Taudul 2023-03-18 16:07:56 +01:00
parent c75bec9122
commit 0a32929b0b
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
11 changed files with 33 additions and 31 deletions

View File

@ -115,6 +115,7 @@ void TimelineController::End( double pxns, const ImVec2& wpos, bool hover, bool
ctx.pxns = pxns;
ctx.nspx = 1.0 / pxns;
ctx.wpos = wpos;
ctx.hover = hover;
for( auto& item : m_items )
{
@ -129,7 +130,7 @@ void TimelineController::End( double pxns, const ImVec2& wpos, bool hover, bool
for( auto& item : m_items )
{
auto currentFrameItemHeight = item->GetNextFrameHeight();
item->Draw( m_firstFrame, ctx, yOffset, hover );
item->Draw( m_firstFrame, ctx, yOffset );
if( m_firstFrame ) currentFrameItemHeight = item->GetNextFrameHeight();
yOffset += currentFrameItemHeight;
}

View File

@ -19,7 +19,7 @@ TimelineItem::TimelineItem( View& view, Worker& worker, const void* key, bool wa
{
}
void TimelineItem::Draw( bool firstFrame, const TimelineContext& ctx, int yOffset, bool hover )
void TimelineItem::Draw( bool firstFrame, const TimelineContext& ctx, int yOffset )
{
const auto yBegin = yOffset;
auto yEnd = yOffset;
@ -45,7 +45,7 @@ void TimelineItem::Draw( bool firstFrame, const TimelineContext& ctx, int yOffse
yEnd += ostep;
if( m_showFull )
{
if( !DrawContents( ctx, yEnd, hover ) && !m_view.GetViewData().drawEmptyLabels )
if( !DrawContents( ctx, yEnd ) && !m_view.GetViewData().drawEmptyLabels )
{
yEnd = yBegin;
AdjustThreadHeight( firstFrame, yBegin, yEnd );
@ -80,10 +80,10 @@ void TimelineItem::Draw( bool firstFrame, const TimelineContext& ctx, int yOffse
if( m_showFull )
{
DrawLine( draw, dpos + ImVec2( 0, hdrOffset + ty - 1 ), dpos + ImVec2( w, hdrOffset + ty - 1 ), HeaderLineColor() );
HeaderExtraContents( hdrOffset, wpos, labelWidth, ctx.pxns, hover );
HeaderExtraContents( ctx, hdrOffset, labelWidth );
}
if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( 0, hdrOffset ), wpos + ImVec2( ty + labelWidth, hdrOffset + ty ) ) )
if( ctx.hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( 0, hdrOffset ), wpos + ImVec2( ty + labelWidth, hdrOffset + ty ) ) )
{
HeaderTooltip( label );

View File

@ -18,6 +18,7 @@ struct TimelineContext
float yMin, yMax;
double pxns, nspx;
ImVec2 wpos;
bool hover;
};
class TimelineItem
@ -27,7 +28,7 @@ public:
virtual ~TimelineItem() = default;
// draws the timeline item and also updates the next frame height value
void Draw( bool firstFrame, const TimelineContext& ctx, int yOffset, bool hover );
void Draw( bool firstFrame, const TimelineContext& ctx, int yOffset );
bool WantPreprocess() const { return m_wantPreprocess; }
virtual void Preprocess( const TimelineContext& ctx ) { assert( false ); }
@ -50,12 +51,12 @@ protected:
virtual const char* HeaderLabel() const = 0;
virtual void HeaderTooltip( const char* label ) const {};
virtual void HeaderExtraContents( int offset, const ImVec2& wpos, float labelWidth, double pxns, bool hover ) {};
virtual void HeaderExtraContents( const TimelineContext& ctx, int offset, float labelWidth ) {};
virtual int64_t RangeBegin() const = 0;
virtual int64_t RangeEnd() const = 0;
virtual bool DrawContents( const TimelineContext& ctx, int& offset, bool hover ) = 0;
virtual bool DrawContents( const TimelineContext& ctx, int& offset ) = 0;
virtual void DrawOverlay( const ImVec2& ul, const ImVec2& dr ) {}
virtual bool IsEmpty() const { return false; }

View File

@ -38,9 +38,9 @@ int64_t TimelineItemCpuData::RangeEnd() const
return -1;
}
bool TimelineItemCpuData::DrawContents( const TimelineContext& ctx, int& offset, bool hover )
bool TimelineItemCpuData::DrawContents( const TimelineContext& ctx, int& offset )
{
return m_view.DrawCpuData( ctx.pxns, offset, ctx.wpos, hover, ctx.yMin, ctx.yMax );
return m_view.DrawCpuData( ctx.pxns, offset, ctx.wpos, ctx.hover, ctx.yMin, ctx.yMax );
}
}

View File

@ -24,7 +24,7 @@ protected:
int64_t RangeBegin() const override;
int64_t RangeEnd() const override;
bool DrawContents( const TimelineContext& ctx, int& offset, bool hover ) override;
bool DrawContents( const TimelineContext& ctx, int& offset ) override;
bool IsEmpty() const override;
};

View File

@ -124,7 +124,7 @@ void TimelineItemGpu::HeaderTooltip( const char* label ) const
ImGui::EndTooltip();
}
void TimelineItemGpu::HeaderExtraContents( int offset, const ImVec2& wpos, float labelWidth, double pxns, bool hover )
void TimelineItemGpu::HeaderExtraContents( const TimelineContext& ctx, int offset, float labelWidth )
{
if( m_gpu->name.Active() )
{
@ -133,7 +133,7 @@ void TimelineItemGpu::HeaderExtraContents( int offset, const ImVec2& wpos, float
char buf[64];
sprintf( buf, "%s context %i", GpuContextNames[(int)m_gpu->type], m_idx );
draw->AddText( wpos + ImVec2( ty * 1.5f + labelWidth, offset ), HeaderColorInactive(), buf );
draw->AddText( ctx.wpos + ImVec2( ty * 1.5f + labelWidth, offset ), HeaderColorInactive(), buf );
}
}
@ -188,9 +188,9 @@ int64_t TimelineItemGpu::RangeEnd() const
return t;
}
bool TimelineItemGpu::DrawContents( const TimelineContext& ctx, int& offset, bool hover )
bool TimelineItemGpu::DrawContents( const TimelineContext& ctx, int& offset )
{
return m_view.DrawGpu( *m_gpu, ctx.pxns, offset, ctx.wpos, hover, ctx.yMin, ctx.yMax );
return m_view.DrawGpu( *m_gpu, ctx.pxns, offset, ctx.wpos, ctx.hover, ctx.yMin, ctx.yMax );
}
}

View File

@ -24,9 +24,9 @@ protected:
int64_t RangeEnd() const override;
void HeaderTooltip( const char* label ) const override;
void HeaderExtraContents( int offset, const ImVec2& wpos, float labelWidth, double pxns, bool hover ) override;
void HeaderExtraContents( const TimelineContext& ctx, int offset, float labelWidth ) override;
bool DrawContents( const TimelineContext& ctx, int& offset, bool hover ) override;
bool DrawContents( const TimelineContext& ctx, int& offset ) override;
bool IsEmpty() const override;

View File

@ -84,14 +84,14 @@ void TimelineItemPlot::HeaderTooltip( const char* label ) const
ImGui::EndTooltip();
}
void TimelineItemPlot::HeaderExtraContents( int offset, const ImVec2& wpos, float labelWidth, double pxns, bool hover )
void TimelineItemPlot::HeaderExtraContents( const TimelineContext& ctx, int offset, float labelWidth )
{
auto draw = ImGui::GetWindowDrawList();
const auto ty = ImGui::GetTextLineHeight();
char tmp[128];
sprintf( tmp, "(y-range: %s, visible data points: %s)", FormatPlotValue( m_plot->rMax - m_plot->rMin, m_plot->format ), RealToString( m_plot->num ) );
draw->AddText( wpos + ImVec2( ty * 1.5f + labelWidth, offset ), 0xFF226E6E, tmp );
draw->AddText( ctx.wpos + ImVec2( ty * 1.5f + labelWidth, offset ), 0xFF226E6E, tmp );
}
int64_t TimelineItemPlot::RangeBegin() const
@ -104,9 +104,9 @@ int64_t TimelineItemPlot::RangeEnd() const
return m_plot->data.back().time.Val();
}
bool TimelineItemPlot::DrawContents( const TimelineContext& ctx, int& offset, bool hover )
bool TimelineItemPlot::DrawContents( const TimelineContext& ctx, int& offset )
{
return m_view.DrawPlot( *m_plot, ctx.pxns, offset, ctx.wpos, hover, ctx.yMin, ctx.yMax );
return m_view.DrawPlot( *m_plot, ctx.pxns, offset, ctx.wpos, ctx.hover, ctx.yMin, ctx.yMax );
}
}

View File

@ -22,9 +22,9 @@ protected:
int64_t RangeEnd() const override;
void HeaderTooltip( const char* label ) const override;
void HeaderExtraContents( int offset, const ImVec2& wpos, float labelWidth, double pxns, bool hover ) override;
void HeaderExtraContents( const TimelineContext& ctx, int offset, float labelWidth ) override;
bool DrawContents( const TimelineContext& ctx, int& offset, bool hover ) override;
bool DrawContents( const TimelineContext& ctx, int& offset ) override;
bool IsEmpty() const override;

View File

@ -226,9 +226,9 @@ void TimelineItemThread::HeaderTooltip( const char* label ) const
ImGui::EndTooltip();
}
void TimelineItemThread::HeaderExtraContents( int offset, const ImVec2& wpos, float labelWidth, double pxns, bool hover )
void TimelineItemThread::HeaderExtraContents( const TimelineContext& ctx, int offset, float labelWidth )
{
m_view.DrawThreadMessages( *m_thread, pxns, offset, wpos, hover );
m_view.DrawThreadMessages( *m_thread, ctx.pxns, offset, ctx.wpos, ctx.hover );
#ifndef TRACY_NO_STATISTICS
const bool hasGhostZones = m_worker.AreGhostZonesReady() && !m_thread->ghostZones.empty();
@ -238,10 +238,10 @@ void TimelineItemThread::HeaderExtraContents( int offset, const ImVec2& wpos, fl
const auto ty = ImGui::GetTextLineHeight();
const auto color = m_ghost ? 0xFFAA9999 : 0x88AA7777;
draw->AddText( wpos + ImVec2( 1.5f * ty + labelWidth, offset ), color, ICON_FA_GHOST );
draw->AddText( ctx.wpos + ImVec2( 1.5f * ty + labelWidth, offset ), color, ICON_FA_GHOST );
float ghostSz = ImGui::CalcTextSize( ICON_FA_GHOST ).x;
if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( 1.5f * ty + labelWidth, offset ), wpos + ImVec2( 1.5f * ty + labelWidth + ghostSz, offset + ty ) ) )
if( ctx.hover && ImGui::IsMouseHoveringRect( ctx.wpos + ImVec2( 1.5f * ty + labelWidth, offset ), ctx.wpos + ImVec2( 1.5f * ty + labelWidth + ghostSz, offset + ty ) ) )
{
if( IsMouseClicked( 0 ) )
{
@ -252,9 +252,9 @@ void TimelineItemThread::HeaderExtraContents( int offset, const ImVec2& wpos, fl
#endif
}
bool TimelineItemThread::DrawContents( const TimelineContext& ctx, int& offset, bool hover )
bool TimelineItemThread::DrawContents( const TimelineContext& ctx, int& offset )
{
const auto res = m_view.DrawThread( *m_thread, ctx.pxns, offset, ctx.wpos, hover, ctx.yMin, ctx.yMax, m_ghost );
const auto res = m_view.DrawThread( *m_thread, ctx.pxns, offset, ctx.wpos, ctx.hover, ctx.yMin, ctx.yMax, m_ghost );
if( !res )
{
auto& crash = m_worker.GetCrashEvent();

View File

@ -22,9 +22,9 @@ protected:
int64_t RangeEnd() const override;
void HeaderTooltip( const char* label ) const override;
void HeaderExtraContents( int offset, const ImVec2& wpos, float labelWidth, double pxns, bool hover ) override;
void HeaderExtraContents( const TimelineContext& ctx, int offset, float labelWidth ) override;
bool DrawContents( const TimelineContext& ctx, int& offset, bool hover ) override;
bool DrawContents( const TimelineContext& ctx, int& offset ) override;
void DrawOverlay( const ImVec2& ul, const ImVec2& dr ) override;
bool IsEmpty() const override;