2.5
authorTon Roosendaal <ton@blender.org>
Wed, 20 May 2009 15:20:24 +0000 (15:20 +0000)
committerTon Roosendaal <ton@blender.org>
Wed, 20 May 2009 15:20:24 +0000 (15:20 +0000)
Colorband (ramp) buttons back (now only in Node editor)

source/blender/editors/include/UI_interface.h
source/blender/editors/interface/interface_regions.c
source/blender/editors/space_node/drawnode.c

index dba944ad9b752c1b285a1cd7814611dbb52bec1f..61fd6cb0b79fcab9cf9db18c8e2a27f6931bd4b1 100644 (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);
index 8474ee17ee07ef777852fe4f12a0b9c07316dee9..847c0a02ee4084ca3f69fb2913fea0e727870a25 100644 (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;
index cfbb03b986569082df211d69798d3808a0cb2193..50cf193f37b5535bd8e56c64023fe20d445c7cf1 100644 (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;