62 for (
int i = 0; i < 3; i++) {
63 if (
fabsf(rgb[i]) < 5e-5f) {
66 else if (
fabsf(1.0f - rgb[i]) < 5e-5f) {
76 switch (
U.color_picker_type) {
88 switch (
U.color_picker_type) {
100 switch (
U.color_picker_type) {
127 if (color_components_count == 4) {
173 const bool is_editing_sliders,
174 const float rgb_scene_linear[3])
181 if (cpicker->
is_init ==
false ||
190 if (cpicker->
is_init ==
false) {
200 if (cpicker->
is_init ==
false) {
214 float rgb_perceptual_slider[3];
215 copy_v3_v3(rgb_perceptual_slider, rgb_scene_linear);
218 if (cpicker->
is_init ==
false) {
231 float rgb_perceptual_slider[3];
243 const bool is_editing_sliders,
244 const float rgba_scene_linear[4])
250 if (bt.custom_data != cpicker) {
263 uchar rgba_hex_uchar[4];
283 memcpy(bt.poin, col, col_len + 1);
302 float rgba_scene_linear[4];
306 &ptr, prop, rgba_scene_linear,
ARRAY_SIZE(rgba_scene_linear));
326 float rgba_scene_linear[4];
333 &ptr, prop, rgba_scene_linear,
ARRAY_SIZE(rgba_scene_linear));
356 float rgba_scene_linear[4];
363 &ptr, prop, rgba_scene_linear,
ARRAY_SIZE(rgba_scene_linear));
384 float rgba_scene_linear[4];
391 &ptr, prop, rgba_scene_linear,
ARRAY_SIZE(rgba_scene_linear));
426 const bool is_parsed =
hex_to_rgba(hexcol, rgba, rgba + 1, rgba + 2, rgba + 3);
501 float rgba_scene_linear[4];
505 &ptr, prop, rgba_scene_linear,
ARRAY_SIZE(rgba_scene_linear));
511#define PICKER_TOTAL_W (180.0f * UI_SCALE_FAC)
512#define PICKER_BAR ((8.0f * UI_SCALE_FAC) + (6 * U.pixelsize))
513#define PICKER_SPACE (8.0f * UI_SCALE_FAC)
514#define PICKER_W (PICKER_TOTAL_W - PICKER_BAR - PICKER_SPACE)
515#define PICKER_H PICKER_W
523 const char **r_area_tooltip,
524 const char **r_slider_tooltip)
532 const char *axis_x =
nullptr;
533 const char *axis_y =
nullptr;
534 const char *slider =
nullptr;
536 switch (
U.color_picker_type) {
563 *r_area_tooltip = name_color;
564 *r_slider_tooltip = name_val;
571 *r_slider_tooltip = slider;
581 const char *circle_tooltip;
582 const char *slider_tooltip;
626 const char *square_tooltip;
627 const char *slider_tooltip;
674 float rgba_scene_linear[4],
680 float softmin, softmax, hardmin, hardmax,
step, precision;
701 switch (
U.color_picker_type) {
727 TIP_(
"Color Space: ") + std::string(
static_cast<const char *
>(space)),
746 TIP_(
"Scene linear values in the working color space"));
767 TIP_(
"Perceptually uniform values, matching the color picker"));
813 TIP_(
"Hue, Saturation, Value"));
821 const int slider_yco = yco - 1.1f *
UI_UNIT_Y;
827 const auto add_rgb_perceptual_slider =
828 [&](
const char *
str,
const char *tip,
const int index,
const int y) {
849 add_rgb_perceptual_slider(
IFACE_(
"Red:"),
TIP_(
"Red"), 0, yco);
854 const auto add_hsv_perceptual_slider =
855 [&](
const char *
str,
const char *tip,
const int index,
const int y,
const bool linear) {
884 add_hsv_perceptual_slider(
IFACE_(
"Saturation:"),
890 add_hsv_perceptual_slider(
IFACE_(
"Lightness:"),
912 const auto add_rgb_perceptual_slider =
913 [&](
const char *
str,
const char *tip,
const int index,
const int y) {
934 add_rgb_perceptual_slider(
IFACE_(
"Red:"),
TIP_(
"Red"), 0, yco);
939 add_hsv_perceptual_slider(
IFACE_(
"Hue:"),
TIP_(
"Hue"), 0, yco,
false);
940 add_hsv_perceptual_slider(
943 add_hsv_perceptual_slider(
975 rgba_scene_linear[3] = 1.0f;
982 uchar rgba_hex_uchar[4];
1002 const int label_width = picker_width * 0.15f;
1003 const int eyedropper_offset = show_picker ?
UI_UNIT_X * 1.25f : 0;
1004 const int text_width = picker_width - label_width - eyedropper_offset;
1029 const auto bt_tooltip_func =
1031 const bool *has_alpha =
static_cast<bool *
>(has_alpha_ptr);
1034 TIP_(
"Hex triplet for color with alpha (#RRGGBBAA)."),
1042 TIP_(
"Hex triplet for color (#RRGGBB)."),
1052 bt, bt_tooltip_func,
static_cast<void *
>(&cpicker->
has_alpha),
nullptr);
1060 "UI_OT_eyedropper_color",
1081 float(event->
xy[0]),
1082 float(event->
xy[1]));
1093 switch (event->
type) {
1114 float rgba_perceptual[4];
1122 hsv_perceptual[2] =
clamp_f(hsv_perceptual[2] + add, 0.0f, 1.0f);
1125 float rgba_scene_linear[4];
1126 rgba_scene_linear[3] = rgba_perceptual[3];
#define SNPRINTF_UTF8(dst, format,...)
#define SNPRINTF_UTF8_RLEN(dst, format,...)
#define CTX_IFACE_(context, msgid)
#define CTX_TIP_(context, msgid)
#define BLT_I18NCONTEXT_COLOR
Read Blender memory allocation and freeing.
#define UNPACK3_EX(pre, a, post)
#define UNPACK4_EX(pre, a, post)
#define SET_FLAG_FROM_TEST(value, test, flag)
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
static void colorpicker_update_type_space_cb(bContext *, void *picker_bt1, void *prop_bt1)
static void block_colorpicker(const bContext *, Block *block, Button *from_but, float rgba_scene_linear[4], bool show_picker)
Block * block_func_COLOR(bContext *C, PopupBlockHandle *handle, void *arg_but)
static void colorpicker_hex_rna_cb(bContext *, void *bt1, void *bt2)
void perceptual_to_scene_linear_space(Button *but, float rgb[3])
void button_v4_set(Button *but, const float vec[4])
void button_string_get(Button *but, char *str, const size_t str_maxncpy)
@ BLOCK_THEME_STYLE_POPUP
void button_func_set(Button *but, std::function< void(bContext &)> func)
void button_v4_get(Button *but, float vec[4])
void block_bounds_set_normal(Block *block, int addval)
static void colorpicker_square(Block *block, PointerRNA *ptr, PropertyRNA *prop, eButGradientType type, ColorPicker *cpicker)
static char g_color_picker_type
static void colorpicker_hsv_perceptual_slider_update_cb(bContext *, void *bt1, void *bt2)
void block_align_begin(Block *block)
static void colorpicker_hide_reveal(Block *block)
static int colorpicker_wheel_cb(const bContext *, Block *block, const wmEvent *event)
static void colorpicker_circle(Block *block, PointerRNA *ptr, PropertyRNA *prop, ColorPicker *cpicker)
static void update_color_picker_buts_rgba(Block *block, ColorPicker *cpicker, const bool is_editing_sliders, const float rgba_scene_linear[4])
Button * uiDefIconButO(Block *block, ButtonType type, StringRefNull opname, wm::OpCallContext opcontext, int icon, int x, int y, short width, short height, std::optional< StringRef > tip)
ColorPicker * block_colorpicker_create(Block *block)
void button_func_tooltip_custom_set(Button *but, ButtonToolTipCustomFunc func, void *arg, FreeArgFunc free_arg)
void scene_linear_to_perceptual_space(Button *but, float rgb[3])
bool button_color_has_alpha(Button *but)
void color_picker_rgb_to_hsv(const float rgb[3], float r_cp[3])
static void popup_close_cb(bContext *, void *bt1, void *)
Block * block_begin(const bContext *C, ARegion *region, std::string name, EmbossType emboss)
Button * uiDefBut(Block *block, ButtonTypeWithPointerType but_and_ptr_type, StringRef str, int x, int y, short width, short height, void *poin, float min, float max, std::optional< StringRef > tip)
static void color_picker_rgb_round(float rgb[3])
static void colorpicker_tooltips(ColorPicker *cpicker, const char **r_area_tooltip, const char **r_slider_tooltip)
Button * uiDefButR_prop(Block *block, ButtonType type, std::optional< StringRef > str, int x, int y, short width, short height, PointerRNA *ptr, PropertyRNA *prop, int index, float min, float max, std::optional< StringRef > tip)
void button_number_slider_precision_set(Button *but, float precision)
void block_theme_style_set(Block *block, char theme_style)
static char g_color_picker_space
static void colorpicker_rgb_perceptual_slider_update_cb(bContext *, void *bt1, void *bt2)
void block_align_end(Block *block)
void tooltip_text_field_add(TooltipData &data, std::string text, std::string suffix, const TooltipStyle style, const TooltipColorID color_id, const bool is_pad=false)
void button_flag_disable(Button *but, int64_t flag)
void color_picker_hsv_to_rgb(const float r_cp[3], float rgb[3])
void button_drawflag_disable(Button *but, int flag)
bool button_is_color_gamma(Button &but)
void button_number_slider_step_size_set(Button *but, float step_size)
void button_v3_set(Button *but, const float vec[3])
Button * uiDefButV(Block *block, ButtonType type, StringRef str, int x, int y, short width, short height, T *poin, float min, float max, std::optional< StringRef > tip)
static void colorpicker_rgba_update_cb(bContext *, void *picker_bt1, void *prop_bt1)
static void color_picker_update_from_rgb_linear(ColorPicker *cpicker, const bool is_gamma, const bool is_editing_sliders, const float rgb_scene_linear[3])
void button_hsv_set(Button *but)
@ PICKER_SPACE_PERCEPTUAL
void button_update(Button *but)
void color_picker_rgb_to_hsv_compat(const float rgb[3], float r_cp[3])
static void colorpicker_hsv_linear_slider_update_cb(bContext *, void *bt1, void *bt2)
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void RNA_property_float_get_array_at_most(PointerRNA *ptr, PropertyRNA *prop, float *values, int values_num)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void rgb_to_hsl_v(const float rgb[3], float r_hsl[3])
void rgb_to_hsv_v(const float rgb[3], float r_hsv[3])
void rgb_to_hsv_compat_v(const float rgb[3], float r_hsv[3])
@ COLOR_ROLE_SCENE_LINEAR
@ COLOR_ROLE_COLOR_PICKING
MINLINE void zero_v4(float r[4])
MINLINE bool equals_v3v3(const float v1[3], const float v2[3]) ATTR_WARN_UNUSED_RESULT
void IMB_colormanagement_scene_linear_to_color_picking_v3(float color_picking[3], const float scene_linear[3])
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
const char * IMB_colormanagement_role_colorspace_name_get(int role)
void hsv_to_rgb_v(const float hsv[3], float r_rgb[3])
BLI_INLINE void IMB_colormanagement_srgb_to_scene_linear_v3(float scene_linear[3], const float srgb[3])
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
void rgb_to_hsl_compat_v(const float rgb[3], float r_hsl[3])
void hsl_to_rgb_v(const float hsl[3], float r_rgb[3])
PropertySubType RNA_property_subtype(PropertyRNA *prop)
bool hex_to_rgba(const char *hexcol, float *r_r, float *r_g, float *r_b, float *r_a)
void IMB_colormanagement_color_picking_to_scene_linear_v3(float scene_linear[3], const float color_picking[3])
int WM_event_absolute_delta_y(const wmEvent *event)
MINLINE void copy_v4_v4(float r[4], const float a[4])
void RNA_property_float_ui_range(PointerRNA *ptr, PropertyRNA *prop, float *softmin, float *softmax, float *step, float *precision)
bool BLI_rcti_isect_pt(const struct rcti *rect, int x, int y)
BLI_INLINE void IMB_colormanagement_scene_linear_to_srgb_v3(float srgb[3], const float scene_linear[3])
MINLINE void rgba_float_to_uchar(unsigned char r_col[4], const float col_f[4])
void RNA_property_float_range(PointerRNA *ptr, PropertyRNA *prop, float *hardmin, float *hardmax)
MINLINE float clamp_f(float value, float min, float max)
int(*) block_event_func(const bContext *C, Block *, const wmEvent *)
std::ranges::transform_view< std::ranges::ref_view< const Vector< std::unique_ptr< Button > > >, Button &(*)(const std::unique_ptr< Button > &)> buttons() const
PopupBlockHandle * handle
bool is_color_gamma_picker
ColorPickerData color_pickers
ListBaseT< ColorPicker > list
float hsv_perceptual_slider[3]
float rgb_perceptual_slider[3]
float hsv_linear_slider[3]
float hsv_perceptual_init[3]
#define ISMOUSE_WHEEL(event_type)