Note: ColorPicker4() only accesses 3 floats if ImGuiColorEditFlags_NoAlpha flag is set. (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.) 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
| 5366 | // 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..) |
| 5367 | // 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) |
| 5368 | bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags flags, const float* ref_col) |
| 5369 | { |
| 5370 | ImGuiContext& g = *GImGui; |
| 5371 | ImGuiWindow* window = GetCurrentWindow(); |
| 5372 | if (window->SkipItems) |
| 5373 | return false; |
| 5374 | |
| 5375 | ImDrawList* draw_list = window->DrawList; |
| 5376 | ImGuiStyle& style = g.Style; |
| 5377 | ImGuiIO& io = g.IO; |
| 5378 | |
| 5379 | const float width = CalcItemWidth(); |
| 5380 | g.NextItemData.ClearFlags(); |
| 5381 | |
| 5382 | PushID(label); |
| 5383 | const bool set_current_color_edit_id = (g.ColorEditCurrentID == 0); |
| 5384 | if (set_current_color_edit_id) |
| 5385 | g.ColorEditCurrentID = window->IDStack.back(); |
| 5386 | BeginGroup(); |
| 5387 | |
| 5388 | if (!(flags & ImGuiColorEditFlags_NoSidePreview)) |
| 5389 | flags |= ImGuiColorEditFlags_NoSmallPreview; |
| 5390 | |
| 5391 | // Context menu: display and store options. |
| 5392 | if (!(flags & ImGuiColorEditFlags_NoOptions)) |
| 5393 | ColorPickerOptionsPopup(col, flags); |
| 5394 | |
| 5395 | // Read stored options |
| 5396 | if (!(flags & ImGuiColorEditFlags_PickerMask_)) |
| 5397 | flags |= ((g.ColorEditOptions & ImGuiColorEditFlags_PickerMask_) ? g.ColorEditOptions : ImGuiColorEditFlags_DefaultOptions_) & ImGuiColorEditFlags_PickerMask_; |
| 5398 | if (!(flags & ImGuiColorEditFlags_InputMask_)) |
| 5399 | flags |= ((g.ColorEditOptions & ImGuiColorEditFlags_InputMask_) ? g.ColorEditOptions : ImGuiColorEditFlags_DefaultOptions_) & ImGuiColorEditFlags_InputMask_; |
| 5400 | IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiColorEditFlags_PickerMask_)); // Check that only 1 is selected |
| 5401 | IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiColorEditFlags_InputMask_)); // Check that only 1 is selected |
| 5402 | if (!(flags & ImGuiColorEditFlags_NoOptions)) |
| 5403 | flags |= (g.ColorEditOptions & ImGuiColorEditFlags_AlphaBar); |
| 5404 | |
| 5405 | // Setup |
| 5406 | int components = (flags & ImGuiColorEditFlags_NoAlpha) ? 3 : 4; |
| 5407 | bool alpha_bar = (flags & ImGuiColorEditFlags_AlphaBar) && !(flags & ImGuiColorEditFlags_NoAlpha); |
| 5408 | ImVec2 picker_pos = window->DC.CursorPos; |
| 5409 | float square_sz = GetFrameHeight(); |
| 5410 | float bars_width = square_sz; // Arbitrary smallish width of Hue/Alpha picking bars |
| 5411 | float sv_picker_size = ImMax(bars_width * 1, width - (alpha_bar ? 2 : 1) * (bars_width + style.ItemInnerSpacing.x)); // Saturation/Value picking box |
| 5412 | float bar0_pos_x = picker_pos.x + sv_picker_size + style.ItemInnerSpacing.x; |
| 5413 | float bar1_pos_x = bar0_pos_x + bars_width + style.ItemInnerSpacing.x; |
| 5414 | float bars_triangles_half_sz = IM_FLOOR(bars_width * 0.20f); |
| 5415 | |
| 5416 | float backup_initial_col[4]; |
| 5417 | memcpy(backup_initial_col, col, components * sizeof(float)); |
| 5418 | |
| 5419 | float wheel_thickness = sv_picker_size * 0.08f; |
| 5420 | float wheel_r_outer = sv_picker_size * 0.50f; |
| 5421 | float wheel_r_inner = wheel_r_outer - wheel_thickness; |
| 5422 | ImVec2 wheel_center(picker_pos.x + (sv_picker_size + bars_width) * 0.5f, picker_pos.y + sv_picker_size * 0.5f); |
| 5423 | |
| 5424 | // Note: the triangle is displayed rotated with triangle_pa pointing to Hue, but most coordinates stays unrotated for logic. |
| 5425 | float triangle_r = wheel_r_inner - (int)(sv_picker_size * 0.027f); |
nothing calls this directly
no test coverage detected