Push timline context to Draw and DrawContents functions.

This commit is contained in:
Bartosz Taudul 2023-03-14 02:24:23 +01:00
parent b6b6e1edcf
commit c81ef177ab
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
11 changed files with 21 additions and 20 deletions

View File

@ -127,7 +127,7 @@ void TimelineController::End( double pxns, const ImVec2& wpos, bool hover, bool
for( auto& item : m_items ) for( auto& item : m_items )
{ {
auto currentFrameItemHeight = item->GetNextFrameHeight(); auto currentFrameItemHeight = item->GetNextFrameHeight();
item->Draw( m_firstFrame, pxns, yOffset, wpos, hover, yMin, yMax ); item->Draw( m_firstFrame, ctx, yOffset, hover, yMin, yMax );
if( m_firstFrame ) currentFrameItemHeight = item->GetNextFrameHeight(); if( m_firstFrame ) currentFrameItemHeight = item->GetNextFrameHeight();
yOffset += currentFrameItemHeight; yOffset += currentFrameItemHeight;
} }

View File

@ -19,7 +19,7 @@ TimelineItem::TimelineItem( View& view, Worker& worker, const void* key, bool wa
{ {
} }
void TimelineItem::Draw( bool firstFrame, double pxns, int yOffset, const ImVec2& wpos, bool hover, float yMin, float yMax ) void TimelineItem::Draw( bool firstFrame, const TimelineContext& ctx, int yOffset, bool hover, float yMin, float yMax )
{ {
const auto yBegin = yOffset; const auto yBegin = yOffset;
auto yEnd = yOffset; auto yEnd = yOffset;
@ -31,9 +31,10 @@ void TimelineItem::Draw( bool firstFrame, double pxns, int yOffset, const ImVec2
} }
if( IsEmpty() ) return; if( IsEmpty() ) return;
const auto w = ImGui::GetContentRegionAvail().x - 1; const auto w = ctx.w;
const auto ty = ImGui::GetTextLineHeight(); const auto ty = ctx.ty;
const auto ostep = ty + 1; const auto ostep = ty + 1;
const auto& wpos = ctx.wpos;
const auto yPos = wpos.y + yBegin; const auto yPos = wpos.y + yBegin;
const auto dpos = wpos + ImVec2( 0.5f, 0.5f ); const auto dpos = wpos + ImVec2( 0.5f, 0.5f );
auto draw = ImGui::GetWindowDrawList(); auto draw = ImGui::GetWindowDrawList();
@ -44,7 +45,7 @@ void TimelineItem::Draw( bool firstFrame, double pxns, int yOffset, const ImVec2
yEnd += ostep; yEnd += ostep;
if( m_showFull ) if( m_showFull )
{ {
if( !DrawContents( pxns, yEnd, wpos, hover, yMin, yMax ) && !m_view.GetViewData().drawEmptyLabels ) if( !DrawContents( ctx, yEnd, hover, yMin, yMax ) && !m_view.GetViewData().drawEmptyLabels )
{ {
yEnd = yBegin; yEnd = yBegin;
AdjustThreadHeight( firstFrame, yBegin, yEnd ); AdjustThreadHeight( firstFrame, yBegin, yEnd );
@ -79,7 +80,7 @@ void TimelineItem::Draw( bool firstFrame, double pxns, int yOffset, const ImVec2
if( m_showFull ) if( m_showFull )
{ {
DrawLine( draw, dpos + ImVec2( 0, hdrOffset + ty - 1 ), dpos + ImVec2( w, hdrOffset + ty - 1 ), HeaderLineColor() ); DrawLine( draw, dpos + ImVec2( 0, hdrOffset + ty - 1 ), dpos + ImVec2( w, hdrOffset + ty - 1 ), HeaderLineColor() );
HeaderExtraContents( hdrOffset, wpos, labelWidth, pxns, hover ); HeaderExtraContents( hdrOffset, wpos, labelWidth, ctx.pxns, hover );
} }
if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( 0, hdrOffset ), wpos + ImVec2( ty + labelWidth, hdrOffset + ty ) ) ) if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( 0, hdrOffset ), wpos + ImVec2( ty + labelWidth, hdrOffset + ty ) ) )

View File

@ -26,7 +26,7 @@ public:
virtual ~TimelineItem() = default; virtual ~TimelineItem() = default;
// draws the timeline item and also updates the next frame height value // draws the timeline item and also updates the next frame height value
void Draw( bool firstFrame, double pxns, int yOffset, const ImVec2& wpos, bool hover, float yMin, float yMax ); void Draw( bool firstFrame, const TimelineContext& ctx, int yOffset, bool hover, float yMin, float yMax );
bool WantPreprocess() const { return m_wantPreprocess; } bool WantPreprocess() const { return m_wantPreprocess; }
virtual void Preprocess( const TimelineContext& ctx ) { assert( false ); } virtual void Preprocess( const TimelineContext& ctx ) { assert( false ); }
@ -54,7 +54,7 @@ protected:
virtual int64_t RangeBegin() const = 0; virtual int64_t RangeBegin() const = 0;
virtual int64_t RangeEnd() const = 0; virtual int64_t RangeEnd() const = 0;
virtual bool DrawContents( double pxns, int& offset, const ImVec2& wpos, bool hover, float yMin, float yMax ) = 0; virtual bool DrawContents( const TimelineContext& ctx, int& offset, bool hover, float yMin, float yMax ) = 0;
virtual void DrawOverlay( const ImVec2& ul, const ImVec2& dr ) {} virtual void DrawOverlay( const ImVec2& ul, const ImVec2& dr ) {}
virtual bool IsEmpty() const { return false; } virtual bool IsEmpty() const { return false; }

View File

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

View File

@ -24,7 +24,7 @@ protected:
int64_t RangeBegin() const override; int64_t RangeBegin() const override;
int64_t RangeEnd() const override; int64_t RangeEnd() const override;
bool DrawContents( double pxns, int& offset, const ImVec2& wpos, bool hover, float yMin, float yMax ) override; bool DrawContents( const TimelineContext& ctx, int& offset, bool hover, float yMin, float yMax ) override;
bool IsEmpty() const override; bool IsEmpty() const override;
}; };

View File

@ -188,9 +188,9 @@ int64_t TimelineItemGpu::RangeEnd() const
return t; return t;
} }
bool TimelineItemGpu::DrawContents( double pxns, int& offset, const ImVec2& wpos, bool hover, float yMin, float yMax ) bool TimelineItemGpu::DrawContents( const TimelineContext& ctx, int& offset, bool hover, float yMin, float yMax )
{ {
return m_view.DrawGpu( *m_gpu, pxns, offset, wpos, hover, yMin, yMax ); return m_view.DrawGpu( *m_gpu, ctx.pxns, offset, ctx.wpos, hover, yMin, yMax );
} }
} }

