Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_region_color_picker.c
| Show First 20 Lines • Show All 188 Lines • ▼ Show 20 Lines | if (bt->rnaprop) { | ||||
| /* original button that created the color picker already does undo | /* original button that created the color picker already does undo | ||||
| * push, so disable it on RNA buttons in the color picker block */ | * push, so disable it on RNA buttons in the color picker block */ | ||||
| UI_but_flag_disable(bt, UI_BUT_UNDO); | UI_but_flag_disable(bt, UI_BUT_UNDO); | ||||
| } | } | ||||
| else if (STREQ(bt->str, "Hex: ")) { | else if (STREQ(bt->str, "Hex: ")) { | ||||
| float rgb_hex[3]; | float rgb_hex[3]; | ||||
| uchar rgb_hex_uchar[3]; | uchar rgb_hex_uchar[3]; | ||||
| double intpart; | |||||
| char col[16]; | char col[16]; | ||||
| /* Hex code is assumed to be in sRGB space | /* Hex code is assumed to be in sRGB space | ||||
| * (coming from other applications, web, etc) */ | * (coming from other applications, web, etc) */ | ||||
| copy_v3_v3(rgb_hex, rgb); | copy_v3_v3(rgb_hex, rgb); | ||||
| if (from_but && !ui_but_is_color_gamma(from_but)) { | if (from_but && !ui_but_is_color_gamma(from_but)) { | ||||
| IMB_colormanagement_scene_linear_to_srgb_v3(rgb_hex); | IMB_colormanagement_scene_linear_to_srgb_v3(rgb_hex); | ||||
| } | } | ||||
| if (rgb_hex[0] > 1.0f) { | CLAMP3(rgb_hex, 0, 1); | ||||
| rgb_hex[0] = modf(rgb_hex[0], &intpart); | |||||
| } | |||||
| if (rgb_hex[1] > 1.0f) { | |||||
| rgb_hex[1] = modf(rgb_hex[1], &intpart); | |||||
| } | |||||
| if (rgb_hex[2] > 1.0f) { | |||||
| rgb_hex[2] = modf(rgb_hex[2], &intpart); | |||||
| } | |||||
| rgb_float_to_uchar(rgb_hex_uchar, rgb_hex); | rgb_float_to_uchar(rgb_hex_uchar, rgb_hex); | ||||
| BLI_snprintf(col, sizeof(col), "%02X%02X%02X", UNPACK3_EX((uint), rgb_hex_uchar, )); | BLI_snprintf(col, sizeof(col), "%02X%02X%02X", UNPACK3_EX((uint), rgb_hex_uchar, )); | ||||
| strcpy(bt->poin, col); | strcpy(bt->poin, col); | ||||
| /* Hex can't represent rgb values greater than 1, so even if we display | |||||
| * the value, we block editing so the resulting clamped color won't be | |||||
| * accidentally applied */ | |||||
| if (rgb[0] > 1 || rgb[1] > 1 || rgb[2] > 1) { | |||||
| bt->flag |= UI_BUT_DISABLED; | |||||
| bt->disabled_info = "HEX can't represent the current RGB value"; | |||||
| } | |||||
| else { | |||||
| bt->flag &= ~UI_BUT_DISABLED; | |||||
| } | |||||
| } | } | ||||
| else if (bt->str[1] == ' ') { | else if (bt->str[1] == ' ') { | ||||
| if (bt->str[0] == 'R') { | if (bt->str[0] == 'R') { | ||||
| ui_but_value_set(bt, rgb[0]); | ui_but_value_set(bt, rgb[0]); | ||||
| } | } | ||||
| else if (bt->str[0] == 'G') { | else if (bt->str[0] == 'G') { | ||||
| ui_but_value_set(bt, rgb[1]); | ui_but_value_set(bt, rgb[1]); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 562 Lines • ▼ Show 20 Lines | bt = uiDefBut(block, | ||||
| butwidth, | butwidth, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| hexcol, | hexcol, | ||||
| 0, | 0, | ||||
| 8, | 8, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| TIP_("Hex triplet for color (#RRGGBB)")); | TIP_("Hex triplet for color (#RRGGBB)")); | ||||
| /* Hex can't represent rgb values greater than 1, so even if we display | |||||
| * the value, we block editing so the resulting clamped color won't be | |||||
| * accidentally applied */ | |||||
| if (rgba[0] > 1 || rgba[1] > 1 || rgba[2] > 1) { | |||||
| bt->flag |= UI_BUT_DISABLED; | |||||
| bt->disabled_info = "HEX can't represent the current RGB value"; | |||||
| } | |||||
| else { | |||||
| bt->flag &= ~UI_BUT_DISABLED; | |||||
| } | |||||
| UI_but_flag_disable(bt, UI_BUT_UNDO); | UI_but_flag_disable(bt, UI_BUT_UNDO); | ||||
| UI_but_func_set(bt, ui_colorpicker_hex_rna_cb, bt, hexcol); | UI_but_func_set(bt, ui_colorpicker_hex_rna_cb, bt, hexcol); | ||||
| bt->custom_data = cpicker; | bt->custom_data = cpicker; | ||||
| uiDefBut(block, | uiDefBut(block, | ||||
| UI_BTYPE_LABEL, | UI_BTYPE_LABEL, | ||||
| 0, | 0, | ||||
| IFACE_("(Gamma Corrected)"), | IFACE_("(Gamma Corrected)"), | ||||
| 0, | 0, | ||||
| ▲ Show 20 Lines • Show All 103 Lines • Show Last 20 Lines | |||||