@@ -4402,17 +4402,19 @@ void ImGui::RenderColorRectWithAlphaCheckerboard(ImVec2 p_min, ImVec2 p_max, ImU
4402
4402
}
4403
4403
4404
4404
// Helper for ColorPicker4()
4405
- static void RenderArrowsForVerticalBar (ImDrawList* draw_list, ImVec2 pos, ImVec2 half_sz, float bar_w)
4405
+ static void RenderArrowsForVerticalBar (ImDrawList* draw_list, ImVec2 pos, ImVec2 half_sz, float bar_w, float alpha )
4406
4406
{
4407
- ImGui::RenderArrowPointingAt (draw_list, ImVec2 (pos.x + half_sz.x + 1 , pos.y ), ImVec2 (half_sz.x + 2 , half_sz.y + 1 ), ImGuiDir_Right, IM_COL32_BLACK);
4408
- ImGui::RenderArrowPointingAt (draw_list, ImVec2 (pos.x + half_sz.x , pos.y ), half_sz, ImGuiDir_Right, IM_COL32_WHITE);
4409
- ImGui::RenderArrowPointingAt (draw_list, ImVec2 (pos.x + bar_w - half_sz.x - 1 , pos.y ), ImVec2 (half_sz.x + 2 , half_sz.y + 1 ), ImGuiDir_Left, IM_COL32_BLACK);
4410
- ImGui::RenderArrowPointingAt (draw_list, ImVec2 (pos.x + bar_w - half_sz.x , pos.y ), half_sz, ImGuiDir_Left, IM_COL32_WHITE);
4407
+ ImU32 alpha8 = IM_F32_TO_INT8_SAT (alpha);
4408
+ ImGui::RenderArrowPointingAt (draw_list, ImVec2 (pos.x + half_sz.x + 1 , pos.y ), ImVec2 (half_sz.x + 2 , half_sz.y + 1 ), ImGuiDir_Right, IM_COL32 (0 ,0 ,0 ,alpha8));
4409
+ ImGui::RenderArrowPointingAt (draw_list, ImVec2 (pos.x + half_sz.x , pos.y ), half_sz, ImGuiDir_Right, IM_COL32 (255 ,255 ,255 ,alpha8));
4410
+ ImGui::RenderArrowPointingAt (draw_list, ImVec2 (pos.x + bar_w - half_sz.x - 1 , pos.y ), ImVec2 (half_sz.x + 2 , half_sz.y + 1 ), ImGuiDir_Left, IM_COL32 (0 ,0 ,0 ,alpha8));
4411
+ ImGui::RenderArrowPointingAt (draw_list, ImVec2 (pos.x + bar_w - half_sz.x , pos.y ), half_sz, ImGuiDir_Left, IM_COL32 (255 ,255 ,255 ,alpha8));
4411
4412
}
4412
4413
4413
4414
// Note: ColorPicker4() only accesses 3 floats if ImGuiColorEditFlags_NoAlpha flag is set.
4414
4415
// (In C++ the 'float col[4]' notation for a function argument is equivalent to 'float* col', we only specify a size to facilitate understanding of the code.)
4415
4416
// FIXME: we adjust the big color square height based on item width, which may cause a flickering feedback loop (if automatic height makes a vertical scrollbar appears, affecting automatic width..)
4417
+ // FIXME: this is trying to be aware of style.Alpha but not fully correct. Also, the color wheel will have overlapping glitches with (style.Alpha < 1.0)
4416
4418
bool ImGui::ColorPicker4 (const char * label, float col[4 ], ImGuiColorEditFlags flags, const float * ref_col)
4417
4419
{
4418
4420
ImGuiContext& g = *GImGui;
@@ -4662,31 +4664,36 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl
4662
4664
}
4663
4665
}
4664
4666
4665
- ImVec4 hue_color_f (1 , 1 , 1 , 1 ); ColorConvertHSVtoRGB (H, 1 , 1 , hue_color_f.x , hue_color_f.y , hue_color_f.z );
4667
+ const int style_alpha8 = IM_F32_TO_INT8_SAT (style.Alpha );
4668
+ const ImU32 col_black = IM_COL32 (0 ,0 ,0 ,style_alpha8);
4669
+ const ImU32 col_white = IM_COL32 (255 ,255 ,255 ,style_alpha8);
4670
+ const ImU32 col_midgrey = IM_COL32 (128 ,128 ,128 ,style_alpha8);
4671
+ const ImU32 col_hues[6 + 1 ] = { IM_COL32 (255 ,0 ,0 ,style_alpha8), IM_COL32 (255 ,255 ,0 ,style_alpha8), IM_COL32 (0 ,255 ,0 ,style_alpha8), IM_COL32 (0 ,255 ,255 ,style_alpha8), IM_COL32 (0 ,0 ,255 ,style_alpha8), IM_COL32 (255 ,0 ,255 ,style_alpha8), IM_COL32 (255 ,0 ,0 ,style_alpha8) };
4672
+
4673
+ ImVec4 hue_color_f (1 , 1 , 1 , style.Alpha ); ColorConvertHSVtoRGB (H, 1 , 1 , hue_color_f.x , hue_color_f.y , hue_color_f.z );
4666
4674
ImU32 hue_color32 = ColorConvertFloat4ToU32 (hue_color_f);
4667
- ImU32 col32_no_alpha = ColorConvertFloat4ToU32 (ImVec4 (R, G, B, 1 . 0f ));
4675
+ ImU32 user_col32_striped_of_alpha = ColorConvertFloat4ToU32 (ImVec4 (R, G, B, style. Alpha )); // Important: this is still including the main rendering/style alpha!!
4668
4676
4669
- const ImU32 hue_colors[6 +1 ] = { IM_COL32 (255 ,0 ,0 ,255 ), IM_COL32 (255 ,255 ,0 ,255 ), IM_COL32 (0 ,255 ,0 ,255 ), IM_COL32 (0 ,255 ,255 ,255 ), IM_COL32 (0 ,0 ,255 ,255 ), IM_COL32 (255 ,0 ,255 ,255 ), IM_COL32 (255 ,0 ,0 ,255 ) };
4670
4677
ImVec2 sv_cursor_pos;
4671
4678
4672
4679
if (flags & ImGuiColorEditFlags_PickerHueWheel)
4673
4680
{
4674
4681
// Render Hue Wheel
4675
- const float aeps = 1 .5f / wheel_r_outer; // Half a pixel arc length in radians (2pi cancels out).
4682
+ const float aeps = 0 .5f / wheel_r_outer; // Half a pixel arc length in radians (2pi cancels out).
4676
4683
const int segment_per_arc = ImMax (4 , (int )wheel_r_outer / 12 );
4677
4684
for (int n = 0 ; n < 6 ; n++)
4678
4685
{
4679
4686
const float a0 = (n) /6 .0f * 2 .0f * IM_PI - aeps;
4680
4687
const float a1 = (n+1 .0f )/6 .0f * 2 .0f * IM_PI + aeps;
4681
4688
const int vert_start_idx = draw_list->VtxBuffer .Size ;
4682
4689
draw_list->PathArcTo (wheel_center, (wheel_r_inner + wheel_r_outer)*0 .5f , a0, a1, segment_per_arc);
4683
- draw_list->PathStroke (IM_COL32_WHITE , false , wheel_thickness);
4690
+ draw_list->PathStroke (col_white , false , wheel_thickness);
4684
4691
const int vert_end_idx = draw_list->VtxBuffer .Size ;
4685
4692
4686
4693
// Paint colors over existing vertices
4687
4694
ImVec2 gradient_p0 (wheel_center.x + ImCos (a0) * wheel_r_inner, wheel_center.y + ImSin (a0) * wheel_r_inner);
4688
4695
ImVec2 gradient_p1 (wheel_center.x + ImCos (a1) * wheel_r_inner, wheel_center.y + ImSin (a1) * wheel_r_inner);
4689
- ShadeVertsLinearColorGradientKeepAlpha (draw_list, vert_start_idx, vert_end_idx, gradient_p0, gradient_p1, hue_colors [n], hue_colors [n+1 ]);
4696
+ ShadeVertsLinearColorGradientKeepAlpha (draw_list, vert_start_idx, vert_end_idx, gradient_p0, gradient_p1, col_hues [n], col_hues [n+1 ]);
4690
4697
}
4691
4698
4692
4699
// Render Cursor + preview on Hue Wheel
@@ -4696,8 +4703,8 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl
4696
4703
float hue_cursor_rad = value_changed_h ? wheel_thickness * 0 .65f : wheel_thickness * 0 .55f ;
4697
4704
int hue_cursor_segments = ImClamp ((int )(hue_cursor_rad / 1 .4f ), 9 , 32 );
4698
4705
draw_list->AddCircleFilled (hue_cursor_pos, hue_cursor_rad, hue_color32, hue_cursor_segments);
4699
- draw_list->AddCircle (hue_cursor_pos, hue_cursor_rad+1 , IM_COL32 ( 128 , 128 , 128 , 255 ) , hue_cursor_segments);
4700
- draw_list->AddCircle (hue_cursor_pos, hue_cursor_rad, IM_COL32_WHITE , hue_cursor_segments);
4706
+ draw_list->AddCircle (hue_cursor_pos, hue_cursor_rad+1 , col_midgrey , hue_cursor_segments);
4707
+ draw_list->AddCircle (hue_cursor_pos, hue_cursor_rad, col_white , hue_cursor_segments);
4701
4708
4702
4709
// Render SV triangle (rotated according to hue)
4703
4710
ImVec2 tra = wheel_center + ImRotate (triangle_pa, cos_hue_angle, sin_hue_angle);
@@ -4707,46 +4714,46 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl
4707
4714
draw_list->PrimReserve (6 , 6 );
4708
4715
draw_list->PrimVtx (tra, uv_white, hue_color32);
4709
4716
draw_list->PrimVtx (trb, uv_white, hue_color32);
4710
- draw_list->PrimVtx (trc, uv_white, IM_COL32_WHITE );
4711
- draw_list->PrimVtx (tra, uv_white, IM_COL32_BLACK_TRANS );
4712
- draw_list->PrimVtx (trb, uv_white, IM_COL32_BLACK );
4713
- draw_list->PrimVtx (trc, uv_white, IM_COL32_BLACK_TRANS );
4714
- draw_list->AddTriangle (tra, trb, trc, IM_COL32 ( 128 , 128 , 128 , 255 ) , 1 .5f );
4717
+ draw_list->PrimVtx (trc, uv_white, col_white );
4718
+ draw_list->PrimVtx (tra, uv_white, 0 );
4719
+ draw_list->PrimVtx (trb, uv_white, col_white );
4720
+ draw_list->PrimVtx (trc, uv_white, 0 );
4721
+ draw_list->AddTriangle (tra, trb, trc, col_midgrey , 1 .5f );
4715
4722
sv_cursor_pos = ImLerp (ImLerp (trc, tra, ImSaturate (S)), trb, ImSaturate (1 - V));
4716
4723
}
4717
4724
else if (flags & ImGuiColorEditFlags_PickerHueBar)
4718
4725
{
4719
4726
// Render SV Square
4720
- draw_list->AddRectFilledMultiColor (picker_pos, picker_pos + ImVec2 (sv_picker_size,sv_picker_size), IM_COL32_WHITE , hue_color32, hue_color32, IM_COL32_WHITE );
4721
- draw_list->AddRectFilledMultiColor (picker_pos, picker_pos + ImVec2 (sv_picker_size,sv_picker_size), IM_COL32_BLACK_TRANS, IM_COL32_BLACK_TRANS, IM_COL32_BLACK, IM_COL32_BLACK );
4722
- RenderFrameBorder (picker_pos, picker_pos + ImVec2 (sv_picker_size,sv_picker_size), 0 .0f );
4727
+ draw_list->AddRectFilledMultiColor (picker_pos, picker_pos + ImVec2 (sv_picker_size, sv_picker_size), col_white , hue_color32, hue_color32, col_white );
4728
+ draw_list->AddRectFilledMultiColor (picker_pos, picker_pos + ImVec2 (sv_picker_size, sv_picker_size), 0 , 0 , col_black, col_black );
4729
+ RenderFrameBorder (picker_pos, picker_pos + ImVec2 (sv_picker_size, sv_picker_size), 0 .0f );
4723
4730
sv_cursor_pos.x = ImClamp ((float )(int )(picker_pos.x + ImSaturate (S) * sv_picker_size + 0 .5f ), picker_pos.x + 2 , picker_pos.x + sv_picker_size - 2 ); // Sneakily prevent the circle to stick out too much
4724
4731
sv_cursor_pos.y = ImClamp ((float )(int )(picker_pos.y + ImSaturate (1 - V) * sv_picker_size + 0 .5f ), picker_pos.y + 2 , picker_pos.y + sv_picker_size - 2 );
4725
4732
4726
4733
// Render Hue Bar
4727
4734
for (int i = 0 ; i < 6 ; ++i)
4728
- draw_list->AddRectFilledMultiColor (ImVec2 (bar0_pos_x, picker_pos.y + i * (sv_picker_size / 6 )), ImVec2 (bar0_pos_x + bars_width, picker_pos.y + (i + 1 ) * (sv_picker_size / 6 )), hue_colors [i], hue_colors [i], hue_colors [i + 1 ], hue_colors [i + 1 ]);
4735
+ draw_list->AddRectFilledMultiColor (ImVec2 (bar0_pos_x, picker_pos.y + i * (sv_picker_size / 6 )), ImVec2 (bar0_pos_x + bars_width, picker_pos.y + (i + 1 ) * (sv_picker_size / 6 )), col_hues [i], col_hues [i], col_hues [i + 1 ], col_hues [i + 1 ]);
4729
4736
float bar0_line_y = (float )(int )(picker_pos.y + H * sv_picker_size + 0 .5f );
4730
4737
RenderFrameBorder (ImVec2 (bar0_pos_x, picker_pos.y ), ImVec2 (bar0_pos_x + bars_width, picker_pos.y + sv_picker_size), 0 .0f );
4731
- RenderArrowsForVerticalBar (draw_list, ImVec2 (bar0_pos_x - 1 , bar0_line_y), ImVec2 (bars_triangles_half_sz + 1 , bars_triangles_half_sz), bars_width + 2 .0f );
4738
+ RenderArrowsForVerticalBar (draw_list, ImVec2 (bar0_pos_x - 1 , bar0_line_y), ImVec2 (bars_triangles_half_sz + 1 , bars_triangles_half_sz), bars_width + 2 .0f , style. Alpha );
4732
4739
}
4733
4740
4734
4741
// Render cursor/preview circle (clamp S/V within 0..1 range because floating points colors may lead HSV values to be out of range)
4735
4742
float sv_cursor_rad = value_changed_sv ? 10 .0f : 6 .0f ;
4736
- draw_list->AddCircleFilled (sv_cursor_pos, sv_cursor_rad, col32_no_alpha , 12 );
4737
- draw_list->AddCircle (sv_cursor_pos, sv_cursor_rad+1 , IM_COL32 ( 128 , 128 , 128 , 255 ) , 12 );
4738
- draw_list->AddCircle (sv_cursor_pos, sv_cursor_rad, IM_COL32_WHITE , 12 );
4743
+ draw_list->AddCircleFilled (sv_cursor_pos, sv_cursor_rad, user_col32_striped_of_alpha , 12 );
4744
+ draw_list->AddCircle (sv_cursor_pos, sv_cursor_rad+1 , col_midgrey , 12 );
4745
+ draw_list->AddCircle (sv_cursor_pos, sv_cursor_rad, col_white , 12 );
4739
4746
4740
4747
// Render alpha bar
4741
4748
if (alpha_bar)
4742
4749
{
4743
4750
float alpha = ImSaturate (col[3 ]);
4744
4751
ImRect bar1_bb (bar1_pos_x, picker_pos.y , bar1_pos_x + bars_width, picker_pos.y + sv_picker_size);
4745
- RenderColorRectWithAlphaCheckerboard (bar1_bb.Min , bar1_bb.Max , IM_COL32 ( 0 , 0 , 0 , 0 ) , bar1_bb.GetWidth () / 2 .0f , ImVec2 (0 .0f , 0 .0f ));
4746
- draw_list->AddRectFilledMultiColor (bar1_bb.Min , bar1_bb.Max , col32_no_alpha, col32_no_alpha, col32_no_alpha & ~IM_COL32_A_MASK, col32_no_alpha & ~IM_COL32_A_MASK);
4752
+ RenderColorRectWithAlphaCheckerboard (bar1_bb.Min , bar1_bb.Max , 0 , bar1_bb.GetWidth () / 2 .0f , ImVec2 (0 .0f , 0 .0f ));
4753
+ 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);
4747
4754
float bar1_line_y = (float )(int )(picker_pos.y + (1 .0f - alpha) * sv_picker_size + 0 .5f );
4748
4755
RenderFrameBorder (bar1_bb.Min , bar1_bb.Max , 0 .0f );
4749
- RenderArrowsForVerticalBar (draw_list, ImVec2 (bar1_pos_x - 1 , bar1_line_y), ImVec2 (bars_triangles_half_sz + 1 , bars_triangles_half_sz), bars_width + 2 .0f );
4756
+ RenderArrowsForVerticalBar (draw_list, ImVec2 (bar1_pos_x - 1 , bar1_line_y), ImVec2 (bars_triangles_half_sz + 1 , bars_triangles_half_sz), bars_width + 2 .0f , style. Alpha );
4750
4757
}
4751
4758
4752
4759
EndGroup ();
0 commit comments