1
0
mirror of https://github.com/wolfpld/tracy synced 2025-04-29 04:23:51 +00:00

Make plot color/value formatting generic utilities.

Previous implementations of these functions (in TracyView) are still used
throughout the code. They will be removed in subsequent commits.
This commit is contained in:
Bartosz Taudul 2022-09-03 16:49:25 +02:00
parent 1736fb387a
commit 55a82ea714
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
2 changed files with 47 additions and 0 deletions

View File

@ -1,6 +1,9 @@
#include <assert.h>
#include "TracyColor.hpp"
#include "TracyPrint.hpp"
#include "TracyUtility.hpp"
#include "TracyWorker.hpp"
namespace tracy
{
@ -137,4 +140,42 @@ void TooltipNormalizedName( const char* name, const char* normalized )
}
}
uint32_t GetPlotColor( const PlotData& plot, const Worker& worker )
{
switch( plot.type )
{
case PlotType::User:
if( plot.color != 0 ) return plot.color | 0xFF000000;
return GetHsvColor( charutil::hash( worker.GetString( plot.name ) ), -10 );
case PlotType::Memory:
return 0xFF2266CC;
case PlotType::SysTime:
return 0xFFBAB220;
default:
assert( false );
return 0;
}
}
const char* FormatPlotValue( double val, PlotValueFormatting format )
{
static char buf[64];
switch( format )
{
case PlotValueFormatting::Number:
return RealToString( val );
break;
case PlotValueFormatting::Memory:
return MemSizeToString( val );
break;
case PlotValueFormatting::Percentage:
sprintf( buf, "%.2f%%", val );
break;
default:
assert( false );
break;
}
return buf;
}
}

View File

@ -4,10 +4,13 @@
#include <stdint.h>
#include "imgui.h"
#include "TracyEvent.hpp"
namespace tracy
{
class Worker;
enum class ShortenName : uint8_t
{
Never,
@ -22,6 +25,9 @@ void TooltipNormalizedName( const char* name, const char* normalized );
static inline const char* ShortenZoneName( ShortenName type, const char* name ) { ImVec2 tsz = {}; return ShortenZoneName( type, name, tsz, 0 ); }
uint32_t GetPlotColor( const PlotData& plot, const Worker& worker );
const char* FormatPlotValue( double val, PlotValueFormatting format );
}
#endif