mirror of
https://github.com/wolfpld/tracy.git
synced 2026-08-31 23:48:26 +00:00
Rework the way the cropper computes its sizes and position
- No long assumes timelines are on the left of the window - Derive circle size from cropper width
This commit is contained in:
@@ -253,7 +253,7 @@ private:
|
||||
void DrawTimeline();
|
||||
void DrawSampleList( const TimelineContext& ctx, const std::vector<SamplesDraw>& drawList, const Vector<SampleData>& vec, int offset );
|
||||
void DrawZoneList( const TimelineContext& ctx, const std::vector<TimelineDraw>& drawList, int offset, uint64_t tid, int maxDepth, double margin );
|
||||
void DrawThreadCropper( const int depth, const uint64_t tid, const float xPos, const float yPos, const float ostep, const float radius, const float margin, const bool hasCtxSwitches );
|
||||
void DrawThreadCropper( const int depth, const uint64_t tid, const float xPos, const float yPos, const float ostep, const float cropperWidth, const bool hasCtxSwitches );
|
||||
void DrawContextSwitchList( const TimelineContext& ctx, const std::vector<ContextSwitchDraw>& drawList, const Vector<ContextSwitchData>& ctxSwitch, int offset, int endOffset, bool isFiber );
|
||||
int DispatchGpuZoneLevel( const Vector<short_ptr<GpuEvent>>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, uint64_t thread, float yMin, float yMax, int64_t begin, int drift );
|
||||
template<typename Adapter, typename V>
|
||||
|
||||
@@ -57,21 +57,21 @@ void View::DrawThread( const TimelineContext& ctx, const ThreadData& thread, con
|
||||
}
|
||||
|
||||
const auto yPos = wpos.y + offset;
|
||||
const float cropperWidth = ImGui::CalcTextSize( ICON_FA_CARET_DOWN ).x;
|
||||
const float cropperCircleRadius = ( cropperWidth - 2.0f * GetScale() ) / 2.0f ;
|
||||
const float cropperAdditionalMargin = cropperWidth + wpos.x; // We add the left window margin for symmetry
|
||||
|
||||
const auto* drawList = ImGui::GetWindowDrawList();
|
||||
const float croppperPosX = wpos.x;
|
||||
const float cropperWidth = ImGui::CalcTextSize( ICON_FA_CARET_DOWN ).x + 2.0f * GetScale();
|
||||
const float cropperAdditionalMargin = cropperWidth + ImGui::GetStyle().WindowBorderSize; // We add the left window margin for symmetry
|
||||
|
||||
// Display cropper if currently limited or if hovering the cropper area
|
||||
const auto threadDepthLimitIt = m_threadDepthLimit.find( thread.id );
|
||||
const bool croppingActive = ( threadDepthLimitIt != m_threadDepthLimit.end() && threadDepthLimitIt->second <= depth );
|
||||
const int croppedDepth = croppingActive ? threadDepthLimitIt->second : depth;
|
||||
const bool mouseInCropperDisplayZone = ctx.hover && ImGui::GetMousePos().x >= wpos.x && ImGui::GetMousePos().x < wpos.x + cropperAdditionalMargin && ImGui::GetMousePos().y > ctx.yMin && ImGui::GetMousePos().y < ctx.yMax;
|
||||
const bool mouseInCropperDisplayZone = ctx.hover && ImGui::GetMousePos().x >= croppperPosX && ImGui::GetMousePos().x < croppperPosX + cropperWidth && ImGui::GetMousePos().y > ctx.yMin && ImGui::GetMousePos().y < ctx.yMax;
|
||||
|
||||
const bool displayCropper = croppingActive || mouseInCropperDisplayZone;
|
||||
if( displayCropper )
|
||||
{
|
||||
const auto* drawList = ImGui::GetWindowDrawList();
|
||||
ImGui::PushClipRect( drawList->GetClipRectMin() + ImVec2( cropperAdditionalMargin, 0 ), drawList->GetClipRectMax(), true );
|
||||
ImGui::PushClipRect( ImVec2( croppperPosX + cropperAdditionalMargin, drawList->GetClipRectMin().y ), drawList->GetClipRectMax(), true );
|
||||
}
|
||||
if( !draw.empty() && yPos <= yMax && yPos + ostep * croppedDepth >= yMin )
|
||||
{
|
||||
@@ -99,7 +99,7 @@ void View::DrawThread( const TimelineContext& ctx, const ThreadData& thread, con
|
||||
if( displayCropper )
|
||||
{
|
||||
ImGui::PopClipRect();
|
||||
if( depth > 0 ) DrawThreadCropper( depth, thread.id, wpos.x, yPos, ostep, cropperCircleRadius, cropperWidth, hasCtxSwitch );
|
||||
if( depth > 0 ) DrawThreadCropper( depth, thread.id, croppperPosX, yPos, ostep, cropperWidth, hasCtxSwitch );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -605,7 +605,7 @@ void View::DrawZoneList( const TimelineContext& ctx, const std::vector<TimelineD
|
||||
}
|
||||
}
|
||||
|
||||
void View::DrawThreadCropper( const int depth, const uint64_t tid, const float xPos, const float yPos, const float ostep, const float radius, const float cropperWidth, const bool hasCtxSwitches )
|
||||
void View::DrawThreadCropper( const int depth, const uint64_t tid, const float xPos, const float yPos, const float ostep, const float cropperWidth, const bool hasCtxSwitches )
|
||||
{
|
||||
const ImVec2 mousePos = ImGui::GetMousePos();
|
||||
const bool clicked = ImGui::IsMouseClicked( 0 );
|
||||
@@ -616,6 +616,8 @@ void View::DrawThreadCropper( const int depth, const uint64_t tid, const float x
|
||||
if( !hasCtxSwitches && isCropped && depthLimit == 0 ) m_threadDepthLimit[tid] = 1;
|
||||
|
||||
const float cropperCenterX = xPos + cropperWidth / 2.0;
|
||||
const float hoverCircleThickness = GetScale();
|
||||
const float circleRadius = cropperWidth / 2.0 - 2.0f * GetScale();
|
||||
|
||||
const auto CircleCenterYForLine = [=]( int lane ){
|
||||
return yPos + ostep * ( lane + 0.5 );
|
||||
@@ -636,13 +638,13 @@ void View::DrawThreadCropper( const int depth, const uint64_t tid, const float x
|
||||
for( ; lane < depthLimit; lane++ )
|
||||
{
|
||||
const ImVec2 center = ImVec2( cropperCenterX, CircleCenterYForLine( lane ) );
|
||||
const float hradius = radius + 2.0f * GetScale();
|
||||
const float hradius = circleRadius + 2.0f * GetScale();
|
||||
const float dx = mousePos.x - center.x;
|
||||
const float dy = mousePos.y - center.y;
|
||||
|
||||
if( dx * dx + dy * dy <= hradius * hradius )
|
||||
{
|
||||
draw->AddCircle( center, hradius, 0xFFFFFFFF, 0, GetScale() );
|
||||
draw->AddCircle( center, hradius, 0xFFFFFFFF, 0, hoverCircleThickness );
|
||||
const float wPosX = ImGui::GetWindowPos().x + ImGui::GetWindowContentRegionMin().x;
|
||||
const float wSizeX = ImGui::GetWindowContentRegionMax().x;
|
||||
draw->AddLine( ImVec2( wPosX, yPos + ( lane + 1 ) * ostep ), ImVec2( wPosX + wSizeX, yPos + ( lane + 1 ) * ostep ), 0x880000FF, 2.0f * GetScale() );
|
||||
@@ -664,7 +666,7 @@ void View::DrawThreadCropper( const int depth, const uint64_t tid, const float x
|
||||
{
|
||||
color = 0xFF888888;
|
||||
}
|
||||
draw->AddCircleFilled( center, radius, color );
|
||||
draw->AddCircleFilled( center, circleRadius, color );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user