bugfix [#23355] Square Color picker moving by itself and locking up

This commit is contained in:
2010-10-13 13:53:49 +00:00
parent 62f4d613d0
commit 843d8859a7
8 changed files with 107 additions and 69 deletions

View File

@@ -61,6 +61,7 @@ void cpack_to_rgb(unsigned int col, float *r, float *g, float *b);
void rgb_to_yuv(float r, float g, float b, float *ly, float *lu, float *lv);
void rgb_to_ycc(float r, float g, float b, float *ly, float *lcb, float *lcr, int colorspace);
void rgb_to_hsv(float r, float g, float b, float *lh, float *ls, float *lv);
void rgb_to_hsv_compat(float r, float g, float b, float *lh, float *ls, float *lv);
unsigned int rgb_to_cpack(float r, float g, float b);
unsigned int hsv_to_cpack(float h, float s, float v);

View File

@@ -232,6 +232,26 @@ void rgb_to_hsv(float r, float g, float b, float *lh, float *ls, float *lv)
*lv = v;
}
void rgb_to_hsv_compat(float r, float g, float b, float *lh, float *ls, float *lv)
{
float orig_h= *lh;
float orig_s= *ls;
rgb_to_hsv(r, g, b, lh, ls, lv);
if(*lv <= 0.0f) {
*lh= orig_h;
*ls= orig_s;
}
else if (*ls <= 0.0f) {
*lh= orig_h;
}
if(*lh==0.0f && orig_h >= 1.0f) {
*lh= 1.0f;
}
}
/*http://brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html */
void xyz_to_rgb(float xc, float yc, float zc, float *r, float *g, float *b, int colorspace)

View File

@@ -2136,11 +2136,6 @@ void ui_check_but(uiBut *but)
case HSVCUBE:
case HSVCIRCLE:
{
float rgb[3];
ui_get_but_vectorf(but, rgb);
rgb_to_hsv(rgb[0], rgb[1], rgb[2], but->hsv, but->hsv+1, but->hsv+2);
}
break;
default:
strncpy(but->drawstr, but->str, UI_MAX_DRAW_STR);

View File

