mirror of
https://github.com/ocornut/imgui.git
synced 2026-07-23 09:23:16 +00:00
ColorPicker: added option to fix Saturation/Value triangle in wheel picker. (#9337)
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user