diff options
author | Ton Roosendaal <ton@blender.org> | 2004-10-30 20:11:36 +0400 |
---|---|---|
committer | Ton Roosendaal <ton@blender.org> | 2004-10-30 20:11:36 +0400 |
commit | e1fb446ce741c462a763b26ffba5cf572fb5de06 (patch) | |
tree | 9c3088d2a72d809e4bacebc43ab5629cec2d570f /source | |
parent | f3a6e55c82e1abe714907882001accd736a339f1 (diff) |
Feat request intrr, he won a bet with me :)
Colorband sliders now activate automatic on a click closer than 12 pixels
away from it. No more clumsy 'act' button stuff.
BTW: Error in utildefines.h, ABS() was defined incorrect.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_utildefines.h | 2 | ||||
-rw-r--r-- | source/blender/src/buttons_shading.c | 95 |
2 files changed, 59 insertions, 38 deletions
diff --git a/source/blender/blenkernel/BKE_utildefines.h b/source/blender/blenkernel/BKE_utildefines.h index 44cef530f48..c32e767ab92 100644 --- a/source/blender/blenkernel/BKE_utildefines.h +++ b/source/blender/blenkernel/BKE_utildefines.h @@ -69,7 +69,7 @@ #define SWAP(type, a, b) { type sw_ap; sw_ap=(a); (a)=(b); (b)=sw_ap; } -#define ABS(a) ( (a)<0 ? (-a) : (a) ) +#define ABS(a) ( (a)<0 ? (-(a)) : (a) ) #define VECCOPY(v1,v2) {*(v1)= *(v2); *(v1+1)= *(v2+1); *(v1+2)= *(v2+2);} #define QUATCOPY(v1,v2) {*(v1)= *(v2); *(v1+1)= *(v2+1); *(v1+2)= *(v2+2); *(v1+3)= *(v2+3);} diff --git a/source/blender/src/buttons_shading.c b/source/blender/src/buttons_shading.c index b55a43f3820..cca7df488f4 100644 --- a/source/blender/src/buttons_shading.c +++ b/source/blender/src/buttons_shading.c @@ -371,11 +371,7 @@ static void drawcolorband_cb(void) static void do_colorbandbuts(ColorBand *coba, unsigned short event) { - uiBlock *block; - CBData *cbd; - float dx; int a; - short mvalo[2], mval[2]; if(coba==NULL) return; @@ -424,40 +420,63 @@ static void do_colorbandbuts(ColorBand *coba, unsigned short event) case B_DOCOLORBAND: - /* weak; find panel where colorband is */ - block= uiFindOpenPanelBlockName(&curarea->uiblocks, "Colors"); - if(block==NULL) block= uiFindOpenPanelBlockName(&curarea->uiblocks, "Ramps"); + break; + } +} + +/* callback for label button... the size of the button (300) still hardcoded! */ +static void do_colorband_cb(void *namev, void *arg2_unused) +{ + ColorBand *coba= namev; + CBData *cbd; + uiBlock *block; + float dx; + int a; + short mval[2], mvalo[2]; + + /* weak; find panel where colorband is */ + block= uiFindOpenPanelBlockName(&curarea->uiblocks, "Colors"); + if(block==NULL) block= uiFindOpenPanelBlockName(&curarea->uiblocks, "Ramps"); + + if(coba && block) { + int mindist= 12, xco; + uiGetMouse(mywinget(), mvalo); - if(block) { - cbd= coba->data + coba->cur; - uiGetMouse(mywinget(), mvalo); - - while(get_mbut() & L_MOUSE) { - uiGetMouse(mywinget(), mval); - if(mval[0]!=mvalo[0]) { - dx= mval[0]-mvalo[0]; - dx/= 345.0; - cbd->pos+= dx; - CLAMP(cbd->pos, 0.0, 1.0); - - glDrawBuffer(GL_FRONT); - uiPanelPush(block); - drawcolorband_cb(); - uiPanelPop(block); - glDrawBuffer(GL_BACK); - - do_colorbandbuts(coba, B_CALCCBAND2); - cbd= coba->data + coba->cur; /* because qsort */ - - mvalo[0]= mval[0]; - } - BIF_wait_for_statechange(); + /* first, activate new key when mouse is close */ + for(a=0, cbd= coba->data; a<coba->tot; a++, cbd++) { + xco= 12 + (cbd->pos*300.0); + xco= ABS(xco-mvalo[0]); + if(a==coba->cur) xco+= 5; // selected one disadvantage + if(xco<mindist) { + coba->cur= a; + mindist= xco; } - allqueue(REDRAWBUTSSHADING, 0); - BIF_all_preview_changed(); - shade_buttons_change_3d(); } - break; + + cbd= coba->data + coba->cur; + + while(get_mbut() & L_MOUSE) { + uiGetMouse(mywinget(), mval); + if(mval[0]!=mvalo[0]) { + dx= mval[0]-mvalo[0]; + dx/= 300.0; + cbd->pos+= dx; + CLAMP(cbd->pos, 0.0, 1.0); + + glDrawBuffer(GL_FRONT); + drawcolorband_cb(); + glDrawBuffer(GL_BACK); + + do_colorbandbuts(coba, B_CALCCBAND2); + cbd= coba->data + coba->cur; /* because qsort */ + + mvalo[0]= mval[0]; + } + BIF_wait_for_statechange(); + } + allqueue(REDRAWBUTSSHADING, 0); + BIF_all_preview_changed(); + shade_buttons_change_3d(); } } @@ -1251,6 +1270,7 @@ static void texture_panel_image(Tex *tex) static void draw_colorband_buts(uiBlock *block, ColorBand *coba, int offs, int redraw) { CBData *cbd; + uiBut *bt; if(coba==NULL) return; @@ -1261,8 +1281,9 @@ static void draw_colorband_buts(uiBlock *block, ColorBand *coba, int offs, int r uiDefButS(block, ROW, B_TEXREDR_PRV, "L", 277,180+offs,16,20, &coba->ipotype, 5.0, 0.0, 0, 0, "Sets interpolation type Linear"); uiDefButS(block, ROW, B_TEXREDR_PRV, "S", 293,180+offs,17,20, &coba->ipotype, 5.0, 2.0, 0, 0, "Sets interpolation type B-Spline"); - uiDefBut(block, LABEL, B_DOCOLORBAND, "", 10,150+offs,300,30, 0, 0, 0, 0, 0, "Colorband"); /* only for event! */ - + bt=uiDefBut(block, LABEL, B_DOCOLORBAND, "", 10,150+offs,300,30, 0, 0, 0, 0, 0, "Colorband"); /* only for event! */ + uiButSetFunc(bt, do_colorband_cb, coba, NULL); + uiBlockSetDrawExtraFunc(block, drawcolorband_cb); cbd= coba->data + coba->cur; |