Node curves to maintain handle status after adding a control point
authorJuho Vepsalainen <bebraw@gmail.com>
Wed, 26 Dec 2007 17:04:21 +0000 (17:04 +0000)
committerJuho Vepsalainen <bebraw@gmail.com>
Wed, 26 Dec 2007 17:04:21 +0000 (17:04 +0000)
Node curves maintain handles status (normal, auto, vector) even after adding
a control point now. This makes the behavior the same as in case of removing a control
point. Previously the status of handles was reseted.

source/blender/blenkernel/intern/colortools.c

index 83b014cdd63cddef3d9f1e4a7fa5e13bee3097a2..e4336576e2a82ef020eccd5b3c0d9fd888184cb5 100644 (file)
@@ -167,18 +167,30 @@ void curvemap_remove(CurveMap *cuma, int flag)
 void curvemap_insert(CurveMap *cuma, float x, float y)
 {
        CurveMapPoint *cmp= MEM_callocN((cuma->totpoint+1)*sizeof(CurveMapPoint), "curve points");
-       int a;
-       
-       memcpy(cmp, cuma->curve, (cuma->totpoint)*sizeof(CurveMapPoint));
+       int a, b, foundloc= 0;
+               
+       /* insert fragments of the old one and the new point to the new curve */
+       cuma->totpoint++;
+       for(a=0, b=0; a<cuma->totpoint; a++) {
+               if((x < cuma->curve[a].x) && !foundloc) {
+                       cmp[a].x= x;
+                       cmp[a].y= y;
+                       cmp[a].flag= CUMA_SELECT;
+                       foundloc= 1;
+               }
+               else {
+                       cmp[a].x= cuma->curve[b].x;
+                       cmp[a].y= cuma->curve[b].y;
+                       cmp[a].flag= cuma->curve[b].flag;
+                       cmp[a].flag &= ~CUMA_SELECT; /* make sure old points don't remain selected */
+                       cmp[a].shorty= cuma->curve[b].shorty;
+                       b++;
+               }
+       }
+
+       /* free old curve and replace it with new one */
        MEM_freeN(cuma->curve);
        cuma->curve= cmp;
-       
-       cuma->curve[cuma->totpoint].x= x;
-       cuma->curve[cuma->totpoint].y= y;
-       cuma->curve[cuma->totpoint].flag = CUMA_SELECT;
-       for(a=0; a<cuma->totpoint; a++, cmp++)
-               cmp->flag= 0;
-       cuma->totpoint++;
 }
 
 void curvemap_reset(CurveMap *cuma, rctf *clipr)