diff options
author | Ton Roosendaal <ton@blender.org> | 2009-06-12 18:22:27 +0400 |
---|---|---|
committer | Ton Roosendaal <ton@blender.org> | 2009-06-12 18:22:27 +0400 |
commit | a62bec6667c7ae0df7d0003b566a466b1047d728 (patch) | |
tree | 40e2baf1b662083d27a0f2dc5ccee310594a4ee0 /source/blender/editors/interface/interface_regions.c | |
parent | 32b34f82fd782d45ee4b5389a1f961bc1f463631 (diff) |
2.5
Quick Color picker alternative!
- only a color circle + value slider
- exits immediate after use, or slight mouse move outside picker
- use scrollwheel to change HSV 'value'. Also works while picking.
- added nicer AA'ed cursor in picker
- All color swatches change 'value' on ALT+Wheel mouse-over
Old picker is still there, under SHIFT+click on swatch. Needs
evaluation... part of UI keymap? Per button type? Or divide
picker in left/right? Or just have all those old picker buttons
in another panel... I'm not to fond of this giant old popup.
Diffstat (limited to 'source/blender/editors/interface/interface_regions.c')
-rw-r--r-- | source/blender/editors/interface/interface_regions.c | 92 |
1 files changed, 87 insertions, 5 deletions
diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index 5d562805b51..89654f0ffab 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -1393,6 +1393,7 @@ static void update_picker_hex(uiBlock *block, float *rgb) } } +/* also used by small picker, be careful with name checks below... */ void ui_update_block_buts_hsv(uiBlock *block, float *hsv) { uiBut *bt; @@ -1406,7 +1407,7 @@ void ui_update_block_buts_hsv(uiBlock *block, float *hsv) update_picker_hex(block, rgb); for(bt= block->buttons.first; bt; bt= bt->next) { - if(bt->type==HSVCUBE) { + if(ELEM(bt->type, HSVCUBE, HSVCIRCLE)) { VECCOPY(bt->hsv, hsv); ui_set_but_hsv(bt); } @@ -1701,22 +1702,103 @@ void uiBlockPickerButtons(uiBlock *block, float *col, float *hsv, float *old, ch uiBlockEndAlign(block); } +/* bt1 is num but, hsv1 is pointer to original color in hsv space*/ +/* callback to handle changes */ +static void do_picker_small_cb(bContext *C, void *bt1, void *hsv1) +{ + uiBut *but1= (uiBut *)bt1; + uiPopupBlockHandle *popup= but1->block->handle; + float *hsv= (float *)hsv1; + float *fp= NULL; + + fp= (float *)but1->poin; + rgb_to_hsv(fp[0], fp[1], fp[2], hsv, hsv+1, hsv+2); + + ui_update_block_buts_hsv(but1->block, hsv); + + if(popup) + popup->menuretval= UI_RETURN_UPDATE; +} + + +/* only the color, a circle, slider */ +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, ""); + 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, ""); + uiButSetFunc(bt, do_picker_small_cb, bt, hsv); + +} + +static int ui_picker_small_wheel(const bContext *C, uiBlock *block, wmEvent *event) +{ + float add= 0.0f; + + if(event->type==WHEELUPMOUSE) + add= 0.05f; + else if(event->type==WHEELDOWNMOUSE) + add= -0.05f; + + if(add!=0.0f) { + uiBut *but; + + for(but= block->buttons.first; but; but= but->next) { + if(but->type==HSVCUBE && but->active==NULL) { + uiPopupBlockHandle *popup= block->handle; + 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); + 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); + + ui_set_but_vectorf(but, col); + + ui_update_block_buts_hsv(block, but->hsv); + if(popup) + popup->menuretval= UI_RETURN_UPDATE; + + return 1; + } + } + } + return 0; +} + uiBlock *ui_block_func_COL(bContext *C, uiPopupBlockHandle *handle, void *arg_but) { + wmWindow *win= CTX_wm_window(C); // XXX temp, needs to become keymap to detect type? uiBut *but= arg_but; uiBlock *block; static float hsvcol[3], oldcol[3]; static char hexcol[128]; block= uiBeginBlock(C, handle->region, "colorpicker", UI_EMBOSS); - block->flag= UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_KEEP_OPEN; VECCOPY(handle->retvec, but->editvec); - uiBlockPickerButtons(block, handle->retvec, hsvcol, oldcol, hexcol, 'p', 0); - + if(win->eventstate->shift) { + uiBlockPickerButtons(block, handle->retvec, hsvcol, oldcol, hexcol, 'p', 0); + block->flag= UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_KEEP_OPEN; + uiBoundsBlock(block, 3); + } + else { + uiBlockPickerSmall(block, handle->retvec, hsvcol, oldcol, hexcol, 'p', 0); + block->flag= UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1; + uiBoundsBlock(block, 10); + + block->block_event_func= ui_picker_small_wheel; + } /* and lets go */ block->direction= UI_TOP; - uiBoundsBlock(block, 3); return block; } |