Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_regions.c
| Show First 20 Lines • Show All 1,646 Lines • ▼ Show 20 Lines | void ui_set_but_hsv(uiBut *but) | ||||
| float *hsv = ui_block_hsv_get(but->block); | float *hsv = ui_block_hsv_get(but->block); | ||||
| ui_color_picker_to_rgb_v(hsv, col); | ui_color_picker_to_rgb_v(hsv, col); | ||||
| ui_set_but_vectorf(but, col); | ui_set_but_vectorf(but, col); | ||||
| } | } | ||||
| /* also used by small picker, be careful with name checks below... */ | /* also used by small picker, be careful with name checks below... */ | ||||
| static void ui_update_block_buts_rgb(uiBlock *block, const float rgb[3]) | static void ui_update_block_buts_rgb(uiBlock *block, const float rgb[3], bool is_display_space) | ||||
| { | { | ||||
| uiBut *bt; | uiBut *bt; | ||||
| float *hsv = ui_block_hsv_get(block); | float *hsv = ui_block_hsv_get(block); | ||||
| struct ColorManagedDisplay *display = NULL; | struct ColorManagedDisplay *display = NULL; | ||||
| /* this is to keep the H and S value when V is equal to zero | /* this is to keep the H and S value when V is equal to zero | ||||
| * and we are working in HSV mode, of course! | * and we are working in HSV mode, of course! | ||||
| */ | */ | ||||
| if (is_display_space) { | |||||
| ui_rgb_to_color_picker_compat_v(rgb, hsv); | ui_rgb_to_color_picker_compat_v(rgb, hsv); | ||||
| } | |||||
| else { | |||||
| /* we need to convert to display space to use hsv, because hsv is stored in display space */ | |||||
| float rgb_display[3]; | |||||
| copy_v3_v3(rgb_display, rgb); | |||||
| ui_block_to_display_space_v3(block, rgb_display); | |||||
| ui_rgb_to_color_picker_compat_v(rgb_display, hsv); | |||||
| } | |||||
| if (block->color_profile) | if (block->color_profile) | ||||
| display = ui_block_display_get(block); | display = ui_block_display_get(block); | ||||
| /* this updates button strings, is hackish... but button pointers are on stack of caller function */ | /* this updates button strings, is hackish... but button pointers are on stack of caller function */ | ||||
| for (bt = block->buttons.first; bt; bt = bt->next) { | for (bt = block->buttons.first; bt; bt = bt->next) { | ||||
| if (bt->rnaprop) { | if (bt->rnaprop) { | ||||
| ▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | static void do_picker_rna_cb(bContext *UNUSED(C), void *bt1, void *UNUSED(arg)) | ||||
| uiBut *but = (uiBut *)bt1; | uiBut *but = (uiBut *)bt1; | ||||
| uiPopupBlockHandle *popup = but->block->handle; | uiPopupBlockHandle *popup = but->block->handle; | ||||
| PropertyRNA *prop = but->rnaprop; | PropertyRNA *prop = but->rnaprop; | ||||
| PointerRNA ptr = but->rnapoin; | PointerRNA ptr = but->rnapoin; | ||||
| float rgb[4]; | float rgb[4]; | ||||
| if (prop) { | if (prop) { | ||||
| RNA_property_float_get_array(&ptr, prop, rgb); | RNA_property_float_get_array(&ptr, prop, rgb); | ||||
| ui_update_block_buts_rgb(but->block, rgb); | ui_update_block_buts_rgb(but->block, rgb, (RNA_property_subtype(prop) == PROP_COLOR_GAMMA)); | ||||
| } | } | ||||
| if (popup) | if (popup) | ||||
| popup->menuretval = UI_RETURN_UPDATE; | popup->menuretval = UI_RETURN_UPDATE; | ||||
| } | } | ||||
| static void do_color_wheel_rna_cb(bContext *UNUSED(C), void *bt1, void *UNUSED(arg)) | static void do_color_wheel_rna_cb(bContext *UNUSED(C), void *bt1, void *UNUSED(arg)) | ||||
| { | { | ||||
| uiBut *but = (uiBut *)bt1; | uiBut *but = (uiBut *)bt1; | ||||
| uiPopupBlockHandle *popup = but->block->handle; | uiPopupBlockHandle *popup = but->block->handle; | ||||
| float rgb[3]; | float rgb[3]; | ||||
| float *hsv = ui_block_hsv_get(but->block); | float *hsv = ui_block_hsv_get(but->block); | ||||
| bool use_display_colorspace = ui_color_picker_use_display_colorspace(but); | |||||
| ui_color_picker_to_rgb_v(hsv, rgb); | ui_color_picker_to_rgb_v(hsv, rgb); | ||||
| ui_update_block_buts_rgb(but->block, rgb); | /* hsv is saved in display space so convert back */ | ||||
| if (use_display_colorspace) { | |||||
| ui_block_to_scene_linear_v3(but->block, rgb); | |||||
| } | |||||
| ui_update_block_buts_rgb(but->block, rgb, !use_display_colorspace); | |||||
| if (popup) | if (popup) | ||||
| popup->menuretval = UI_RETURN_UPDATE; | popup->menuretval = UI_RETURN_UPDATE; | ||||
| } | } | ||||
| static void do_hex_rna_cb(bContext *UNUSED(C), void *bt1, void *hexcl) | static void do_hex_rna_cb(bContext *UNUSED(C), void *bt1, void *hexcl) | ||||
| { | { | ||||
| uiBut *but = (uiBut *)bt1; | uiBut *but = (uiBut *)bt1; | ||||
| uiPopupBlockHandle *popup = but->block->handle; | uiPopupBlockHandle *popup = but->block->handle; | ||||
| char *hexcol = (char *)hexcl; | char *hexcol = (char *)hexcl; | ||||
| float rgb[3]; | float rgb[3]; | ||||
| hex_to_rgb(hexcol, rgb, rgb + 1, rgb + 2); | hex_to_rgb(hexcol, rgb, rgb + 1, rgb + 2); | ||||
| /* Hex code is assumed to be in sRGB space (coming from other applications, web, etc) */ | /* Hex code is assumed to be in sRGB space (coming from other applications, web, etc) */ | ||||
| if (but->block->color_profile) { | if (but->block->color_profile) { | ||||
| /* so we need to linearise it for Blender */ | /* so we need to linearise it for Blender */ | ||||
| ui_block_to_scene_linear_v3(but->block, rgb); | ui_block_to_scene_linear_v3(but->block, rgb); | ||||
| } | } | ||||
| ui_update_block_buts_rgb(but->block, rgb); | ui_update_block_buts_rgb(but->block, rgb, false); | ||||
| if (popup) | if (popup) | ||||
| popup->menuretval = UI_RETURN_UPDATE; | popup->menuretval = UI_RETURN_UPDATE; | ||||
| } | } | ||||
| static void close_popup_cb(bContext *UNUSED(C), void *bt1, void *UNUSED(arg)) | static void close_popup_cb(bContext *UNUSED(C), void *bt1, void *UNUSED(arg)) | ||||
| { | { | ||||
| uiBut *but = (uiBut *)bt1; | uiBut *but = (uiBut *)bt1; | ||||
| ▲ Show 20 Lines • Show All 214 Lines • ▼ Show 20 Lines | static int ui_picker_small_wheel_cb(const bContext *UNUSED(C), uiBlock *block, const wmEvent *event) | ||||
| if (add != 0.0f) { | if (add != 0.0f) { | ||||
| uiBut *but; | uiBut *but; | ||||
| for (but = block->buttons.first; but; but = but->next) { | for (but = block->buttons.first; but; but = but->next) { | ||||
| if (but->type == HSVCUBE && but->active == NULL) { | if (but->type == HSVCUBE && but->active == NULL) { | ||||
| uiPopupBlockHandle *popup = block->handle; | uiPopupBlockHandle *popup = block->handle; | ||||
| float rgb[3]; | float rgb[3]; | ||||
| float *hsv = ui_block_hsv_get(block); | float *hsv = ui_block_hsv_get(block); | ||||
| bool use_display_colorspace = ui_color_picker_use_display_colorspace(but); | |||||
| ui_get_but_vectorf(but, rgb); | ui_get_but_vectorf(but, rgb); | ||||
| rgb_to_hsv_compat_v(rgb, hsv); | if (use_display_colorspace) | ||||
| ui_block_to_display_space_v3(block, rgb); | |||||
| ui_rgb_to_color_picker_compat_v(rgb, hsv); | |||||
| hsv[2] = CLAMPIS(hsv[2] + add, 0.0f, 1.0f); | hsv[2] = CLAMPIS(hsv[2] + add, 0.0f, 1.0f); | ||||
| hsv_to_rgb_v(hsv, rgb); | ui_color_picker_to_rgb_v(hsv, rgb); | ||||
| if (use_display_colorspace) | |||||
| ui_block_to_scene_linear_v3(block, rgb); | |||||
| ui_set_but_vectorf(but, rgb); | ui_set_but_vectorf(but, rgb); | ||||
| ui_update_block_buts_rgb(block, rgb); | ui_update_block_buts_rgb(block, rgb, !use_display_colorspace); | ||||
| if (popup) | if (popup) | ||||
| popup->menuretval = UI_RETURN_UPDATE; | popup->menuretval = UI_RETURN_UPDATE; | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return 0; | return 0; | ||||
| ▲ Show 20 Lines • Show All 536 Lines • Show Last 20 Lines | |||||