changes to color wheel commit.

- use a flag rather then a2 for locking color.
- remove float from button added for color wheel size, use a2 instead.
- holding shift on the color wheel gives higher precission.
This commit is contained in:
Campbell Barton
2010-07-05 07:08:10 +00:00
parent 1c35121213
commit d9e9aa1e4d
5 changed files with 20 additions and 16 deletions

View File

@@ -142,7 +142,7 @@ typedef struct uiLayout uiLayout;
#define UI_BUT_ALIGN_DOWN (1<<17)
#define UI_BUT_DISABLED (1<<18)
#define UI_BUT_UNUSED (1<<19)
#define UI_BUT_COLOR_LOCK (1<<19)
#define UI_BUT_ANIMATED (1<<20)
#define UI_BUT_ANIMATED_KEY (1<<21)
#define UI_BUT_DRIVEN (1<<22)

View File

@@ -3047,7 +3047,7 @@ static int ui_do_but_HSVCUBE(bContext *C, uiBlock *block, uiBut *but, uiHandleBu
return WM_UI_HANDLER_CONTINUE;
}
static int ui_numedit_but_HSVCIRCLE(uiBut *but, uiHandleButtonData *data, int mx, int my)
static int ui_numedit_but_HSVCIRCLE(uiBut *but, uiHandleButtonData *data, int mx, int my, int shift)
{
rcti rect;
int changed= 1;
@@ -3061,23 +3061,24 @@ static int ui_numedit_but_HSVCIRCLE(uiBut *but, uiHandleButtonData *data, int mx
/* exception, when using color wheel in 'locked' value state:
* allow choosing a hue for black values, by giving a tiny increment */
if (but->a2 == 1) { // lock
if (but->flag & UI_BUT_COLOR_LOCK) { // lock
if (hsv[2] == 0.f) hsv[2] = 0.0001f;
}
if(U.uiflag & USER_CONTINUOUS_MOUSE) {
float fac= shift ? 0.02 : 0.1;
/* slow down the mouse, this is fairly picky */
mx = (data->dragstartx*0.9 + mx*0.1);
my = (data->dragstarty*0.9 + my*0.1);
mx = (data->dragstartx*(1.0f-fac) + mx*fac);
my = (data->dragstarty*(1.0f-fac) + my*fac);
}
ui_hsvcircle_vals_from_pos(hsv, hsv+1, &rect, (float)mx, (float)my);
hsv_to_rgb(hsv[0], hsv[1], hsv[2], rgb, rgb+1, rgb+2);
if(but->flag & UI_BUT_VEC_SIZE_LOCK) {
if((but->flag & UI_BUT_VEC_SIZE_LOCK) && (rgb[0] || rgb[1] || rgb[2])) {
normalize_v3(rgb);
mul_v3_fl(rgb, but->color_lum);
mul_v3_fl(rgb, but->a2);
}
ui_set_but_vectorf(but, rgb);
@@ -3106,7 +3107,7 @@ static int ui_do_but_HSVCIRCLE(bContext *C, uiBlock *block, uiBut *but, uiHandle
button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
/* also do drag the first time */
if(ui_numedit_but_HSVCIRCLE(but, data, mx, my))
if(ui_numedit_but_HSVCIRCLE(but, data, mx, my, event->shift))
ui_numedit_apply(C, block, but, data);
return WM_UI_HANDLER_BREAK;
@@ -3157,7 +3158,7 @@ static int ui_do_but_HSVCIRCLE(bContext *C, uiBlock *block, uiBut *but, uiHandle
}
else if(event->type == MOUSEMOVE) {
if(mx!=data->draglastx || my!=data->draglasty) {
if(ui_numedit_but_HSVCIRCLE(but, data, mx, my))
if(ui_numedit_but_HSVCIRCLE(but, data, mx, my, event->shift))
ui_numedit_apply(C, block, but, data);
}
}

View File

@@ -173,7 +173,6 @@ struct uiBut {
float hardmin, hardmax, softmin, softmax;
float a1, a2, hsv[3]; // hsv is temp memory for hsv buttons
float aspect;
float color_lum; /* used only for color buttons so far */
uiButHandleFunc func;
void *func_arg1;

View File

@@ -1971,13 +1971,17 @@ void uiTemplateColorWheel(uiLayout *layout, PointerRNA *ptr, char *propname, int
col = uiLayoutColumn(layout, 0);
row= uiLayoutRow(col, 1);
but= uiDefButR(block, HSVCIRCLE, 0, "", 0, 0, WHEEL_SIZE, WHEEL_SIZE, ptr, propname, -1, 0.0, 0.0, 0, lock, "");
but= uiDefButR(block, HSVCIRCLE, 0, "", 0, 0, WHEEL_SIZE, WHEEL_SIZE, ptr, propname, -1, 0.0, 0.0, 0, 0, "");
if(lock) {
but->flag |= UI_BUT_COLOR_LOCK;
}
if(lock_luminosity) {
float color[4]; /* incase of alpha */
but->flag |= UI_BUT_VEC_SIZE_LOCK;
RNA_property_float_get_array(ptr, prop, color);
but->color_lum= len_v3(color); /* abuse the soft-max though this is a kind of soft-max */
but->a2= len_v3(color);
}
uiItemS(row);

View File

@@ -1656,10 +1656,10 @@ void ui_draw_but_HSVCIRCLE(uiBut *but, uiWidgetColors *wcol, rcti *rect)
rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
copy_v3_v3(hsvo, hsv);
/* exception: if 'lock' is set (stored in but->a2),
/* exception: if 'lock' is set
* lock the value of the color wheel to 1.
* Useful for color correction tools where you're only interested in hue. */
if (but->a2) hsv[2] = 1.f;
if (but->flag & UI_BUT_COLOR_LOCK) hsv[2] = 1.f;
hsv_to_rgb(0.f, 0.f, hsv[2], colcent, colcent+1, colcent+2);