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
| 6068 | // 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..) |
| 6069 | // 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) |
| 6070 | bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags flags, const float* ref_col) |
| 6071 | { |
| 6072 | ImGuiContext& g = *GImGui; |
| 6073 | ImGuiWindow* window = GetCurrentWindow(); |
| 6074 | if (window->SkipItems) |
| 6075 | return false; |
| 6076 | |
| 6077 | ImDrawList* draw_list = window->DrawList; |
| 6078 | ImGuiStyle& style = g.Style; |
| 6079 | ImGuiIO& io = g.IO; |
| 6080 | |
| 6081 | const float width = CalcItemWidth(); |
| 6082 | const bool is_readonly = ((g.NextItemData.ItemFlags | g.CurrentItemFlags) & ImGuiItemFlags_ReadOnly) != 0; |
| 6083 | g.NextItemData.ClearFlags(); |
| 6084 | |
| 6085 | PushID(label); |
| 6086 | const bool set_current_color_edit_id = (g.ColorEditCurrentID == 0); |
| 6087 | if (set_current_color_edit_id) |
| 6088 | g.ColorEditCurrentID = window->IDStack.back(); |
| 6089 | BeginGroup(); |
| 6090 | |
| 6091 | if (!(flags & ImGuiColorEditFlags_NoSidePreview)) |
| 6092 | flags |= ImGuiColorEditFlags_NoSmallPreview; |
| 6093 | |
| 6094 | // Context menu: display and store options. |
| 6095 | if (!(flags & ImGuiColorEditFlags_NoOptions)) |
| 6096 | ColorPickerOptionsPopup(col, flags); |
| 6097 | |
| 6098 | // Read stored options |
| 6099 | if (!(flags & ImGuiColorEditFlags_PickerMask_)) |
| 6100 | flags |= ((g.ColorEditOptions & ImGuiColorEditFlags_PickerMask_) ? g.ColorEditOptions : ImGuiColorEditFlags_DefaultOptions_) & ImGuiColorEditFlags_PickerMask_; |
| 6101 | if (!(flags & ImGuiColorEditFlags_InputMask_)) |
| 6102 | flags |= ((g.ColorEditOptions & ImGuiColorEditFlags_InputMask_) ? g.ColorEditOptions : ImGuiColorEditFlags_DefaultOptions_) & ImGuiColorEditFlags_InputMask_; |
| 6103 | IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiColorEditFlags_PickerMask_)); // Check that only 1 is selected |
| 6104 | IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiColorEditFlags_InputMask_)); // Check that only 1 is selected |
| 6105 | if (!(flags & ImGuiColorEditFlags_NoOptions)) |
| 6106 | flags |= (g.ColorEditOptions & ImGuiColorEditFlags_AlphaBar); |
| 6107 | |
| 6108 | // Setup |
| 6109 | int components = (flags & ImGuiColorEditFlags_NoAlpha) ? 3 : 4; |
| 6110 | bool alpha_bar = (flags & ImGuiColorEditFlags_AlphaBar) && !(flags & ImGuiColorEditFlags_NoAlpha); |
| 6111 | ImVec2 picker_pos = window->DC.CursorPos; |
| 6112 | float square_sz = GetFrameHeight(); |
| 6113 | float bars_width = square_sz; // Arbitrary smallish width of Hue/Alpha picking bars |
| 6114 | float sv_picker_size = ImMax(bars_width * 1, width - (alpha_bar ? 2 : 1) * (bars_width + style.ItemInnerSpacing.x)); // Saturation/Value picking box |
| 6115 | float bar0_pos_x = picker_pos.x + sv_picker_size + style.ItemInnerSpacing.x; |
| 6116 | float bar1_pos_x = bar0_pos_x + bars_width + style.ItemInnerSpacing.x; |
| 6117 | float bars_triangles_half_sz = IM_TRUNC(bars_width * 0.20f); |
| 6118 | |
| 6119 | float backup_initial_col[4]; |
| 6120 | memcpy(backup_initial_col, col, components * sizeof(float)); |
| 6121 | |
| 6122 | float wheel_thickness = sv_picker_size * 0.08f; |
| 6123 | float wheel_r_outer = sv_picker_size * 0.50f; |
| 6124 | float wheel_r_inner = wheel_r_outer - wheel_thickness; |
| 6125 | ImVec2 wheel_center(picker_pos.x + (sv_picker_size + bars_width)*0.5f, picker_pos.y + sv_picker_size * 0.5f); |
| 6126 | |
| 6127 | // 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