View File

@ -26,7 +26,7 @@ protected:
void HeaderTooltip( const char* label ) 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( int offset, const ImVec2& wpos, float labelWidth, double pxns, bool hover ) override;
bool DrawContents( double pxns, int& offset, const ImVec2& wpos, bool hover, float yMin, float yMax ) override; bool DrawContents( const TimelineContext& ctx, int& offset, bool hover, float yMin, float yMax ) override;
bool IsEmpty() const override; bool IsEmpty() const override;

View File

@ -104,9 +104,9 @@ int64_t TimelineItemPlot::RangeEnd() const
return m_plot->data.back().time.Val(); return m_plot->data.back().time.Val();
} }
bool TimelineItemPlot::DrawContents( double pxns, int& offset, const ImVec2& wpos, bool hover, float yMin, float yMax ) bool TimelineItemPlot::DrawContents( const TimelineContext& ctx, int& offset, bool hover, float yMin, float yMax )
{ {
return m_view.DrawPlot( *m_plot, pxns, offset, wpos, hover, yMin, yMax ); return m_view.DrawPlot( *m_plot, ctx.pxns, offset, ctx.wpos, hover, yMin, yMax );
} }
} }

View File

@ -24,7 +24,7 @@ protected:
void HeaderTooltip( const char* label ) 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( int offset, const ImVec2& wpos, float labelWidth, double pxns, bool hover ) override;
bool DrawContents( double pxns, int& offset, const ImVec2& wpos, bool hover, float yMin, float yMax ) override; bool DrawContents( const TimelineContext& ctx, int& offset, bool hover, float yMin, float yMax ) override;
bool IsEmpty() const override; bool IsEmpty() const override;

View File

@ -252,9 +252,9 @@ void TimelineItemThread::HeaderExtraContents( int offset, const ImVec2& wpos, fl
#endif #endif
} }
bool TimelineItemThread::DrawContents( double pxns, int& offset, const ImVec2& wpos, bool hover, float yMin, float yMax ) bool TimelineItemThread::DrawContents( const TimelineContext& ctx, int& offset, bool hover, float yMin, float yMax )
{ {
const auto res = m_view.DrawThread( *m_thread, pxns, offset, wpos, hover, yMin, yMax, m_ghost ); const auto res = m_view.DrawThread( *m_thread, ctx.pxns, offset, ctx.wpos, hover, yMin, yMax, m_ghost );
if( !res ) if( !res )
{ {
auto& crash = m_worker.GetCrashEvent(); auto& crash = m_worker.GetCrashEvent();

View File

@ -24,7 +24,7 @@ protected:
void HeaderTooltip( const char* label ) 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( int offset, const ImVec2& wpos, float labelWidth, double pxns, bool hover ) override;
bool DrawContents( double pxns, int& offset, const ImVec2& wpos, bool hover, float yMin, float yMax ) override; bool DrawContents( const TimelineContext& ctx, int& offset, bool hover, float yMin, float yMax ) override;
void DrawOverlay( const ImVec2& ul, const ImVec2& dr ) override; void DrawOverlay( const ImVec2& ul, const ImVec2& dr ) override;
bool IsEmpty() const override; bool IsEmpty() const override;