From 87d639c8511764aeba164f23bb426859ca17db9d Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sat, 2 Jul 2022 15:08:52 +0200 Subject: [PATCH] Move DrawStripedRect() out of header. --- server/TracyImGui.cpp | 51 +++++++++++++++++++++++++++++++++++++++++ server/TracyImGui.hpp | 53 ++----------------------------------------- 2 files changed, 53 insertions(+), 51 deletions(-) diff --git a/server/TracyImGui.cpp b/server/TracyImGui.cpp index 03a22d84..df767bb0 100644 --- a/server/TracyImGui.cpp +++ b/server/TracyImGui.cpp @@ -47,4 +47,55 @@ void DrawZigZag( ImDrawList* draw, const ImVec2& wpos, double start, double end, draw->AddPolyline( path, ptr - path, color, 0, thickness ); } +void DrawStripedRect( ImDrawList* draw, const ImVec2& wpos, 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 ); + assert( sw > 0 ); + + const auto ww = ImGui::GetItemRectSize().x; + if( x0 > ww || x1 < 0 ) return; + + if( x1 - x0 > ww ) + { + x0 = std::max( 0, x0 ); + x1 = std::min( ww, x1 ); + } + + x0 += wpos.x; + x1 += wpos.x; + + ImGui::PushClipRect( ImVec2( x0, y0 ), ImVec2( x1, y1 ), true ); + + 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 ) + { + 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 manhattan_distance = x0 + flipped_v0y; + const auto in_multiples_of_2_times_sw = int( manhattan_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 ); //the corrected (floored) y respects the position of the stripes + v0.y = window_height - corrected_flipped_v0y - double( inverted*sw ); //transform back into y-is-down imgui space + } + + for( int i=0; iPathLineTo( v0 + ImVec2( 0, i*sw*2 ) ); + draw->PathLineTo( v0 + ImVec2( rw, i*sw*2 + rw ) ); + draw->PathLineTo( v0 + ImVec2( rw, i*sw*2 + rw + sw ) ); + draw->PathLineTo( v0 + ImVec2( 0, i*sw*2 + sw ) ); + draw->PathFillConvex( color ); + } + + ImGui::PopClipRect(); +} + } diff --git a/server/TracyImGui.hpp b/server/TracyImGui.hpp index 565497b4..040d5015 100644 --- a/server/TracyImGui.hpp +++ b/server/TracyImGui.hpp @@ -24,6 +24,8 @@ namespace tracy { void DrawZigZag( ImDrawList* draw, const ImVec2& wpos, double start, double end, double h, uint32_t color, float thickness = 1.f ); +void DrawStripedRect( ImDrawList* draw, const ImVec2& wpos, double x0, double y0, double x1, double y1, double sw, uint32_t color, bool fix_stripes_in_screen_space, bool inverted ); + static const ImVec4 SyntaxColors[] = { { 0.7f, 0.7f, 0.7f, 1 }, // default @@ -196,57 +198,6 @@ static const ImVec4 SyntaxColorsDimmed[] = { return res; } -[[maybe_unused]] static void DrawStripedRect( ImDrawList* draw, const ImVec2& wpos, 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 ); - assert( sw > 0 ); - - const auto ww = ImGui::GetItemRectSize().x; - if( x0 > ww || x1 < 0 ) return; - - if( x1 - x0 > ww ) - { - x0 = std::max( 0, x0 ); - x1 = std::min( ww, x1 ); - } - - x0 += wpos.x; - x1 += wpos.x; - - ImGui::PushClipRect( ImVec2( x0, y0 ), ImVec2( x1, y1 ), true ); - - 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 ) - { - 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 manhattan_distance = x0 + flipped_v0y; - const auto in_multiples_of_2_times_sw = int( manhattan_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 ); //the corrected (floored) y respects the position of the stripes - v0.y = window_height - corrected_flipped_v0y - double( inverted*sw ); //transform back into y-is-down imgui space - } - - for( int i=0; iPathLineTo( v0 + ImVec2( 0, i*sw*2 ) ); - draw->PathLineTo( v0 + ImVec2( rw, i*sw*2 + rw ) ); - draw->PathLineTo( v0 + ImVec2( rw, i*sw*2 + rw + sw ) ); - draw->PathLineTo( v0 + ImVec2( 0, i*sw*2 + sw ) ); - draw->PathFillConvex( color ); - } - - ImGui::PopClipRect(); -} - [[maybe_unused]] static tracy_force_inline void DrawLine( ImDrawList* draw, const ImVec2& v1, const ImVec2& v2, uint32_t col, float thickness = 1.0f ) { const ImVec2 data[2] = { v1, v2 };