@ -4493,52 +4493,6 @@ bool ImGui::ColorPicker3(const char* label, float col[3], ImGuiColorEditFlags fl
return true ;
}
static inline ImU32 ImAlphaBlendColor ( ImU32 col_a , ImU32 col_b )
{
float t = ( ( col_b > > IM_COL32_A_SHIFT ) & 0xFF ) / 255.f ;
int r = ImLerp ( ( int ) ( col_a > > IM_COL32_R_SHIFT ) & 0xFF , ( int ) ( col_b > > IM_COL32_R_SHIFT ) & 0xFF , t ) ;
int g = ImLerp ( ( int ) ( col_a > > IM_COL32_G_SHIFT ) & 0xFF , ( int ) ( col_b > > IM_COL32_G_SHIFT ) & 0xFF , t ) ;
int b = ImLerp ( ( int ) ( col_a > > IM_COL32_B_SHIFT ) & 0xFF , ( int ) ( col_b > > IM_COL32_B_SHIFT ) & 0xFF , t ) ;
return IM_COL32 ( r , g , b , 0xFF ) ;
}
// Helper for ColorPicker4()
// NB: This is rather brittle and will show artifact when rounding this enabled if rounded corners overlap multiple cells. Caller currently responsible for avoiding that.
// I spent a non reasonable amount of time trying to getting this right for ColorButton with rounding+anti-aliasing+ImGuiColorEditFlags_HalfAlphaPreview flag + various grid sizes and offsets, and eventually gave up... probably more reasonable to disable rounding alltogether.
void ImGui : : RenderColorRectWithAlphaCheckerboard ( ImVec2 p_min , ImVec2 p_max , ImU32 col , float grid_step , ImVec2 grid_off , float rounding , int rounding_corners_flags )
{
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( ( ( col & IM_COL32_A_MASK ) > > IM_COL32_A_SHIFT ) < 0xFF )
{
ImU32 col_bg1 = GetColorU32 ( ImAlphaBlendColor ( IM_COL32 ( 204 , 204 , 204 , 255 ) , col ) ) ;
ImU32 col_bg2 = GetColorU32 ( ImAlphaBlendColor ( IM_COL32 ( 128 , 128 , 128 , 255 ) , col ) ) ;
window - > DrawList - > AddRectFilled ( p_min , p_max , col_bg1 , rounding , rounding_corners_flags ) ;
int yi = 0 ;
for ( float y = p_min . y + grid_off . y ; y < p_max . y ; y + = grid_step , yi + + )
{
float y1 = ImClamp ( y , p_min . y , p_max . y ) , y2 = ImMin ( y + grid_step , p_max . y ) ;
if ( y2 < = y1 )
continue ;
for ( float x = p_min . x + grid_off . x + ( yi & 1 ) * grid_step ; x < p_max . x ; x + = grid_step * 2.0f )
{
float x1 = ImClamp ( x , p_min . x , p_max . x ) , x2 = ImMin ( x + grid_step , p_max . x ) ;
if ( x2 < = x1 )
continue ;
int rounding_corners_flags_cell = 0 ;
if ( y1 < = p_min . y ) { if ( x1 < = p_min . x ) rounding_corners_flags_cell | = ImDrawCornerFlags_TopLeft ; if ( x2 > = p_max . x ) rounding_corners_flags_cell | = ImDrawCornerFlags_TopRight ; }
if ( y2 > = p_max . y ) { if ( x1 < = p_min . x ) rounding_corners_flags_cell | = ImDrawCornerFlags_BotLeft ; if ( x2 > = p_max . x ) rounding_corners_flags_cell | = ImDrawCornerFlags_BotRight ; }
rounding_corners_flags_cell & = rounding_corners_flags ;
window - > DrawList - > AddRectFilled ( ImVec2 ( x1 , y1 ) , ImVec2 ( x2 , y2 ) , col_bg2 , rounding_corners_flags_cell ? rounding : 0.0f , rounding_corners_flags_cell ) ;
}
}
}
else
{
window - > DrawList - > AddRectFilled ( p_min , p_max , col , rounding , rounding_corners_flags ) ;
}
}
// Helper for ColorPicker4()
static void RenderArrowsForVerticalBar ( ImDrawList * draw_list , ImVec2 pos , ImVec2 half_sz , float bar_w , float alpha )
{
@ -4909,7 +4863,7 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl
{
float alpha = ImSaturate ( col [ 3 ] ) ;
ImRect bar1_bb ( bar1_pos_x , picker_pos . y , bar1_pos_x + bars_width , picker_pos . y + sv_picker_size ) ;
RenderColorRectWithAlphaCheckerboard ( bar1_bb. Min , bar1_bb . Max , 0 , bar1_bb . GetWidth ( ) / 2.0f , ImVec2 ( 0.0f , 0.0f ) ) ;
RenderColorRectWithAlphaCheckerboard ( draw_list, bar1_bb. Min , bar1_bb . Max , 0 , bar1_bb . GetWidth ( ) / 2.0f , ImVec2 ( 0.0f , 0.0f ) ) ;
draw_list - > AddRectFilledMultiColor ( bar1_bb . Min , bar1_bb . Max , user_col32_striped_of_alpha , user_col32_striped_of_alpha , user_col32_striped_of_alpha & ~ IM_COL32_A_MASK , user_col32_striped_of_alpha & ~ IM_COL32_A_MASK ) ;
float bar1_line_y = IM_ROUND ( picker_pos . y + ( 1.0f - alpha ) * sv_picker_size ) ;
RenderFrameBorder ( bar1_bb . Min , bar1_bb . Max , 0.0f ) ;
@ -4973,7 +4927,7 @@ bool ImGui::ColorButton(const char* desc_id, const ImVec4& col, ImGuiColorEditFl
if ( ( flags & ImGuiColorEditFlags_AlphaPreviewHalf ) & & col_rgb . w < 1.0f )
{
float mid_x = IM_ROUND ( ( bb_inner . Min . x + bb_inner . Max . x ) * 0.5f ) ;
RenderColorRectWithAlphaCheckerboard ( ImVec2( bb_inner . Min . x + grid_step , bb_inner . Min . y ) , bb_inner . Max , GetColorU32 ( col_rgb ) , grid_step , ImVec2 ( - grid_step + off , off ) , rounding , ImDrawCornerFlags_TopRight | ImDrawCornerFlags_BotRight ) ;
RenderColorRectWithAlphaCheckerboard ( window- > DrawList , ImVec2( bb_inner . Min . x + grid_step , bb_inner . Min . y ) , bb_inner . Max , GetColorU32 ( col_rgb ) , grid_step , ImVec2 ( - grid_step + off , off ) , rounding , ImDrawCornerFlags_TopRight | ImDrawCornerFlags_BotRight ) ;
window - > DrawList - > AddRectFilled ( bb_inner . Min , ImVec2 ( mid_x , bb_inner . Max . y ) , GetColorU32 ( col_rgb_without_alpha ) , rounding , ImDrawCornerFlags_TopLeft | ImDrawCornerFlags_BotLeft ) ;
}
else
@ -4981,7 +4935,7 @@ bool ImGui::ColorButton(const char* desc_id, const ImVec4& col, ImGuiColorEditFl
// Because GetColorU32() multiplies by the global style Alpha and we don't want to display a checkerboard if the source code had no alpha
ImVec4 col_source = ( flags & ImGuiColorEditFlags_AlphaPreview ) ? col_rgb : col_rgb_without_alpha ;
if ( col_source . w < 1.0f )
RenderColorRectWithAlphaCheckerboard ( bb_inner. Min , bb_inner . Max , GetColorU32 ( col_source ) , grid_step , ImVec2 ( off , off ) , rounding ) ;
RenderColorRectWithAlphaCheckerboard ( window- > DrawList , bb_inner. Min , bb_inner . Max , GetColorU32 ( col_source ) , grid_step , ImVec2 ( off , off ) , rounding ) ;
else
window - > DrawList - > AddRectFilled ( bb_inner . Min , bb_inner . Max , GetColorU32 ( col_source ) , rounding , ImDrawCornerFlags_All ) ;
}