Store common constants in context variable.

This commit is contained in:
Bartosz Taudul 2023-03-14 02:11:33 +01:00
parent 66d8dab925
commit b6b6e1edcf
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
2 changed files with 18 additions and 4 deletions

View File

@ -1,7 +1,6 @@
#include <algorithm> #include <algorithm>
#include "imgui.h" #include "TracyImGui.hpp"
#include "TracyTimelineController.hpp" #include "TracyTimelineController.hpp"
namespace tracy namespace tracy
@ -107,11 +106,19 @@ void TimelineController::End( double pxns, const ImVec2& wpos, bool hover, bool
UpdateCenterItem(); UpdateCenterItem();
} }
TimelineContext ctx;
ctx.w = ImGui::GetContentRegionAvail().x - 1;
ctx.ty = ImGui::GetTextLineHeight();
ctx.scale = GetScale();
ctx.pxns = pxns;
ctx.nspx = 1.0 / pxns;
ctx.wpos = wpos;
for( auto& item : m_items ) for( auto& item : m_items )
{ {
if( item->WantPreprocess() && item->IsVisible() ) if( item->WantPreprocess() && item->IsVisible() )
{ {
item->Preprocess(); item->Preprocess( ctx );
} }
} }

View File

@ -12,6 +12,13 @@ namespace tracy
class View; class View;
class Worker; class Worker;
struct TimelineContext
{
float w, ty, scale;
double pxns, nspx;
ImVec2 wpos;
};
class TimelineItem class TimelineItem
{ {
public: public:
@ -22,7 +29,7 @@ public:
void Draw( bool firstFrame, double pxns, int yOffset, const ImVec2& wpos, bool hover, float yMin, float yMax ); void Draw( bool firstFrame, double pxns, int yOffset, const ImVec2& wpos, bool hover, float yMin, float yMax );
bool WantPreprocess() const { return m_wantPreprocess; } bool WantPreprocess() const { return m_wantPreprocess; }
virtual void Preprocess() { assert( false ); } virtual void Preprocess( const TimelineContext& ctx ) { assert( false ); }
void VisibilityCheckbox(); void VisibilityCheckbox();
virtual void SetVisible( bool visible ) { m_visible = visible; } virtual void SetVisible( bool visible ) { m_visible = visible; }