From 3dd80c5288692fc11d89abf1b9e53079d516284e Mon Sep 17 00:00:00 2001 From: Simon van Bernem Date: Fri, 7 Aug 2020 10:24:13 +0200 Subject: [PATCH 1/7] DrawStripedRect can now draw screen-space stripes Added two parameters to DrawStripedRect: fix_stripes_in_screen_space aligns the stripes to screen space. This leads to the stripes of any stripe rect being drawn aligning. Also added inverted, which flips the empty and filled part of the striped rect. This is used to make statRange and findZone stripes interleave, when they overlap. --- server/TracyImGui.hpp | 21 ++++++++++++++++++--- server/TracyView.cpp | 6 +++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/server/TracyImGui.hpp b/server/TracyImGui.hpp index 09d248eb..21b236ac 100644 --- a/server/TracyImGui.hpp +++ b/server/TracyImGui.hpp @@ -164,7 +164,7 @@ namespace tracy return res; } - static void DrawStripedRect( ImDrawList* draw, double x0, double y0, double x1, double y1, double sw, uint32_t color ) + static void DrawStripedRect( ImDrawList* draw, double x0, double y0, double x1, double y1, double sw, uint32_t color, bool fix_stripes_in_screen_space, bool inverted ) { assert( x1 >= x0 ); assert( y1 >= y0 ); @@ -183,8 +183,23 @@ namespace tracy const auto rw = x1 - x0; const auto rh = y1 - y0; - const auto v0 = ImVec2( x0, y0 - rw ); - const auto cnt = int( ( rh + rw + sw*2 ) / ( sw*2 ) ); + auto v0 = ImVec2( x0, y0 - rw); + + if (fix_stripes_in_screen_space) + { + const auto window_width = double(ImGui::GetWindowHeight()); + const auto flipped_v0y = window_width - v0.y; //we transform into a y-is-up coordinate space to achieve upper-left to lower-right stripes. If we didn't, we would calculate values for lower-left to upper-right + + const auto manhatten_distance = x0 + flipped_v0y; + const auto in_multiples_of_2_times_sw = int(manhatten_distance / (sw * 2)); + + const auto floored_manhatten_distance = double(in_multiples_of_2_times_sw * sw * 2); //floor in terms of 2 * stripe width + + const auto corrected_flipped_v0y = (floored_manhatten_distance - x0); //we transform back into y-is-down imgui space + v0.y = window_width - corrected_flipped_v0y - double(inverted * sw); + } + + const auto cnt = int( ( rh + rw + 2*sw*2 ) / ( sw*2 ) ); for( int i=0; iPathLineTo( v0 + ImVec2( 0, i*sw*2 ) ); diff --git a/server/TracyView.cpp b/server/TracyView.cpp index e1e10758..76984a35 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -3227,7 +3227,7 @@ void View::DrawZones() { const auto px0 = ( m_findZone.range.min - m_vd.zvStart ) * pxns; const auto px1 = std::max( px0 + std::max( 1.0, pxns * 0.5 ), ( m_findZone.range.max - m_vd.zvStart ) * pxns ); - DrawStripedRect( draw, wpos.x + px0, linepos.y, wpos.x + px1, linepos.y + lineh, 10 * ImGui::GetTextLineHeight() / 15.f, 0x2288DD88 ); + DrawStripedRect( draw, wpos.x + px0, linepos.y, wpos.x + px1, linepos.y + lineh, 10 * ImGui::GetTextLineHeight() / 15.f, 0x2288DD88, true, true ); draw->AddLine( ImVec2( wpos.x + px0, linepos.y ), ImVec2( wpos.x + px0, linepos.y + lineh ), m_findZone.range.hiMin ? 0x9988DD88 : 0x3388DD88, m_findZone.range.hiMin ? 2 : 1 ); draw->AddLine( ImVec2( wpos.x + px1, linepos.y ), ImVec2( wpos.x + px1, linepos.y + lineh ), m_findZone.range.hiMax ? 0x9988DD88 : 0x3388DD88, m_findZone.range.hiMax ? 2 : 1 ); } @@ -3236,7 +3236,7 @@ void View::DrawZones() { const auto px0 = ( m_statRange.min - m_vd.zvStart ) * pxns; const auto px1 = std::max( px0 + std::max( 1.0, pxns * 0.5 ), ( m_statRange.max - m_vd.zvStart ) * pxns ); - DrawStripedRect( draw, wpos.x + px0, linepos.y, wpos.x + px1, linepos.y + lineh, 10 * ImGui::GetTextLineHeight() / 15.f, 0x228888EE ); + DrawStripedRect( draw, wpos.x + px0, linepos.y, wpos.x + px1, linepos.y + lineh, 10 * ImGui::GetTextLineHeight() / 15.f, 0x228888EE, true, false ); draw->AddLine( ImVec2( wpos.x + px0, linepos.y ), ImVec2( wpos.x + px0, linepos.y + lineh ), m_statRange.hiMin ? 0x998888EE : 0x338888EE, m_statRange.hiMin ? 2 : 1 ); draw->AddLine( ImVec2( wpos.x + px1, linepos.y ), ImVec2( wpos.x + px1, linepos.y + lineh ), m_statRange.hiMax ? 0x998888EE : 0x338888EE, m_statRange.hiMax ? 2 : 1 ); } @@ -3245,7 +3245,7 @@ void View::DrawZones() { const auto s = std::min( m_setRangePopup.min, m_setRangePopup.max ); const auto e = std::max( m_setRangePopup.min, m_setRangePopup.max ); - DrawStripedRect( draw, wpos.x + ( s - m_vd.zvStart ) * pxns, linepos.y, wpos.x + ( e - m_vd.zvStart ) * pxns, linepos.y + lineh, 5 * ImGui::GetTextLineHeight() / 15.f, 0x55DD8888 ); + DrawStripedRect( draw, wpos.x + ( s - m_vd.zvStart ) * pxns, linepos.y, wpos.x + ( e - m_vd.zvStart ) * pxns, linepos.y + lineh, 5 * ImGui::GetTextLineHeight() / 15.f, 0x55DD8888, true, false ); draw->AddRect( ImVec2( wpos.x + ( s - m_vd.zvStart ) * pxns, linepos.y ), ImVec2( wpos.x + ( e - m_vd.zvStart ) * pxns, linepos.y + lineh ), 0x77DD8888 ); } From b826c14e4d28ad8739ddac93d9eb855dd6c14a4e Mon Sep 17 00:00:00 2001 From: Simon van Bernem Date: Fri, 7 Aug 2020 10:37:19 +0200 Subject: [PATCH 2/7] reverted an unnecessary change --- server/TracyImGui.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/TracyImGui.hpp b/server/TracyImGui.hpp index 21b236ac..7dabe64a 100644 --- a/server/TracyImGui.hpp +++ b/server/TracyImGui.hpp @@ -183,6 +183,7 @@ namespace tracy const auto rw = x1 - x0; const auto rh = y1 - y0; + const auto cnt = int((rh + rw + sw * 2) / (sw * 2)); auto v0 = ImVec2( x0, y0 - rw); if (fix_stripes_in_screen_space) @@ -199,7 +200,6 @@ namespace tracy v0.y = window_width - corrected_flipped_v0y - double(inverted * sw); } - const auto cnt = int( ( rh + rw + 2*sw*2 ) / ( sw*2 ) ); for( int i=0; iPathLineTo( v0 + ImVec2( 0, i*sw*2 ) ); From e14bb56db1fd337aec499a6d98c28720f60be488 Mon Sep 17 00:00:00 2001 From: Simon van Bernem Date: Fri, 7 Aug 2020 10:38:38 +0200 Subject: [PATCH 3/7] matching spacing to remove change from original --- server/TracyImGui.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/TracyImGui.hpp b/server/TracyImGui.hpp index 7dabe64a..bd62c1a9 100644 --- a/server/TracyImGui.hpp +++ b/server/TracyImGui.hpp @@ -183,7 +183,7 @@ namespace tracy const auto rw = x1 - x0; const auto rh = y1 - y0; - const auto cnt = int((rh + rw + sw * 2) / (sw * 2)); + const auto cnt = int( (rh + rw + sw * 2) / (sw * 2) ); auto v0 = ImVec2( x0, y0 - rw); if (fix_stripes_in_screen_space) From 903b7badc0dd3820bfa1c4c1f2d4f3e53e2d224d Mon Sep 17 00:00:00 2001 From: Simon van Bernem Date: Fri, 7 Aug 2020 10:39:22 +0200 Subject: [PATCH 4/7] next try --- server/TracyImGui.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/TracyImGui.hpp b/server/TracyImGui.hpp index bd62c1a9..8f795c08 100644 --- a/server/TracyImGui.hpp +++ b/server/TracyImGui.hpp @@ -183,7 +183,7 @@ namespace tracy const auto rw = x1 - x0; const auto rh = y1 - y0; - const auto cnt = int( (rh + rw + sw * 2) / (sw * 2) ); + const auto cnt = int( ( rh + rw + sw*2 ) / ( sw*2 ) ); auto v0 = ImVec2( x0, y0 - rw); if (fix_stripes_in_screen_space) From ab85fba7e09a977ce7772442052aac9483d8eb1b Mon Sep 17 00:00:00 2001 From: Simon van Bernem Date: Fri, 7 Aug 2020 10:42:36 +0200 Subject: [PATCH 5/7] Matching the braketing style --- server/TracyImGui.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/server/TracyImGui.hpp b/server/TracyImGui.hpp index 8f795c08..496ccda3 100644 --- a/server/TracyImGui.hpp +++ b/server/TracyImGui.hpp @@ -188,16 +188,16 @@ namespace tracy if (fix_stripes_in_screen_space) { - const auto window_width = double(ImGui::GetWindowHeight()); + const auto window_width = double( ImGui::GetWindowHeight() ); const auto flipped_v0y = window_width - v0.y; //we transform into a y-is-up coordinate space to achieve upper-left to lower-right stripes. If we didn't, we would calculate values for lower-left to upper-right const auto manhatten_distance = x0 + flipped_v0y; - const auto in_multiples_of_2_times_sw = int(manhatten_distance / (sw * 2)); + const auto in_multiples_of_2_times_sw = int( manhatten_distance / ( sw*2 ) ); - const auto floored_manhatten_distance = double(in_multiples_of_2_times_sw * sw * 2); //floor in terms of 2 * stripe width + const auto floored_manhatten_distance = double( in_multiples_of_2_times_sw*sw*2 ); //floor in terms of 2 * stripe width - const auto corrected_flipped_v0y = (floored_manhatten_distance - x0); //we transform back into y-is-down imgui space - v0.y = window_width - corrected_flipped_v0y - double(inverted * sw); + const auto corrected_flipped_v0y = ( floored_manhatten_distance - x0 ); //the corrected (floored) y respects the position of the stripes + v0.y = window_width - corrected_flipped_v0y - double( inverted*sw ); //transform back into y-is-down imgui space } for( int i=0; i Date: Fri, 7 Aug 2020 10:45:52 +0200 Subject: [PATCH 6/7] More matching code-style --- server/TracyImGui.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/TracyImGui.hpp b/server/TracyImGui.hpp index 496ccda3..9f675903 100644 --- a/server/TracyImGui.hpp +++ b/server/TracyImGui.hpp @@ -184,9 +184,9 @@ namespace tracy const auto rw = x1 - x0; const auto rh = y1 - y0; const auto cnt = int( ( rh + rw + sw*2 ) / ( sw*2 ) ); - auto v0 = ImVec2( x0, y0 - rw); + auto v0 = ImVec2( x0, y0 - rw ); - if (fix_stripes_in_screen_space) + if ( fix_stripes_in_screen_space ) { const auto window_width = double( ImGui::GetWindowHeight() ); const auto flipped_v0y = window_width - v0.y; //we transform into a y-is-up coordinate space to achieve upper-left to lower-right stripes. If we didn't, we would calculate values for lower-left to upper-right From d06617b2a553f2e77f92d7285d9ab6ada9167329 Mon Sep 17 00:00:00 2001 From: Simon van Bernem Date: Fri, 7 Aug 2020 10:55:00 +0200 Subject: [PATCH 7/7] Fixed variable name --- server/TracyImGui.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/TracyImGui.hpp b/server/TracyImGui.hpp index 9f675903..bbe6db92 100644 --- a/server/TracyImGui.hpp +++ b/server/TracyImGui.hpp @@ -188,8 +188,8 @@ namespace tracy if ( fix_stripes_in_screen_space ) { - const auto window_width = double( ImGui::GetWindowHeight() ); - const auto flipped_v0y = window_width - v0.y; //we transform into a y-is-up coordinate space to achieve upper-left to lower-right stripes. If we didn't, we would calculate values for lower-left to upper-right + const auto window_height = double( ImGui::GetWindowHeight() ); + const auto flipped_v0y = window_height - v0.y; //we transform into a y-is-up coordinate space to achieve upper-left to lower-right stripes. If we didn't, we would calculate values for lower-left to upper-right const auto manhatten_distance = x0 + flipped_v0y; const auto in_multiples_of_2_times_sw = int( manhatten_distance / ( sw*2 ) ); @@ -197,7 +197,7 @@ namespace tracy const auto floored_manhatten_distance = double( in_multiples_of_2_times_sw*sw*2 ); //floor in terms of 2 * stripe width const auto corrected_flipped_v0y = ( floored_manhatten_distance - x0 ); //the corrected (floored) y respects the position of the stripes - v0.y = window_width - corrected_flipped_v0y - double( inverted*sw ); //transform back into y-is-down imgui space + v0.y = window_height - corrected_flipped_v0y - double( inverted*sw ); //transform back into y-is-down imgui space } for( int i=0; i