Draw zigzags using bitmaps.

This commit is contained in:
Bartosz Taudul 2023-04-27 23:16:45 +02:00
parent 62ec968f24
commit 474dc6945e
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
4 changed files with 8 additions and 50 deletions

View File

@ -98,7 +98,7 @@ static void* iconTex;
static int iconTexSz; static int iconTexSz;
static uint8_t* zigzagPx; static uint8_t* zigzagPx;
static int zigzagX, zigzagY; static int zigzagX, zigzagY;
static void* zigzagTex; void* zigzagTex;
static Backend* bptr; static Backend* bptr;
static bool s_customTitle = false; static bool s_customTitle = false;
static bool s_isElevated = false; static bool s_isElevated = false;

View File

@ -1,15 +1,11 @@
#include <assert.h> #include <assert.h>
#include <algorithm> #include <algorithm>
#ifdef _WIN32
# include <malloc.h>
#else
# include <alloca.h>
#endif
#include "TracyPrint.hpp" #include "TracyPrint.hpp"
#include "TracyImGui.hpp" #include "TracyImGui.hpp"
extern void* zigzagTex;
namespace tracy 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 v = ( end - start ) / ( h * 2 );
draw->AddImage( zigzagTex, wpos + ImVec2( start, -h ), wpos + ImVec2( end, h ), ImVec2( 0, 0 ), ImVec2( v, 1 ), color );
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 );
} }
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 ) 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 )

View File

@ -26,7 +26,7 @@ extern bool s_wasActive;
bool WasActive(); bool WasActive();
void DrawZigZag( ImDrawList* draw, const ImVec2& wpos, double start, double end, double h, uint32_t color, float thickness = 1.f ); void DrawZigZag( ImDrawList* draw, const ImVec2& wpos, double start, double end, double h, uint32_t 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 ); 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 );
void DrawHistogramMinMaxLabel( ImDrawList* draw, int64_t tmin, int64_t tmax, ImVec2 wpos, float w, float ty ); void DrawHistogramMinMaxLabel( ImDrawList* draw, int64_t tmin, int64_t tmax, ImVec2 wpos, float w, float ty );

View File

@ -294,7 +294,7 @@ void View::DrawContextSwitchList( const TimelineContext& ctx, const std::vector<
} }
else else
{ {
DrawZigZag( draw, wpos + ImVec2( 0, offset + ty05 ), px0, minpx, ty/4, 0xFF888888, 1.5 ); DrawZigZag( draw, wpos + ImVec2( 0, offset + ty05 ), px0, minpx, ty/4, 0xFF888888 );
if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( px0, offset ), wpos + ImVec2( minpx, offset + ty + 1 ) ) ) if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( px0, offset ), wpos + ImVec2( minpx, offset + ty + 1 ) ) )
{ {
ImGui::BeginTooltip(); ImGui::BeginTooltip();