@@ -2830,17 +2830,18 @@ static int ui_do_but_BLOCK(bContext *C, uiBut *but, uiHandleButtonData *data, wm
}
else if(but->type==COL) {
if( ELEM(event->type, WHEELDOWNMOUSE, WHEELUPMOUSE) && event->alt) {
float *hsv= ui_block_hsv_get(but->block);
float col[3];
ui_get_but_vectorf(but, col);
rgb_to_hsv(col[0], col[1], col[2], but->hsv, but->hsv+1, but->hsv+2);
rgb_to_hsv_compat(col[0], col[1], col[2], hsv, hsv+1, hsv+2);
if(event->type==WHEELDOWNMOUSE)
but->hsv[2]= CLAMPIS(but->hsv[2]-0.05f, 0.0f, 1.0f);
hsv[2]= CLAMPIS(hsv[2]-0.05f, 0.0f, 1.0f);
else
but->hsv[2]= CLAMPIS(but->hsv[2]+0.05f, 0.0f, 1.0f);
hsv[2]= CLAMPIS(hsv[2]+0.05f, 0.0f, 1.0f);
hsv_to_rgb(but->hsv[0], but->hsv[1], but->hsv[2], data->vec, data->vec+1, data->vec+2);
hsv_to_rgb(hsv[0], hsv[1], hsv[2], data->vec, data->vec+1, data->vec+2);
ui_set_but_vectorf(but, data->vec);
button_activate_state(C, but, BUTTON_STATE_EXIT);
@@ -2970,7 +2971,8 @@ static int ui_do_but_NORMAL(bContext *C, uiBlock *block, uiBut *but, uiHandleBut
static int ui_numedit_but_HSVCUBE(uiBut *but, uiHandleButtonData *data, int mx, int my)
{
float rgb[3], hsv[3];
float rgb[3];
float *hsv= ui_block_hsv_get(but->block);
float x, y;
int changed= 1;
int color_profile = but->block->color_profile;
@@ -2979,10 +2981,11 @@ static int ui_numedit_but_HSVCUBE(uiBut *but, uiHandleButtonData *data, int mx,
if (RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA)
color_profile = BLI_PR_NONE;
}
ui_get_but_vectorf(but, rgb);
rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
/* relative position within box */
x= ((float)mx-but->x1)/(but->x2-but->x1);
y= ((float)my-but->y1)/(but->y2-but->y1);
@@ -3059,21 +3062,22 @@ static int ui_do_but_HSVCUBE(bContext *C, uiBlock *block, uiBut *but, uiHandleBu
}
else if (event->type == ZEROKEY && event->val == KM_PRESS) {
if (but->a1==9){
float rgb[3], hsv[3], def_hsv[3];
float *def;
int len;
/* reset only value */
len= RNA_property_array_length(&but->rnapoin, but->rnaprop);
if (len >= 3) {
float rgb[3], def_hsv[3];
float *def;
float *hsv= ui_block_hsv_get(but->block);
def= MEM_callocN(sizeof(float)*len, "reset_defaults - float");
RNA_property_float_get_default_array(&but->rnapoin, but->rnaprop, def);
rgb_to_hsv(def[0], def[1], def[2], def_hsv, def_hsv+1, def_hsv+2);
ui_get_but_vectorf(but, rgb);
rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
hsv_to_rgb(hsv[0], hsv[1], def_hsv[2], rgb, rgb+1, rgb+2);
ui_set_but_vectorf(but, rgb);
@@ -3111,13 +3115,15 @@ static int ui_numedit_but_HSVCIRCLE(uiBut *but, uiHandleButtonData *data, int mx
{
rcti rect;
int changed= 1;
float rgb[3], hsv[3];
float rgb[3];
float hsv[3];
rect.xmin= but->x1; rect.xmax= but->x2;
rect.ymin= but->y1; rect.ymax= but->y2;
ui_get_but_vectorf(but, rgb);
rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
copy_v3_v3(hsv, ui_block_hsv_get(but->block));
rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
/* exception, when using color wheel in 'locked' value state:
* allow choosing a hue for black values, by giving a tiny increment */
@@ -3176,21 +3182,22 @@ static int ui_do_but_HSVCIRCLE(bContext *C, uiBlock *block, uiBut *but, uiHandle
return WM_UI_HANDLER_BREAK;
}
else if (event->type == ZEROKEY && event->val == KM_PRESS) {
float rgb[3], hsv[3], def_hsv[3];
float *def;
int len;
/* reset only saturation */
len= RNA_property_array_length(&but->rnapoin, but->rnaprop);
if (len >= 3) {
float rgb[3], def_hsv[3];
float *def;
float *hsv= ui_block_hsv_get(but->block);
def= MEM_callocN(sizeof(float)*len, "reset_defaults - float");
RNA_property_float_get_default_array(&but->rnapoin, but->rnaprop, def);
rgb_to_hsv(def[0], def[1], def[2], def_hsv, def_hsv+1, def_hsv+2);
ui_get_but_vectorf(but, rgb);
rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
hsv_to_rgb(hsv[0], def_hsv[1], hsv[2], rgb, rgb+1, rgb+2);
ui_set_but_vectorf(but, rgb);
@@ -3210,12 +3217,14 @@ static int ui_do_but_HSVCIRCLE(bContext *C, uiBlock *block, uiBut *but, uiHandle
}
/* XXX hardcoded keymap check.... */
else if(event->type == WHEELDOWNMOUSE) {
but->hsv[2]= CLAMPIS(but->hsv[2]-0.05f, 0.0f, 1.0f);
float *hsv= ui_block_hsv_get(but->block);
hsv[2]= CLAMPIS(hsv[2]-0.05f, 0.0f, 1.0f);
ui_set_but_hsv(but); // converts to rgb
ui_numedit_apply(C, block, but, data);
}
else if(event->type == WHEELUPMOUSE) {
but->hsv[2]= CLAMPIS(but->hsv[2]+0.05f, 0.0f, 1.0f);
float *hsv= ui_block_hsv_get(but->block);
hsv[2]= CLAMPIS(hsv[2]+0.05f, 0.0f, 1.0f);
ui_set_but_hsv(but); // converts to rgb
ui_numedit_apply(C, block, but, data);
}

View File

@@ -171,8 +171,9 @@ struct uiBut {
char *poin;
float hardmin, hardmax, softmin, softmax;
float a1, a2, hsv[3]; // hsv is temp memory for hsv buttons
float a1, a2;
float aspect;
char col[4];
uiButHandleFunc func;
void *func_arg1;
@@ -396,7 +397,7 @@ struct uiPopupBlockHandle {
int butretval;
int menuretval;
float retvalue;
float retvec[4];
float retvec[8];
};
uiBlock *ui_block_func_COL(struct bContext *C, uiPopupBlockHandle *handle, void *arg_but);
@@ -408,6 +409,8 @@ void ui_tooltip_free(struct bContext *C, struct ARegion *ar);
uiBut *ui_popup_menu_memory(uiBlock *block, uiBut *but);
float *ui_block_hsv_get(uiBlock *block);
/* searchbox for string button */
ARegion *ui_searchbox_create(struct bContext *C, struct ARegion *butregion, uiBut *but);
int ui_searchbox_inside(struct ARegion *ar, int x, int y);

View File

@@ -1571,27 +1571,22 @@ static void ui_warp_pointer(short x, short y)
void ui_set_but_hsv(uiBut *but)
{
float col[3];
float *hsv= ui_block_hsv_get(but->block);
hsv_to_rgb(but->hsv[0], but->hsv[1], but->hsv[2], col, col+1, col+2);
hsv_to_rgb(hsv[0], hsv[1], hsv[2], col, col+1, col+2);
ui_set_but_vectorf(but, col);
}
/* also used by small picker, be careful with name checks below... */
void ui_update_block_buts_rgb(uiBlock *block, float *rgb, float *rhsv)
void ui_update_block_buts_rgb(uiBlock *block, float *rgb)
{
uiBut *bt;
float hsv[3];
float *hsv= ui_block_hsv_get(block);
/* this is to keep the H and S value when V is equal to zero
* and we are working in HSV mode, of course!
*/
if (rhsv) {
hsv[0]= rhsv[0];
hsv[1]= rhsv[1];
hsv[2]= rhsv[2];
}
else
rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
// this updates button strings, is hackish... but button pointers are on stack of caller function
for(bt= block->buttons.first; bt; bt= bt->next) {
@@ -1657,23 +1652,23 @@ static void do_picker_rna_cb(bContext *C, void *bt1, void *unused)
if (prop) {
RNA_property_float_get_array(&ptr, prop, rgb);
ui_update_block_buts_rgb(but->block, rgb, NULL);
ui_update_block_buts_rgb(but->block, rgb);
}
if(popup)
popup->menuretval= UI_RETURN_UPDATE;
}
static void do_hsv_rna_cb(bContext *C, void *bt1, void *hsv_arg)
static void do_hsv_rna_cb(bContext *C, void *bt1, void *arg_dummy)
{
uiBut *but= (uiBut *)bt1;
uiPopupBlockHandle *popup= but->block->handle;
float *hsv = (float *)hsv_arg;
float rgb[3];
float *hsv= ui_block_hsv_get(but->block);
hsv_to_rgb(hsv[0], hsv[1], hsv[2], rgb, rgb+1, rgb+2);
ui_update_block_buts_rgb(but->block, rgb, hsv);
ui_update_block_buts_rgb(but->block, rgb);
if(popup)
popup->menuretval= UI_RETURN_UPDATE;
@@ -1694,7 +1689,7 @@ static void do_hex_rna_cb(bContext *C, void *bt1, void *hexcl)
srgb_to_linearrgb_v3_v3(rgb, rgb);
}
ui_update_block_buts_rgb(but->block, rgb, NULL);
ui_update_block_buts_rgb(but->block, rgb);
if(popup)
popup->menuretval= UI_RETURN_UPDATE;
@@ -1740,7 +1735,7 @@ static void picker_new_hide_reveal(uiBlock *block, short colormode)
}
}
static void do_picker_new_mode_cb(bContext *C, void *bt1, void *colv)
static void do_picker_new_mode_cb(bContext *C, void *bt1, void *dummy)
{
uiBut *bt= bt1;
short colormode= ui_get_but_val(bt);
@@ -1794,11 +1789,13 @@ static void uiBlockPicker(uiBlock *block, float *rgb, PointerRNA *ptr, PropertyR
uiBut *bt;
int width, butwidth;
static char tip[50];
static float hsv[3];
static char hexcol[128];
float rgb_gamma[3];
float min, max, step, precision;
const char *propname = RNA_property_identifier(prop);
float *hsv= ui_block_hsv_get(block);
ui_block_hsv_get(block);
width= PICKER_TOTAL_W;
butwidth = width - UI_UNIT_X - 10;
@@ -1818,7 +1815,6 @@ static void uiBlockPicker(uiBlock *block, float *rgb, PointerRNA *ptr, PropertyR
RNA_property_float_ui_range(ptr, prop, &min, &max, &step, &precision);
RNA_property_float_get_array(ptr, prop, rgb);
rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
switch (U.color_picker_type) {
case USER_CP_CIRCLE:
@@ -1838,11 +1834,11 @@ static void uiBlockPicker(uiBlock *block, float *rgb, PointerRNA *ptr, PropertyR
/* mode */
uiBlockBeginAlign(block);
bt= uiDefButS(block, ROW, 0, "RGB", 0, -30, width/3, UI_UNIT_Y, &colormode, 0.0, 0.0, 0, 0, "");
uiButSetFunc(bt, do_picker_new_mode_cb, bt, rgb);
uiButSetFunc(bt, do_picker_new_mode_cb, bt, NULL);
bt= uiDefButS(block, ROW, 0, "HSV", width/3, -30, width/3, UI_UNIT_Y, &colormode, 0.0, 1.0, 0, 0, "");
uiButSetFunc(bt, do_picker_new_mode_cb, bt, hsv);
uiButSetFunc(bt, do_picker_new_mode_cb, bt, NULL);
bt= uiDefButS(block, ROW, 0, "Hex", 2*width/3, -30, width/3, UI_UNIT_Y, &colormode, 0.0, 2.0, 0, 0, "");
uiButSetFunc(bt, do_picker_new_mode_cb, bt, hexcol);
uiButSetFunc(bt, do_picker_new_mode_cb, bt, NULL);
uiBlockEndAlign(block);
bt= uiDefIconButO(block, BUT, "UI_OT_eyedropper", WM_OP_INVOKE_DEFAULT, ICON_EYEDROPPER, butwidth+10, -60, UI_UNIT_X, UI_UNIT_Y, NULL);
@@ -1878,14 +1874,14 @@ static void uiBlockPicker(uiBlock *block, float *rgb, PointerRNA *ptr, PropertyR
rgb[3]= 1.0f;
}
rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
sprintf(hexcol, "%02X%02X%02X", FTOCHAR(rgb_gamma[0]), FTOCHAR(rgb_gamma[1]), FTOCHAR(rgb_gamma[2]));
bt= uiDefBut(block, TEX, 0, "Hex: ", 0, -60, butwidth, UI_UNIT_Y, hexcol, 0, 8, 0, 0, "Hex triplet for color (#RRGGBB)");
uiButSetFunc(bt, do_hex_rna_cb, bt, hexcol);
uiDefBut(block, LABEL, 0, "(Gamma Corrected)", 0, -80, butwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
picker_new_hide_reveal(block, colormode);
}
@@ -1906,16 +1902,17 @@ static int ui_picker_small_wheel(const bContext *C, uiBlock *block, wmEvent *eve
if(but->type==HSVCUBE && but->active==NULL) {
uiPopupBlockHandle *popup= block->handle;
float col[3];
float *hsv= ui_block_hsv_get(block);
ui_get_but_vectorf(but, col);
rgb_to_hsv(col[0], col[1], col[2], but->hsv, but->hsv+1, but->hsv+2);
but->hsv[2]= CLAMPIS(but->hsv[2]+add, 0.0f, 1.0f);
hsv_to_rgb(but->hsv[0], but->hsv[1], but->hsv[2], col, col+1, col+2);
rgb_to_hsv_compat(col[0], col[1], col[2], hsv, hsv+1, hsv+2);
hsv[2]= CLAMPIS(hsv[2]+add, 0.0f, 1.0f);
hsv_to_rgb(hsv[0], hsv[1], hsv[2], col, col+1, col+2);
ui_set_but_vectorf(but, col);
ui_update_block_buts_rgb(block, col, NULL);
ui_update_block_buts_rgb(block, col);
if(popup)
popup->menuretval= UI_RETURN_UPDATE;
@@ -1942,8 +1939,11 @@ uiBlock *ui_block_func_COL(bContext *C, uiPopupBlockHandle *handle, void *arg_bu
uiBlockSetFlag(block, UI_BLOCK_MOVEMOUSE_QUIT);
VECCOPY(handle->retvec, but->editvec);
block->handle= handle; /* XXX, only for ui_block_hsv_get */
uiBlockPicker(block, handle->retvec, &but->rnapoin, but->rnaprop);
block->handle= NULL;
block->flag= UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_KEEP_OPEN;
uiBoundsBlock(block, 10);
@@ -2438,3 +2438,7 @@ void uiPupBlockClose(bContext *C, uiBlock *block)
}
}
float *ui_block_hsv_get(uiBlock *block)
{
return block->handle->retvec+4;
}

View File

@@ -2327,7 +2327,6 @@ void uiTemplateReportsBanner(uiLayout *layout, bContext *C)
uiBut *but;
uiStyle *style= U.uistyles.first;
int width;
float hsv[3];
/* if the report display has timed out, don't show */
if (!reports->reporttimer) return;
@@ -2338,8 +2337,6 @@ void uiTemplateReportsBanner(uiLayout *layout, bContext *C)
abs = uiLayoutAbsolute(layout, 0);
block= uiLayoutGetBlock(abs);
rgb_to_hsv(rti->col[0], rti->col[1], rti->col[2], hsv+0, hsv+1, hsv+2);
width = BLF_width(style->widget.uifont_id, report->message);
width = MIN2(rti->widthfac*width, width);
@@ -2348,11 +2345,16 @@ void uiTemplateReportsBanner(uiLayout *layout, bContext *C)
/* make a box around the report to make it stand out */
uiBlockBeginAlign(block);
but= uiDefBut(block, ROUNDBOX, 0, "", 0, 0, UI_UNIT_X+10, UI_UNIT_Y, NULL, 0.0f, 0.0f, 0, 0, "");
copy_v3_v3(but->hsv, hsv); /* set the report's bg colour in but->hsv - ROUNDBOX feature */
/* set the report's bg colour in but->col - ROUNDBOX feature */
but->col[0]= FTOCHAR(rti->col[0]);
but->col[1]= FTOCHAR(rti->col[1]);
but->col[2]= FTOCHAR(rti->col[2]);
but->col[3]= 255;
but= uiDefBut(block, ROUNDBOX, 0, "", UI_UNIT_X+10, 0, UI_UNIT_X+width, UI_UNIT_Y, NULL, 0.0f, 0.0f, 0, 0, "");
but->hsv[0] = but->hsv[1] = 0.0; /* set a greyscale bg colour in but->hsv - ROUNDBOX feature */
but->hsv[2] = rti->greyscale;
but->col[0]= but->col[1]= but->col[2]= FTOCHAR(rti->greyscale);
but->col[3]= 255;
uiBlockEndAlign(block);

View File

@@ -1646,7 +1646,7 @@ void ui_draw_but_HSVCIRCLE(uiBut *but, uiWidgetColors *wcol, rcti *rect)
/* gouraud triangle fan */
float radstep, ang= 0.0f;
float centx, centy, radius;
float rgb[3], hsv[3], hsvo[3], col[3], colcent[3];
float rgb[3], hsvo[3], hsv[3], col[3], colcent[3];
int a, tot= 32;
int color_profile = but->block->color_profile;
@@ -1664,7 +1664,8 @@ void ui_draw_but_HSVCIRCLE(uiBut *but, uiWidgetColors *wcol, rcti *rect)
/* color */
ui_get_but_vectorf(but, rgb);
rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
copy_v3_v3(hsv, ui_block_hsv_get(but->block));
rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
copy_v3_v3(hsvo, hsv);
/* exception: if 'lock' is set
@@ -1858,9 +1859,14 @@ static void ui_draw_but_HSVCUBE(uiBut *but, rcti *rect)
{
float rgb[3], h,s,v;
float x=0.0f, y=0.0f;
float *hsv= ui_block_hsv_get(but->block);
h= hsv[0];
s= hsv[1];
v= hsv[2];
ui_get_but_vectorf(but, rgb);
rgb_to_hsv(rgb[0], rgb[1], rgb[2], &h, &s, &v);
rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], &h, &s, &v);
ui_draw_gradient(rect, rgb, but->a1, 1.f);
@@ -2481,12 +2487,10 @@ static void widget_box(uiBut *but, uiWidgetColors *wcol, rcti *rect, int state,
VECCOPY(old_col, wcol->inner);
/* abuse but->hsv - if it's non-zero, use this colour as the box's background */
if ((but->hsv[0] != 0.0) || (but->hsv[1] != 0.0) || (but->hsv[2] != 0.0)) {
float rgb[3];
hsv_to_rgb(but->hsv[0], but->hsv[1], but->hsv[2], rgb+0, rgb+1, rgb+2);
wcol->inner[0] = rgb[0] * 255;
wcol->inner[1] = rgb[1] * 255;
wcol->inner[2] = rgb[2] * 255;
if (but->col[3]) {
wcol->inner[0] = but->col[0];
wcol->inner[1] = but->col[1];
wcol->inner[2] = but->col[2];
}
/* half rounded */