MCPcopy Create free account
hub / github.com/cinder/Cinder / ColorPicker4

Method ColorPicker4

src/imgui/imgui_widgets.cpp:5959–6326  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

5957// 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..)
5958// 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)
5959bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags flags, const float* ref_col)
5960{
5961 ImGuiContext& g = *GImGui;
5962 ImGuiWindow* window = GetCurrentWindow();
5963 if (window->SkipItems)
5964 return false;
5965
5966 ImDrawList* draw_list = window->DrawList;
5967 ImGuiStyle& style = g.Style;
5968 ImGuiIO& io = g.IO;
5969
5970 const float width = CalcItemWidth();
5971 const bool is_readonly = ((g.NextItemData.ItemFlags | g.CurrentItemFlags) & ImGuiItemFlags_ReadOnly) != 0;
5972 g.NextItemData.ClearFlags();
5973
5974 PushID(label);
5975 const bool set_current_color_edit_id = (g.ColorEditCurrentID == 0);
5976 if (set_current_color_edit_id)
5977 g.ColorEditCurrentID = window->IDStack.back();
5978 BeginGroup();
5979
5980 if (!(flags & ImGuiColorEditFlags_NoSidePreview))
5981 flags |= ImGuiColorEditFlags_NoSmallPreview;
5982
5983 // Context menu: display and store options.
5984 if (!(flags & ImGuiColorEditFlags_NoOptions))
5985 ColorPickerOptionsPopup(col, flags);
5986
5987 // Read stored options
5988 if (!(flags & ImGuiColorEditFlags_PickerMask_))
5989 flags |= ((g.ColorEditOptions & ImGuiColorEditFlags_PickerMask_) ? g.ColorEditOptions : ImGuiColorEditFlags_DefaultOptions_) & ImGuiColorEditFlags_PickerMask_;
5990 if (!(flags & ImGuiColorEditFlags_InputMask_))
5991 flags |= ((g.ColorEditOptions & ImGuiColorEditFlags_InputMask_) ? g.ColorEditOptions : ImGuiColorEditFlags_DefaultOptions_) & ImGuiColorEditFlags_InputMask_;
5992 IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiColorEditFlags_PickerMask_)); // Check that only 1 is selected
5993 IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiColorEditFlags_InputMask_)); // Check that only 1 is selected
5994 if (!(flags & ImGuiColorEditFlags_NoOptions))
5995 flags |= (g.ColorEditOptions & ImGuiColorEditFlags_AlphaBar);
5996
5997 // Setup
5998 int components = (flags & ImGuiColorEditFlags_NoAlpha) ? 3 : 4;
5999 bool alpha_bar = (flags & ImGuiColorEditFlags_AlphaBar) && !(flags & ImGuiColorEditFlags_NoAlpha);
6000 ImVec2 picker_pos = window->DC.CursorPos;
6001 float square_sz = GetFrameHeight();
6002 float bars_width = square_sz; // Arbitrary smallish width of Hue/Alpha picking bars
6003 float sv_picker_size = ImMax(bars_width * 1, width - (alpha_bar ? 2 : 1) * (bars_width + style.ItemInnerSpacing.x)); // Saturation/Value picking box
6004 float bar0_pos_x = picker_pos.x + sv_picker_size + style.ItemInnerSpacing.x;
6005 float bar1_pos_x = bar0_pos_x + bars_width + style.ItemInnerSpacing.x;
6006 float bars_triangles_half_sz = IM_TRUNC(bars_width * 0.20f);
6007
6008 float backup_initial_col[4];
6009 memcpy(backup_initial_col, col, components * sizeof(float));
6010
6011 float wheel_thickness = sv_picker_size * 0.08f;
6012 float wheel_r_outer = sv_picker_size * 0.50f;
6013 float wheel_r_inner = wheel_r_outer - wheel_thickness;
6014 ImVec2 wheel_center(picker_pos.x + (sv_picker_size + bars_width)*0.5f, picker_pos.y + sv_picker_size * 0.5f);
6015
6016 // Note: the triangle is displayed rotated with triangle_pa pointing to Hue, but most coordinates stays unrotated for logic.

Callers

nothing calls this directly

Calls 15

GetCurrentWindowFunction · 0.85
ImIsPowerOfTwoFunction · 0.85
ImMaxFunction · 0.85
ImVec2Function · 0.85
ColorEditRestoreHSFunction · 0.85
ImLengthSqrFunction · 0.85
ImTriangleContainsPointFunction · 0.85
ImRotateFunction · 0.85
ImTriangleClosestPointFunction · 0.85
ImClampFunction · 0.85
ImSaturateFunction · 0.85

Tested by

no test coverage detected