mirror of
https://github.com/wolfpld/tracy.git
synced 2025-03-20 07:40:02 +08:00
Draw zigzags using bitmaps.
This commit is contained in:
+5
-47
@@ -1,15 +1,11 @@
|
||||
#include <assert.h>
|
||||
#include <algorithm>
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <malloc.h>
|
||||
#else
|
||||
# include <alloca.h>
|
||||
#endif
|
||||
|
||||
#include "TracyPrint.hpp"
|
||||
#include "TracyImGui.hpp"
|
||||
|
||||
extern void* zigzagTex;
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
@@ -26,48 +22,10 @@ bool WasActive()
|
||||
}
|
||||
|
||||
|
||||
void DrawZigZag( ImDrawList* draw, const ImVec2& wpos, double start, double end, double h, uint32_t color, float thickness )
|
||||
void DrawZigZag( ImDrawList* draw, const ImVec2& wpos, double start, double end, double h, uint32_t color )
|
||||
{
|
||||
const auto dpos = wpos + ImVec2( 0.5f, 0.5f );
|
||||
|
||||
const auto spanSz = end - start;
|
||||
if( spanSz <= h * 0.5 )
|
||||
{
|
||||
DrawLine( draw, dpos + ImVec2( start, 0 ), wpos + ImVec2( start + spanSz, round( -spanSz ) ), color, thickness );
|
||||
return;
|
||||
}
|
||||
|
||||
const auto h05 = round( h * 0.5 );
|
||||
const auto h2 = h*2;
|
||||
int steps = int( ( end - start ) / h2 );
|
||||
|
||||
auto path = (ImVec2*)alloca( sizeof( ImVec2 ) * ( 2 * steps + 4 ) );
|
||||
auto ptr = path;
|
||||
|
||||
*ptr++ = dpos + ImVec2( start, 0 );
|
||||
*ptr++ = dpos + ImVec2( start + h05, -h05 );
|
||||
start += h05;
|
||||
|
||||
while( steps-- )
|
||||
{
|
||||
*ptr++ = dpos + ImVec2( start + h, h05 );
|
||||
*ptr++ = dpos + ImVec2( start + h2, -h05 );
|
||||
start += h2;
|
||||
}
|
||||
|
||||
if( end - start <= h )
|
||||
{
|
||||
const auto span = end - start;
|
||||
*ptr++ = dpos + ImVec2( start + span, round( span - h*0.5 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto span = end - start - h;
|
||||
*ptr++ = dpos + ImVec2( start + h, h05 );
|
||||
*ptr++ = dpos + ImVec2( start + h + span, round( h*0.5 - span ) );
|
||||
}
|
||||
|
||||
draw->AddPolyline( path, ptr - path, color, 0, thickness );
|
||||
const auto v = ( end - start ) / ( h * 2 );
|
||||
draw->AddImage( zigzagTex, wpos + ImVec2( start, -h ), wpos + ImVec2( end, h ), ImVec2( 0, 0 ), ImVec2( v, 1 ), color );
|
||||
}
|
||||
|
||||
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 )
|
||||
|
||||
Reference in New Issue
Block a user