Medium sized Color Picker; consisting of number sliders, row buttons to
select rgb/hsv/hex, HS circle and V slider. It opens persistant, like
old picker.

This one opens default, other two can be accessed with ALT or SHIFT click.

On todo;
- eyedropper tool back
- method for click-drag to make mini picker appear

Note for UI coders (brecht :), added a UI_HIDDEN flag in buttons, to
support switching buttons in menus. Hidden buttons are not activated nor
drawn.
This commit is contained in:
Ton Roosendaal 2009-06-24 13:44:19 +00:00
parent 16f32ec4ed
commit 9abce5dfba
4 changed files with 123 additions and 10 deletions

View File

@ -671,7 +671,8 @@ void uiDrawBlock(const bContext *C, uiBlock *block)
/* widgets */
for(but= block->buttons.first; but; but= but->next) {
ui_but_to_pixelrect(&rect, ar, block, but);
ui_draw_but(C, ar, &style, but, &rect);
if(!(but->flag & UI_HIDDEN))
ui_draw_but(C, ar, &style, but, &rect);
}
/* restore matrix */

View File

@ -404,7 +404,15 @@ static void ui_apply_but_TOG(bContext *C, uiBlock *block, uiBut *but, uiHandleBu
static void ui_apply_but_ROW(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data)
{
uiBut *bt;
ui_set_but_val(but, but->hardmax);
/* states of other row buttons */
for(bt= block->buttons.first; bt; bt= bt->next)
if(bt!=but && bt->poin==but->poin && bt->type==ROW)
ui_check_but(bt);
ui_apply_but_func(C, but);
data->retval= but->retval;
@ -3232,7 +3240,8 @@ static uiBut *ui_but_find_mouse_over(ARegion *ar, int x, int y)
for(but=block->buttons.first; but; but= but->next) {
if(ELEM3(but->type, LABEL, ROUNDBOX, SEPR))
continue;
if(but->flag & UI_HIDDEN)
continue;
if(ui_but_contains_pt(but, mx, my))
/* give precedence to already activated buttons */
if(!butover || (!butover->active && but->active))

View File

@ -98,7 +98,7 @@ typedef enum {
#define UI_ACTIVE 4
#define UI_HAS_ICON 8
#define UI_TEXTINPUT 16
#define UI_HIDDEN 32
/* warn: rest of uiBut->flag in UI_interface.h */
/* internal panel drawing defines */

View File

@ -1720,24 +1720,118 @@ static void do_picker_small_cb(bContext *C, void *bt1, void *hsv1)
popup->menuretval= UI_RETURN_UPDATE;
}
/* picker sizes S hsize, F full size, D spacer, B button/pallette height */
#define SPICK1 150.0
#define DPICK1 6.0
/* only the color, a circle, slider */
void uiBlockPickerSmall(uiBlock *block, float *col, float *hsv, float *old, char *hexcol, char mode, short retval)
/* only the color, a HS circle and V slider */
static void uiBlockPickerSmall(uiBlock *block, float *col, float *hsv, float *old, char *hexcol, char mode, short retval)
{
uiBut *bt;
VECCOPY(old, col); // old color stored there, for palette_cb to work
/* HS circle */
bt= uiDefButF(block, HSVCIRCLE, retval, "", 0, 0,SPICK,SPICK, col, 0.0, 0.0, 0, 0, "");
bt= uiDefButF(block, HSVCIRCLE, retval, "", 0, 0,SPICK1,SPICK1, col, 0.0, 0.0, 0, 0, "");
uiButSetFunc(bt, do_picker_small_cb, bt, hsv);
/* value */
bt= uiDefButF(block, HSVCUBE, retval, "", SPICK+DPICK,0,14,SPICK, col, 0.0, 0.0, 4, 0, "");
bt= uiDefButF(block, HSVCUBE, retval, "", SPICK1+DPICK1,0,14,SPICK1, col, 0.0, 0.0, 4, 0, "");
uiButSetFunc(bt, do_picker_small_cb, bt, hsv);
}
static void picker_new_hide_reveal(uiBlock *block, short colormode)
{
uiBut *bt;
/* tag buttons */
for(bt= block->buttons.first; bt; bt= bt->next) {
if(bt->type==NUMSLI || bt->type==TEX) {
if( bt->str[1]=='e') {
if(colormode==2) bt->flag &= ~UI_HIDDEN;
else bt->flag |= UI_HIDDEN;
}
else if( ELEM3(bt->str[0], 'R', 'G', 'B')) {
if(colormode==0) bt->flag &= ~UI_HIDDEN;
else bt->flag |= UI_HIDDEN;
}
else if( ELEM3(bt->str[0], 'H', 'S', 'V')) {
if(colormode==1) bt->flag &= ~UI_HIDDEN;
else bt->flag |= UI_HIDDEN;
}
}
}
}
static void do_picker_new_mode_cb(bContext *C, void *bt1, void *colv)
{
uiBut *bt= bt1;
short colormode= ui_get_but_val(bt);
picker_new_hide_reveal(bt->block, colormode);
}
/* a HS circle, V slider, rgb/hsv/hex sliders */
static void uiBlockPickerNew(uiBlock *block, float *col, float *hsv, float *old, char *hexcol, char mode, short retval)
{
static short colormode= 0; /* temp? 0=rgb, 1=hsv, 2=hex */
uiBut *bt;
int width;
VECCOPY(old, col); // old color stored there, for palette_cb to work
/* HS circle */
bt= uiDefButF(block, HSVCIRCLE, retval, "", 0, 0,SPICK1,SPICK1, col, 0.0, 0.0, 0, 0, "");
uiButSetFunc(bt, do_picker_small_cb, bt, hsv);
/* value */
bt= uiDefButF(block, HSVCUBE, retval, "", SPICK1+DPICK1,0,14,SPICK1, col, 0.0, 0.0, 4, 0, "");
uiButSetFunc(bt, do_picker_small_cb, bt, hsv);
/* mode */
width= (SPICK1+DPICK1+14)/3;
uiBlockBeginAlign(block);
bt= uiDefButS(block, ROW, retval, "RGB", 0, -30, width, 19, &colormode, 0.0, 0.0, 0, 0, "");
uiButSetFunc(bt, do_picker_new_mode_cb, bt, col);
bt= uiDefButS(block, ROW, retval, "HSV", width, -30, width, 19, &colormode, 0.0, 1.0, 0, 0, "");
uiButSetFunc(bt, do_picker_new_mode_cb, bt, hsv);
bt= uiDefButS(block, ROW, retval, "Hex", 2*width, -30, width, 19, &colormode, 0.0, 2.0, 0, 0, "");
uiButSetFunc(bt, do_picker_new_mode_cb, bt, hexcol);
uiBlockEndAlign(block);
/* sliders or hex */
width= (SPICK1+DPICK1+14);
rgb_to_hsv(col[0], col[1], col[2], hsv, hsv+1, hsv+2);
sprintf(hexcol, "%02X%02X%02X", (unsigned int)(col[0]*255.0), (unsigned int)(col[1]*255.0), (unsigned int)(col[2]*255.0));
uiBlockBeginAlign(block);
bt= uiDefButF(block, NUMSLI, 0, "R ", 0, -60, width, 19, col, 0.0, 1.0, 10, 3, "");
uiButSetFunc(bt, do_palette1_cb, bt, hsv);
bt= uiDefButF(block, NUMSLI, 0, "G ", 0, -80, width, 19, col+1, 0.0, 1.0, 10, 3, "");
uiButSetFunc(bt, do_palette1_cb, bt, hsv);
bt= uiDefButF(block, NUMSLI, 0, "B ", 0, -100, width, 19, col+2, 0.0, 1.0, 10, 3, "");
uiButSetFunc(bt, do_palette1_cb, bt, hsv);
uiBlockEndAlign(block);
uiBlockBeginAlign(block);
bt= uiDefButF(block, NUMSLI, 0, "H ", 0, -60, width, 19, hsv, 0.0, 1.0, 10, 3, "");
uiButSetFunc(bt, do_palette2_cb, bt, col);
bt= uiDefButF(block, NUMSLI, 0, "S ", 0, -80, width, 19, hsv+1, 0.0, 1.0, 10, 3, "");
uiButSetFunc(bt, do_palette2_cb, bt, col);
bt= uiDefButF(block, NUMSLI, 0, "V ", 0, -100, width, 19, hsv+2, 0.0, 1.0, 10, 3, "");
uiButSetFunc(bt, do_palette2_cb, bt, col);
uiBlockEndAlign(block);
bt= uiDefBut(block, TEX, 0, "Hex: ", 0, -80, width, 19, hexcol, 0, 8, 0, 0, "Hex triplet for color (#RRGGBB)");
uiButSetFunc(bt, do_palette_hex_cb, bt, hexcol);
picker_new_hide_reveal(block, colormode);
}
static int ui_picker_small_wheel(const bContext *C, uiBlock *block, wmEvent *event)
{
float add= 0.0f;
@ -1790,13 +1884,22 @@ uiBlock *ui_block_func_COL(bContext *C, uiPopupBlockHandle *handle, void *arg_bu
block->flag= UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_KEEP_OPEN;
uiBoundsBlock(block, 3);
}
else {
else if(win->eventstate->alt) {
uiBlockPickerSmall(block, handle->retvec, hsvcol, oldcol, hexcol, 'p', 0);
block->flag= UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1|UI_BLOCK_OUT_1;
uiBoundsBlock(block, 10);
block->block_event_func= ui_picker_small_wheel;
}
}
else {
uiBlockPickerNew(block, handle->retvec, hsvcol, oldcol, hexcol, 'p', 0);
block->flag= UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_KEEP_OPEN;
uiBoundsBlock(block, 10);
block->block_event_func= ui_picker_small_wheel;
}
/* and lets go */
block->direction= UI_TOP;