patch 21737 by Elia Sarti (vekoon)
authorDaniel Salazar <zanqdo@gmail.com>
Wed, 28 Apr 2010 09:29:17 +0000 (09:29 +0000)
committerDaniel Salazar <zanqdo@gmail.com>
Wed, 28 Apr 2010 09:29:17 +0000 (09:29 +0000)
Currently for ColorBands, when pressing the Add button, new elements are
set with a medium gray in a medium position which often is not desired
behaviour.

This patch when possible sets new elements as averaged values between
the current element and its preceding neighbour

source/blender/editors/interface/interface_templates.c

index ec4412d03b0c329184f77a4246420e26ca25dd35..a5eec8f3b7fdb96d9659bf3220f16ac6c5b55386 100644 (file)
@@ -39,6 +39,7 @@
 #include "BKE_global.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
+#include "BKE_texture.h"
 #include "BKE_utildefines.h"
 
 #include "ED_screen.h"
@@ -1438,6 +1439,33 @@ static void colorband_add_cb(bContext *C, void *cb_v, void *coba_v)
 {
        ColorBand *coba= coba_v;
 
+       if(coba->tot > 0) {
+               CBData *xnew, *x1, *x2;
+               float col[4];
+
+               xnew= &coba->data[coba->tot];
+
+               if(coba->tot > 1) {
+                       if(coba->cur > 0) {
+                               x1= &coba->data[coba->cur-1];
+                               x2= &coba->data[coba->cur];
+                       }
+                       else {
+                               x1= &coba->data[coba->cur];
+                               x2= &coba->data[coba->cur+1];
+                       }
+
+                       xnew->pos = x1->pos + ((x2->pos - x1->pos) / 2);
+               }
+
+               do_colorband(coba, xnew->pos, col);
+
+               xnew->r= col[0];
+               xnew->g= col[1];
+               xnew->b= col[2];
+               xnew->a= col[3];
+       }
+
        if(coba->tot < MAXCOLORBAND-1) coba->tot++;
        coba->cur= coba->tot-1;