Colorband (ramp) buttons back (now only in Node editor)
This commit is contained in:
2009-05-20 15:20:24 +00:00
parent d6f71875bd
commit a06caced79
3 changed files with 89 additions and 1 deletions

View File

@@ -48,8 +48,10 @@ struct PointerRNA;
struct PropertyRNA;
struct ReportList;
struct rcti;
struct rctf;
struct uiStyle;
struct uiFontStyle;
struct ColorBand;
typedef struct uiBut uiBut;
typedef struct uiBlock uiBlock;
@@ -398,6 +400,7 @@ uiBut *uiDefIconTextBlockBut(uiBlock *block, uiBlockCreateFunc func, void *arg,
void uiDefKeyevtButS(uiBlock *block, int retval, char *str, short x1, short y1, short x2, short y2, short *spoin, char *tip);
void uiBlockPickerButtons(struct uiBlock *block, float *col, float *hsv, float *old, char *hexcol, char mode, short retval);
void uiBlockColorbandButtons(struct uiBlock *block, struct ColorBand *coba, struct rctf *butr, int event);
uiBut *uiDefAutoButR(uiBlock *block, struct PointerRNA *ptr, struct PropertyRNA *prop, int index, char *name, int icon, int x1, int y1, int x2, int y2);
void uiDefAutoButsRNA(const struct bContext *C, uiLayout *layout, struct PointerRNA *ptr);

View File

@@ -42,6 +42,7 @@
#include "BKE_context.h"
#include "BKE_report.h"
#include "BKE_screen.h"
#include "BKE_texture.h"
#include "BKE_utildefines.h"
#include "WM_api.h"
@@ -1270,6 +1271,90 @@ uiBlock *ui_block_func_COL(bContext *C, uiPopupBlockHandle *handle, void *arg_bu
return block;
}
/* ******************** Color band *************** */
static int vergcband(const void *a1, const void *a2)
{
const CBData *x1=a1, *x2=a2;
if( x1->pos > x2->pos ) return 1;
else if( x1->pos < x2->pos) return -1;
return 0;
}
static void colorband_pos_cb(bContext *C, void *coba_v, void *unused_v)
{
ColorBand *coba= coba_v;
int a;
if(coba->tot<2) return;
for(a=0; a<coba->tot; a++) coba->data[a].cur= a;
qsort(coba->data, coba->tot, sizeof(CBData), vergcband);
for(a=0; a<coba->tot; a++) {
if(coba->data[a].cur==coba->cur) {
/* if(coba->cur!=a) addqueue(curarea->win, REDRAW, 0); */ /* button cur */
coba->cur= a;
break;
}
}
}
static void colorband_add_cb(bContext *C, void *coba_v, void *unused_v)
{
ColorBand *coba= coba_v;
if(coba->tot < MAXCOLORBAND-1) coba->tot++;
coba->cur= coba->tot-1;
colorband_pos_cb(C, coba, NULL);
// BIF_undo_push("Add colorband");
}
static void colorband_del_cb(bContext *C, void *coba_v, void *unused_v)
{
ColorBand *coba= coba_v;
int a;
if(coba->tot<2) return;
for(a=coba->cur; a<coba->tot; a++) {
coba->data[a]= coba->data[a+1];
}
if(coba->cur) coba->cur--;
coba->tot--;
// BIF_undo_push("Delete colorband");
// BIF_preview_changed(ID_TE);
}
void uiBlockColorbandButtons(uiBlock *block, ColorBand *coba, rctf *butr, int event)
{
CBData *cbd;
uiBut *bt;
float unit= (butr->xmax-butr->xmin)/14.0f;
float xs= butr->xmin;
cbd= coba->data + coba->cur;
uiBlockBeginAlign(block);
uiDefButF(block, COL, event, "", xs,butr->ymin+20.0f,2.0f*unit,20, &(cbd->r), 0, 0, 0, 0, "");
uiDefButF(block, NUM, event, "A:", xs+2.0f*unit,butr->ymin+20.0f,4.0f*unit,20, &(cbd->a), 0.0f, 1.0f, 10, 2, "");
bt= uiDefBut(block, BUT, event, "Add", xs+6.0f*unit,butr->ymin+20.0f,2.0f*unit,20, NULL, 0, 0, 0, 0, "Adds a new color position to the colorband");
uiButSetFunc(bt, colorband_add_cb, coba, NULL);
bt= uiDefBut(block, BUT, event, "Del", xs+8.0f*unit, butr->ymin+20.0f, 2.0f*unit, 20, NULL, 0, 0, 0, 0, "Deletes the active position");
uiButSetFunc(bt, colorband_del_cb, coba, NULL);
uiDefButS(block, MENU, event, "Interpolation %t|Ease %x1|Cardinal %x3|Linear %x0|B-Spline %x2|Constant %x4",
xs + 10.0f*unit, butr->ymin+20.0f, unit*4.0f, 20, &coba->ipotype, 0.0, 0.0, 0, 0, "Sets interpolation type");
uiDefBut(block, BUT_COLORBAND, event, "", xs, butr->ymin, butr->xmax-butr->xmin, 20.0f, coba, 0, 0, 0, 0, "");
uiBlockEndAlign(block);
}
/* ******************** PUPmenu ****************** */
static int pupmenu_set= 0;

View File

@@ -291,7 +291,7 @@ static int node_buts_valtorgb(uiBlock *block, bNodeTree *ntree, bNode *node, rct
{
if(block) {
if(node->storage) {
; // XXX draw_colorband_buts_small(block, node->storage, butr, B_NODE_EXEC);
uiBlockColorbandButtons(block, node->storage, butr, B_NODE_EXEC);
}
}
return 40;