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
| 5783 | // 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..) |
| 5784 | // 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) |
| 5785 | bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags flags, const float* ref_col) |
| 5786 | { |
| 5787 | ImGuiContext& g = *GImGui; |
| 5788 | ImGuiWindow* window = GetCurrentWindow(); |
| 5789 | if (window->SkipItems) |
| 5790 | return false; |
| 5791 | |
| 5792 | ImDrawList* draw_list = window->DrawList; |
| 5793 | ImGuiStyle& style = g.Style; |
| 5794 | ImGuiIO& io = g.IO; |
| 5795 | |
| 5796 | const float width = CalcItemWidth(); |
| 5797 | const bool is_readonly = ((g.NextItemData.ItemFlags | g.CurrentItemFlags) & ImGuiItemFlags_ReadOnly) != 0; |
| 5798 | g.NextItemData.ClearFlags(); |
| 5799 | |
| 5800 | PushID(label); |
| 5801 | const bool set_current_color_edit_id = (g.ColorEditCurrentID == 0); |
| 5802 | if (set_current_color_edit_id) |
| 5803 | g.ColorEditCurrentID = window->IDStack.back(); |
| 5804 | BeginGroup(); |
| 5805 | |
| 5806 | if (!(flags & ImGuiColorEditFlags_NoSidePreview)) |
| 5807 | flags |= ImGuiColorEditFlags_NoSmallPreview; |
| 5808 | |
| 5809 | // Context menu: display and store options. |
| 5810 | if (!(flags & ImGuiColorEditFlags_NoOptions)) |
| 5811 | ColorPickerOptionsPopup(col, flags); |
| 5812 | |
| 5813 | // Read stored options |
| 5814 | if (!(flags & ImGuiColorEditFlags_PickerMask_)) |
| 5815 | flags |= ((g.ColorEditOptions & ImGuiColorEditFlags_PickerMask_) ? g.ColorEditOptions : ImGuiColorEditFlags_DefaultOptions_) & ImGuiColorEditFlags_PickerMask_; |
| 5816 | if (!(flags & ImGuiColorEditFlags_InputMask_)) |
| 5817 | flags |= ((g.ColorEditOptions & ImGuiColorEditFlags_InputMask_) ? g.ColorEditOptions : ImGuiColorEditFlags_DefaultOptions_) & ImGuiColorEditFlags_InputMask_; |
| 5818 | IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiColorEditFlags_PickerMask_)); // Check that only 1 is selected |
| 5819 | IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiColorEditFlags_InputMask_)); // Check that only 1 is selected |
| 5820 | if (!(flags & ImGuiColorEditFlags_NoOptions)) |
| 5821 | flags |= (g.ColorEditOptions & ImGuiColorEditFlags_AlphaBar); |
| 5822 | |
| 5823 | // Setup |
| 5824 | int components = (flags & ImGuiColorEditFlags_NoAlpha) ? 3 : 4; |
| 5825 | bool alpha_bar = (flags & ImGuiColorEditFlags_AlphaBar) && !(flags & ImGuiColorEditFlags_NoAlpha); |
| 5826 | ImVec2 picker_pos = window->DC.CursorPos; |
| 5827 | float square_sz = GetFrameHeight(); |
| 5828 | float bars_width = square_sz; // Arbitrary smallish width of Hue/Alpha picking bars |
| 5829 | float sv_picker_size = ImMax(bars_width * 1, width - (alpha_bar ? 2 : 1) * (bars_width + style.ItemInnerSpacing.x)); // Saturation/Value picking box |
| 5830 | float bar0_pos_x = picker_pos.x + sv_picker_size + style.ItemInnerSpacing.x; |
| 5831 | float bar1_pos_x = bar0_pos_x + bars_width + style.ItemInnerSpacing.x; |
| 5832 | float bars_triangles_half_sz = IM_TRUNC(bars_width * 0.20f); |
| 5833 | |
| 5834 | float backup_initial_col[4]; |
| 5835 | memcpy(backup_initial_col, col, components * sizeof(float)); |
| 5836 | |
| 5837 | float wheel_thickness = sv_picker_size * 0.08f; |
| 5838 | float wheel_r_outer = sv_picker_size * 0.50f; |
| 5839 | float wheel_r_inner = wheel_r_outer - wheel_thickness; |
| 5840 | ImVec2 wheel_center(picker_pos.x + (sv_picker_size + bars_width)*0.5f, picker_pos.y + sv_picker_size * 0.5f); |
| 5841 | |
| 5842 | // Note: the triangle is displayed rotated with triangle_pa pointing to Hue, but most coordinates stays unrotated for logic. |
nothing calls this directly
no test coverage detected