Use TimelineContext data for drawing plots.

This commit is contained in:
Bartosz Taudul 2023-03-18 17:11:24 +01:00
parent 0ecdcbc13c
commit 26791f55d1
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
3 changed files with 15 additions and 11 deletions

View File

@ -107,7 +107,7 @@ int64_t TimelineItemPlot::RangeEnd() const
bool TimelineItemPlot::DrawContents( const TimelineContext& ctx, int& offset ) bool TimelineItemPlot::DrawContents( const TimelineContext& ctx, int& offset )
{ {
return m_view.DrawPlot( *m_plot, ctx.pxns, offset, ctx.wpos, ctx.hover, ctx.yMin, ctx.yMax ); return m_view.DrawPlot( ctx, *m_plot, offset );
} }
} }

View File

@ -120,7 +120,7 @@ public:
void HighlightThread( uint64_t thread ); void HighlightThread( uint64_t thread );
void ZoomToRange( int64_t start, int64_t end, bool pause = true ); void ZoomToRange( int64_t start, int64_t end, bool pause = true );
bool DrawPlot( PlotData& plot, double pxns, int& offset, const ImVec2& wpos, bool hover, float yMin, float yMax ); bool DrawPlot( const TimelineContext& ctx, PlotData& plot, int& offset );
bool DrawThread( const ThreadData& thread, double pxns, int& offset, const ImVec2& wpos, bool hover, float yMin, float yMax, bool ghostMode ); bool DrawThread( const ThreadData& thread, double pxns, int& offset, const ImVec2& wpos, bool hover, float yMin, float yMax, bool ghostMode );
void DrawThreadMessages( const ThreadData& thread, double pxns, int offset, const ImVec2& wpos, bool hover ); void DrawThreadMessages( const ThreadData& thread, double pxns, int offset, const ImVec2& wpos, bool hover );
void DrawThreadOverlays( const ThreadData& thread, const ImVec2& ul, const ImVec2& dr ); void DrawThreadOverlays( const ThreadData& thread, const ImVec2& ul, const ImVec2& dr );

View File

@ -4,31 +4,35 @@
#include "TracyImGui.hpp" #include "TracyImGui.hpp"
#include "TracyMouse.hpp" #include "TracyMouse.hpp"
#include "TracyPrint.hpp" #include "TracyPrint.hpp"
#include "TracyTimelineContext.hpp"
#include "TracyUtility.hpp" #include "TracyUtility.hpp"
#include "TracyView.hpp" #include "TracyView.hpp"
namespace tracy namespace tracy
{ {
bool View::DrawPlot( PlotData& plot, double pxns, int& offset, const ImVec2& wpos, bool hover, float yMin, float yMax ) bool View::DrawPlot( const TimelineContext& ctx, PlotData& plot, int& offset )
{ {
auto& vec = plot.data;
vec.ensure_sorted();
if( vec.front().time.Val() > m_vd.zvEnd || vec.back().time.Val() < m_vd.zvStart ) return false;
const auto PlotHeight = 100 * GetScale(); const auto PlotHeight = 100 * GetScale();
enum { MaxPoints = 128 }; enum { MaxPoints = 128 };
float tmpvec[MaxPoints*2]; float tmpvec[MaxPoints*2];
const auto w = ImGui::GetContentRegionAvail().x - 1;
const auto ty = ImGui::GetTextLineHeight();
auto draw = ImGui::GetWindowDrawList(); auto draw = ImGui::GetWindowDrawList();
const auto nspx = 1.0 / pxns; const auto& wpos = ctx.wpos;
const auto dpos = wpos + ImVec2( 0.5f, 0.5f ); const auto dpos = wpos + ImVec2( 0.5f, 0.5f );
const auto pxns = ctx.pxns;
auto& vec = plot.data; const auto nspx = ctx.nspx;
vec.ensure_sorted(); const auto w = ctx.w;
if( vec.front().time.Val() > m_vd.zvEnd || vec.back().time.Val() < m_vd.zvStart ) return false; const auto hover = ctx.hover;
const auto ty = ctx.ty;
auto yPos = wpos.y + offset; auto yPos = wpos.y + offset;
if( yPos + PlotHeight >= yMin && yPos <= yMax ) if( yPos + PlotHeight >= ctx.yMin && yPos <= ctx.yMax )
{ {
const auto color = GetPlotColor( plot, m_worker ); const auto color = GetPlotColor( plot, m_worker );
const auto bg = 0x22000000 | ( DarkenColorMore( color ) & 0xFFFFFF ); const auto bg = 0x22000000 | ( DarkenColorMore( color ) & 0xFFFFFF );