From eb5e4b2c0fb0c8301cbdbcf018f4107ac342617f Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Fri, 30 Aug 2019 20:07:57 +0200 Subject: [PATCH] Test of shaded histogram graph. --- server/TracyImGui.hpp | 24 ++++++++++++++++++++++++ server/TracyView.cpp | 3 ++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/server/TracyImGui.hpp b/server/TracyImGui.hpp index e805867e..fb632d2c 100644 --- a/server/TracyImGui.hpp +++ b/server/TracyImGui.hpp @@ -5,6 +5,9 @@ # pragma warning( disable: 4244 ) // conversion from don't care to whatever, possible loss of data #endif +#include +#include + #include "../imgui/imgui.h" #include "../imgui/imgui_internal.h" @@ -65,6 +68,27 @@ namespace tracy return ret; } + static inline void LineVertical( struct ImDrawList* draw, float x, float y0, float y1, uint32_t c0, uint32_t c1 ) + { + draw->AddRectFilledMultiColor( ImVec2( x, y0 ), ImVec2( x+1, y1 ), c0, c0, c1, c1 ); + } + + static inline uint8_t lerp( uint8_t v0, uint8_t v1, float t ) + { + return uint8_t( v0 + t * ( v1 - v0 ) ); + } + + static inline void LineVerticalShaded( struct ImDrawList* draw, float x, float y0, float y1, uint32_t c0, uint32_t c1, float maxHeight ) + { + const auto dy = y1 - y0; + const auto t = std::min( 1.f, dy / maxHeight ); + const auto ct = 0xFF000000 | + ( lerp( ( c0 & 0x00FF0000 ) >> 16, ( c1 & 0x00FF0000 ) >> 16, t ) << 16 ) | + ( lerp( ( c0 & 0x0000FF00 ) >> 8, ( c1 & 0x0000FF00 ) >> 8, t ) << 8 ) | + ( lerp( ( c0 & 0x000000FF ) , ( c1 & 0x000000FF ) , t ) ); + LineVertical( draw, x, y0, y1, c0, ct ); + } + } #endif diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 5f1d51f4..f5e895de 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -7586,7 +7586,8 @@ void View::DrawFindZone() const auto val = cumulateTime ? binTime[i] : bins[i]; if( val > 0 ) { - draw->AddLine( wpos + ImVec2( 2+i, Height-3 ), wpos + ImVec2( 2+i, Height-3 - val * hAdj ), 0xFF22DDDD ); + LineVerticalShaded( draw, wpos.x + 2+i, wpos.y + Height-2 - val * hAdj, wpos.y + Height-1, 0xFF22DDDD, 0xFF118888, hAdj ); + //draw->AddLine( wpos + ImVec2( 2+i, Height-3 ), wpos + ImVec2( 2+i, Height-3 - val * hAdj ), 0xFF22DDDD ); if( selBin[i] > 0 ) { draw->AddLine( wpos + ImVec2( 2+i, Height-3 ), wpos + ImVec2( 2+i, Height-3 - selBin[i] * hAdj ), 0xFFDD7777 );