ColorPicker: added option to fix Saturation/Value triangle in wheel picker. (#9337)

This commit is contained in:
SeanTheBuilder1
2026-03-31 01:13:25 +08:00
committed by ocornut
parent aca69173df
commit 0785cdb2bb
2 changed files with 19 additions and 2 deletions

View File

@@ -6130,6 +6130,12 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl
ImVec2 triangle_pa = ImVec2(triangle_r, 0.0f); // Hue point.
ImVec2 triangle_pb = ImVec2(triangle_r * -0.5f, triangle_r * -0.866025f); // Black point.
ImVec2 triangle_pc = ImVec2(triangle_r * -0.5f, triangle_r * +0.866025f); // White point.
if (flags & ImGuiColorEditFlags_FixedTriangle)
{
triangle_pa = ImVec2(triangle_r * +0.866025f, triangle_r * +0.5f); // Hue point.
triangle_pb = ImVec2(0.0f, -triangle_r); // Black point.
triangle_pc = ImVec2(triangle_r * -0.866025f, triangle_r * +0.5f); // White point.
}
float H = col[0], S = col[1], V = col[2];
float R = col[0], G = col[1], B = col[2];
@@ -6166,6 +6172,11 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl
}
float cos_hue_angle = ImCos(-H * 2.0f * IM_PI);
float sin_hue_angle = ImSin(-H * 2.0f * IM_PI);
if (flags & ImGuiColorEditFlags_FixedTriangle)
{
cos_hue_angle = ImCos(-0.0 * 2.0f * IM_PI);
sin_hue_angle = ImSin(-0.0 * 2.0f * IM_PI);
}
if (ImTriangleContainsPoint(triangle_pa, triangle_pb, triangle_pc, ImRotate(initial_off, cos_hue_angle, sin_hue_angle)))
{
// Interacting with SV triangle
@@ -6374,6 +6385,11 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl
draw_list->AddCircleFilled(hue_cursor_pos, hue_cursor_rad, hue_color32, hue_cursor_segments);
draw_list->AddCircle(hue_cursor_pos, hue_cursor_rad + 1, col_midgrey, hue_cursor_segments);
draw_list->AddCircle(hue_cursor_pos, hue_cursor_rad, col_white, hue_cursor_segments);
if (flags & ImGuiColorEditFlags_FixedTriangle)
{
cos_hue_angle = ImCos(-0.0 * 2.0f * IM_PI);
sin_hue_angle = ImSin(-0.0 * 2.0f * IM_PI);
}
// Render SV triangle (rotated according to hue)
ImVec2 tra = wheel_center + ImRotate(triangle_pa, cos_hue_angle, sin_hue_angle);