From 0a32929b0b6940474b894a5e06d2bc1dfa76c4fe Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sat, 18 Mar 2023 16:07:56 +0100 Subject: [PATCH] Move hover flag to TimelineContext. --- server/TracyTimelineController.cpp | 3 ++- server/TracyTimelineItem.cpp | 8 ++++---- server/TracyTimelineItem.hpp | 7 ++++--- server/TracyTimelineItemCpuData.cpp | 4 ++-- server/TracyTimelineItemCpuData.hpp | 2 +- server/TracyTimelineItemGpu.cpp | 8 ++++---- server/TracyTimelineItemGpu.hpp | 4 ++-- server/TracyTimelineItemPlot.cpp | 8 ++++---- server/TracyTimelineItemPlot.hpp | 4 ++-- server/TracyTimelineItemThread.cpp | 12 ++++++------ server/TracyTimelineItemThread.hpp | 4 ++-- 11 files changed, 33 insertions(+), 31 deletions(-) diff --git a/server/TracyTimelineController.cpp b/server/TracyTimelineController.cpp index 8e3393cb..1116ee2d 100644 --- a/server/TracyTimelineController.cpp +++ b/server/TracyTimelineController.cpp @@ -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; } diff --git a/server/TracyTimelineItem.cpp b/server/TracyTimelineItem.cpp index 7b75b85c..533b05cd 100644 --- a/server/TracyTimelineItem.cpp +++ b/server/TracyTimelineItem.cpp @@ -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 ); diff --git a/server/TracyTimelineItem.hpp b/server/TracyTimelineItem.hpp index d2727a07..6e6b769e 100644 --- a/server/TracyTimelineItem.hpp +++ b/server/TracyTimelineItem.hpp @@ -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; } diff --git a/server/TracyTimelineItemCpuData.cpp b/server/TracyTimelineItemCpuData.cpp index 9e0353d4..da4f85b8 100644 --- a/server/TracyTimelineItemCpuData.cpp +++ b/server/TracyTimelineItemCpuData.cpp @@ -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 ); } } diff --git a/server/TracyTimelineItemCpuData.hpp b/server/TracyTimelineItemCpuData.hpp index 2bb7e517..85e42606 100644 --- a/server/TracyTimelineItemCpuData.hpp +++ b/server/TracyTimelineItemCpuData.hpp @@ -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; }; diff --git a/server/TracyTimelineItemGpu.cpp b/server/TracyTimelineItemGpu.cpp index 2fb97135..33d7b9a5 100644 --- a/server/TracyTimelineItemGpu.cpp +++ b/server/TracyTimelineItemGpu.cpp @@ -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 ); } } diff --git a/server/TracyTimelineItemGpu.hpp b/server/TracyTimelineItemGpu.hpp index b1fe8418..5bb645b0 100644 --- a/server/TracyTimelineItemGpu.hpp +++ b/server/TracyTimelineItemGpu.hpp @@ -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; diff --git a/server/TracyTimelineItemPlot.cpp b/server/TracyTimelineItemPlot.cpp index b49d41ae..673f778e 100644 --- a/server/TracyTimelineItemPlot.cpp +++ b/server/TracyTimelineItemPlot.cpp @@ -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 ); } } diff --git a/server/TracyTimelineItemPlot.hpp b/server/TracyTimelineItemPlot.hpp index 8cf84d8b..611c6a13 100644 --- a/server/TracyTimelineItemPlot.hpp +++ b/server/TracyTimelineItemPlot.hpp @@ -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; diff --git a/server/TracyTimelineItemThread.cpp b/server/TracyTimelineItemThread.cpp index dff11d4a..6e8e2b9e 100644 --- a/server/TracyTimelineItemThread.cpp +++ b/server/TracyTimelineItemThread.cpp @@ -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(); diff --git a/server/TracyTimelineItemThread.hpp b/server/TracyTimelineItemThread.hpp index 57ad3b73..153435f8 100644 --- a/server/TracyTimelineItemThread.hpp +++ b/server/TracyTimelineItemThread.hpp @@ -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;