mirror of
https://github.com/ocornut/imgui.git
synced 2026-07-09 02:49:39 +00:00
ColorPicker: added option to fix Saturation/Value triangle in wheel picker. (#9337)
This commit is contained in:
5
imgui.h
5
imgui.h
@@ -1914,8 +1914,9 @@ enum ImGuiColorEditFlags_
|
||||
ImGuiColorEditFlags_Float = 1 << 24, // [DataType] // ColorEdit, ColorPicker, ColorButton: _display_ values formatted as 0.0f..1.0f floats instead of 0..255 integers. No round-trip of value via integers.
|
||||
ImGuiColorEditFlags_PickerHueBar = 1 << 25, // [Picker] // ColorPicker: bar for Hue, rectangle for Sat/Value.
|
||||
ImGuiColorEditFlags_PickerHueWheel = 1 << 26, // [Picker] // ColorPicker: wheel for Hue, triangle for Sat/Value.
|
||||
ImGuiColorEditFlags_InputRGB = 1 << 27, // [Input] // ColorEdit, ColorPicker: input and output data in RGB format.
|
||||
ImGuiColorEditFlags_InputHSV = 1 << 28, // [Input] // ColorEdit, ColorPicker: input and output data in HSV format.
|
||||
ImGuiColorEditFlags_FixedTriangle = 1 << 27, // [Picker] // ColorPicker: fix triangle position for PickerHueWheel.
|
||||
ImGuiColorEditFlags_InputRGB = 1 << 28, // [Input] // ColorEdit, ColorPicker: input and output data in RGB format.
|
||||
ImGuiColorEditFlags_InputHSV = 1 << 29, // [Input] // ColorEdit, ColorPicker: input and output data in HSV format.
|
||||
|
||||
// Defaults Options copied to io.ConfigColorEditFlags during initialization.
|
||||
// The intent is that you probably don't want to override them in most of your calls.
|
||||
|
||||
@@ -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