mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-30 09:14:36 +00:00
Optimize drawing zig-zags.
This commit is contained in:
parent
ad3aa73085
commit
eff040dca6
@ -1797,29 +1797,37 @@ static uint32_t DarkenColor( uint32_t color )
|
|||||||
|
|
||||||
static void DrawZigZag( ImDrawList* draw, const ImVec2& wpos, double start, double end, double h, uint32_t color, float thickness = 1.f )
|
static void DrawZigZag( ImDrawList* draw, const ImVec2& wpos, double start, double end, double h, uint32_t color, float thickness = 1.f )
|
||||||
{
|
{
|
||||||
int mode = 0;
|
const auto spanSz = end - start;
|
||||||
while( start < end )
|
const auto h05 = round( h * 0.5 );
|
||||||
|
|
||||||
|
if( spanSz <= h05 )
|
||||||
{
|
{
|
||||||
double step = std::min( end - start, mode == 0 ? h/2 : h );
|
draw->AddLine( wpos + ImVec2( start, 0 ), wpos + ImVec2( start + spanSz, round( -spanSz ) ), color, thickness );
|
||||||
switch( mode )
|
return;
|
||||||
{
|
}
|
||||||
case 0:
|
|
||||||
draw->AddLine( wpos + ImVec2( start, 0 ), wpos + ImVec2( start + step, round( -step ) ), color, thickness );
|
draw->AddLine( wpos + ImVec2( start, 0 ), wpos + ImVec2( start + h05, -h05 ), color, thickness );
|
||||||
mode = 1;
|
start += h05;
|
||||||
break;
|
|
||||||
case 1:
|
const auto h2 = h*2;
|
||||||
draw->AddLine( wpos + ImVec2( start, round( -h/2 ) ), wpos + ImVec2( start + step, round( step - h/2 ) ), color, thickness );
|
int steps = int( ( end - start ) / h2 );
|
||||||
mode = 2;
|
while( steps-- )
|
||||||
break;
|
{
|
||||||
case 2:
|
draw->AddLine( wpos + ImVec2( start, -h05 ), wpos + ImVec2( start + h, h05 ), color, thickness );
|
||||||
draw->AddLine( wpos + ImVec2( start, round( h/2 ) ), wpos + ImVec2( start + step, round( h/2 - step ) ), color, thickness );
|
draw->AddLine( wpos + ImVec2( start + h, h05 ), wpos + ImVec2( start + h2, -h05 ), color, thickness );
|
||||||
mode = 1;
|
start += h2;
|
||||||
break;
|
}
|
||||||
default:
|
|
||||||
assert( false );
|
if( end - start <= h )
|
||||||
break;
|
{
|
||||||
};
|
const auto span = end - start;
|
||||||
start += step;
|
draw->AddLine( wpos + ImVec2( start, -h05 ), wpos + ImVec2( start + span, round( span - h*0.5 ) ), color, thickness );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
draw->AddLine( wpos + ImVec2( start, -h05 ), wpos + ImVec2( start + h, h05 ), color, thickness );
|
||||||
|
const auto span = end - start - h;
|
||||||
|
draw->AddLine( wpos + ImVec2( start + h, h05 ), wpos + ImVec2( start + h + span, round( h*0.5 - span ) ), color, thickness );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user