Less code duplication.

This commit is contained in:
Bartosz Taudul 2020-04-10 23:07:52 +02:00
parent 61828070c5
commit 126a587aa3

View File

@ -687,20 +687,22 @@ void SourceView::RenderSymbolSourceView( uint32_t iptotal, unordered_flat_map<ui
}
const auto ly = round( rect.Min.y + float( firstLine ) / m_lines.size() * rect.GetHeight() );
const auto ipPercent = float( ipSum ) / maxIpCount;
uint32_t color;
if( ipPercent <= 0.5f )
{
const auto a = int( ( ipPercent * 1.5f + 0.25f ) * 255 );
draw->AddRectFilled( ImVec2( x14, ly ), ImVec2( x34, ly+3 ), 0x000000FF | ( a << 24 ) );
color = 0x000000FF | ( a << 24 );
}
else if( ipPercent <= 1.f )
{
const auto g = int( ( ipPercent - 0.5f ) * 511 );
draw->AddRectFilled( ImVec2( x14, ly ), ImVec2( x34, ly+3 ), 0xFF0000FF | ( g << 8 ) );
color = 0xFF0000FF | ( g << 8 );
}
else
{
draw->AddRectFilled( ImVec2( x14, ly ), ImVec2( x34, ly+3 ), 0xFF00FFFF );
color = 0xFF00FFFF;
}
draw->AddRectFilled( ImVec2( x14, ly ), ImVec2( x34, ly+3 ), color );
}
ImGui::PopClipRect();
@ -938,20 +940,22 @@ uint64_t SourceView::RenderSymbolAsmView( uint32_t iptotal, unordered_flat_map<u
}
const auto ly = round( rect.Min.y + float( firstLine ) / m_asm.size() * rect.GetHeight() );
const auto ipPercent = float( ipSum ) / maxIpCount;
uint32_t color;
if( ipPercent <= 0.5f )
{
const auto a = int( ( ipPercent * 1.5f + 0.25f ) * 255 );
draw->AddRectFilled( ImVec2( x14, ly ), ImVec2( x34, ly+3 ), 0x000000FF | ( a << 24 ) );
color = 0x000000FF | ( a << 24 );
}
else if( ipPercent <= 1.f )
{
const auto g = int( ( ipPercent - 0.5f ) * 511 );
draw->AddRectFilled( ImVec2( x14, ly ), ImVec2( x34, ly+3 ), 0xFF0000FF | ( g << 8 ) );
color = 0xFF0000FF | ( g << 8 );
}
else
{
draw->AddRectFilled( ImVec2( x14, ly ), ImVec2( x34, ly+3 ), 0xFF00FFFF );
color = 0xFF00FFFF;
}
draw->AddRectFilled( ImVec2( x14, ly ), ImVec2( x34, ly+3 ), color );
}
}