@@ -38,7 +38,7 @@ Profiler::~Profiler()
3838/* *
3939*/
4040int
41- RecursiveDrawScope (const Profiling::ProfilingScope& scope, ImDrawList* drawList, const ImVec2 start, const ImVec2 fullSize, ImVec2 pos, const ImVec2 canvas, const float fullFrameTime, const float startSection, const float endSection, const int level)
41+ RecursiveDrawScope (const Profiling::ProfilingScope& scope, Profiler::HighLightRegion& highlightRegion, ImDrawList* drawList, const ImVec2 start, const ImVec2 fullSize, ImVec2 pos, const ImVec2 canvas, const float fullFrameTime, const float startSection, const float endSection, const int level)
4242{
4343 const float startTime = startSection * fullFrameTime;
4444 const float endTime = endSection * fullFrameTime;
@@ -95,6 +95,15 @@ RecursiveDrawScope(const Profiling::ProfilingScope& scope, ImDrawList* drawList,
9595
9696 if (ImGui::IsMouseHoveringRect (bbMin, bbMax))
9797 {
98+ // record double-clicked region on the profiler
99+ if (ImGui::IsMouseDoubleClicked (ImGuiMouseButton_Left))
100+ {
101+ float normStart = (bbMin.x - start.x ) / canvas.x ;
102+ float normEnd = (bbMax.x - start.x ) / canvas.x ;
103+ highlightRegion.start = Math::clamp (normStart, 0 .0f , 1 .0f );
104+ highlightRegion.end = Math::clamp (normEnd, 0 .0f , 1 .0f );
105+ }
106+
98107 ImGui::BeginTooltip ();
99108 Util::String text = Util::String::Sprintf (" %s [%s] (%4.4f ms) in %s (%d)" , scope.name , scope.category .Value (), scope.duration * 1000 , scope.file , scope.line );
100109 ImGui::Text (text.AsCharPtr ());
@@ -113,7 +122,7 @@ RecursiveDrawScope(const Profiling::ProfilingScope& scope, ImDrawList* drawList,
113122 int deepest = level + 1 ;
114123 for (IndexT i = 0 ; i < scope.children .Size (); i++)
115124 {
116- int childLevel = RecursiveDrawScope (scope.children [i], drawList, start, fullSize, pos, canvas, fullFrameTime, startSection, endSection, level + 1 );
125+ int childLevel = RecursiveDrawScope (scope.children [i], highlightRegion, drawList, start, fullSize, pos, canvas, fullFrameTime, startSection, endSection, level + 1 );
117126 deepest = Math::max (deepest, childLevel);
118127 }
119128 return deepest;
@@ -256,6 +265,10 @@ Profiler::Run(SaveMode save)
256265 // Handle mouse scroll for timeline zoom
257266 ImGuiIO& io = ImGui::GetIO ();
258267 float mouseWheel = io.MouseWheel ;
268+ if (io.KeyShift )
269+ {
270+ ImGui::SetMouseCursor (ImGuiMouseCursor_Hand);
271+ }
259272 if (mouseWheel != 0 .0f && ImGui::IsWindowHovered () && io.KeyShift )
260273 {
261274 float range = this ->timeEnd - this ->timeStart ;
@@ -335,7 +348,7 @@ Profiler::Run(SaveMode save)
335348 if (ctx.topLevelScopes .Size () > 0 ) for (IndexT i = 0 ; i < ctx.topLevelScopes .Size (); i++)
336349 {
337350 const Profiling::ProfilingScope& scope = ctx.topLevelScopes [i];
338- int level = RecursiveDrawScope (scope, drawList, start, fullSize, pos, canvasSize, this ->currentFrameTime , this ->timeStart , this ->timeEnd , 0 );
351+ int level = RecursiveDrawScope (scope, this -> highlightRegion , drawList, start, fullSize, pos, canvasSize, this ->currentFrameTime , this ->timeStart , this ->timeEnd , 0 );
339352 levels = Math::max (levels, level);
340353 }
341354 else
@@ -354,6 +367,29 @@ Profiler::Run(SaveMode save)
354367 ImGui::PopFont ();
355368 }
356369 }
370+
371+ // draw highlight overlay/lines if user double-clicked a scope
372+ if (this ->highlightRegion .start >= 0 .0f && this ->highlightRegion .end > this ->highlightRegion .start )
373+ {
374+ ImVec2 canvasSize = ImGui::GetContentRegionAvail ();
375+ canvasSize.x *= timeWindow;
376+ float x0 = start.x + this ->highlightRegion .start * canvasSize.x ;
377+ float x1 = start.x + this ->highlightRegion .end * canvasSize.x ;
378+ ImU32 overlayCol = IM_COL32 (255 , 255 , 0 , 60 ); // translucent yellow
379+ drawList->AddRectFilled (ImVec2 (x0, start.y ), ImVec2 (x1, fullSize.y ), overlayCol);
380+ drawList->AddLine (ImVec2 (x0, start.y ), ImVec2 (x0, fullSize.y ), IM_COL32_WHITE, 1 .0f );
381+ drawList->AddLine (ImVec2 (x1, start.y ), ImVec2 (x1, fullSize.y ), IM_COL32_WHITE, 1 .0f );
382+ // clear highlight on right-click inside region
383+ if (ImGui::IsWindowHovered () && ImGui::IsMouseClicked (ImGuiMouseButton_Right))
384+ {
385+ ImVec2 mp = ImGui::GetMousePos ();
386+ float relX = (mp.x - start.x ) / canvasSize.x ;
387+ if (relX >= this ->highlightRegion .start && relX <= this ->highlightRegion .end )
388+ {
389+ this ->highlightRegion .start = this ->highlightRegion .end = -1 .0f ;
390+ }
391+ } }
392+
357393 if (ImGui::CollapsingHeader (" GPU" ))
358394 {
359395 ImGui::PushFont (Dynui::ImguiSmallFont);
0 commit comments