Fix T46113: Color picker erratic outside 0-1 range

This commit is contained in:
Campbell Barton 2015-09-15 21:22:33 +10:00
parent 745510844b
commit 0c2be4d8e8
Notes: blender-bot 2023-02-14 08:40:26 +01:00
Referenced by issue #46113, Color picker doesn't work properly when added using Python script
4 changed files with 27 additions and 4 deletions

View File

@ -3123,6 +3123,20 @@ void ui_block_cm_to_scene_linear_v3(uiBlock *block, float pixel[3])
IMB_colormanagement_display_to_scene_linear_v3(pixel, display);
}
void ui_block_cm_to_display_space_range(uiBlock *block, float *min, float *max)
{
struct ColorManagedDisplay *display = ui_block_cm_display_get(block);
float pixel[3];
copy_v3_fl(pixel, *min);
IMB_colormanagement_scene_linear_to_display_v3(pixel, display);
*min = min_fff(UNPACK3(pixel));
copy_v3_fl(pixel, *max);
IMB_colormanagement_scene_linear_to_display_v3(pixel, display);
*max = max_fff(UNPACK3(pixel));
}
/**
* \brief ui_def_but is the function that draws many button types
*

View File

@ -5200,11 +5200,16 @@ static bool ui_numedit_but_HSVCUBE(
hsv[2] = y;
break;
case UI_GRAD_V_ALT:
{
/* vertical 'value' strip */
float min = but->softmin, max = but->softmax;
if (use_display_colorspace) {
ui_block_cm_to_display_space_range(but->block, &min, &max);
}
/* exception only for value strip - use the range set in but->min/max */
hsv[2] = y * (but->softmax - but->softmin) + but->softmin;
hsv[2] = y * (max - min) + min;
break;
}
default:
BLI_assert(0);
break;

View File

@ -498,6 +498,7 @@ extern void ui_block_align_calc(uiBlock *block);
extern struct ColorManagedDisplay *ui_block_cm_display_get(uiBlock *block);
void ui_block_cm_to_display_space_v3(uiBlock *block, float pixel[3]);
void ui_block_cm_to_scene_linear_v3(uiBlock *block, float pixel[3]);
void ui_block_cm_to_display_space_range(uiBlock *block, float *min, float *max);
/* interface_regions.c */

View File

@ -2587,8 +2587,11 @@ static void ui_draw_but_HSV_v(uiBut *but, const rcti *rect)
/* map v from property range to [0,1] */
if (but->a1 == UI_GRAD_V_ALT) {
float range = but->softmax - but->softmin;
v = (v - but->softmin) / range;
float min = but->softmin, max = but->softmax;
if (color_profile) {
ui_block_cm_to_display_space_range(but->block, &min, &max);
}
v = (v - min) / (max - min);
}
widget_init(&wtb);