svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r20855:20928
[blender.git] / source / blender / blenkernel / intern / curve.c
index d52d91e40e91fac30de54ec05ddf9cb721873d9d..7dd868278f4c2f71716fcd8c7aec88d9aeb44a06 100644 (file)
 #include "DNA_scene_types.h"  
 #include "DNA_vfont_types.h"  
 
+#include "BKE_animsys.h"
 #include "BKE_anim.h"  
 #include "BKE_curve.h"  
 #include "BKE_displist.h"  
+#include "BKE_font.h" 
 #include "BKE_global.h" 
 #include "BKE_key.h"  
 #include "BKE_library.h"  
@@ -83,20 +85,33 @@ void unlink_curve(Curve *cu)
        cu->vfont= 0;
        if(cu->key) cu->key->id.us--;
        cu->key= 0;
-#if 0  // XXX old animation system
-       if(cu->ipo) cu->ipo->id.us--;
-       cu->ipo= 0;
-#endif // XXX old animation system
 }
 
+/* frees editcurve entirely */
+void BKE_free_editfont(Curve *cu)
+{
+       if(cu->editfont) {
+               EditFont *ef= cu->editfont;
+               
+               if(ef->oldstr) MEM_freeN(ef->oldstr);
+               if(ef->oldstrinfo) MEM_freeN(ef->oldstrinfo);
+               if(ef->textbuf) MEM_freeN(ef->textbuf);
+               if(ef->textbufinfo) MEM_freeN(ef->textbufinfo);
+               if(ef->copybuf) MEM_freeN(ef->copybuf);
+               if(ef->copybufinfo) MEM_freeN(ef->copybufinfo);
+               
+               MEM_freeN(ef);
+               cu->editfont= NULL;
+       }
+}
 
-/* niet curve zelf vrijgeven */
+/* don't free curve itself */
 void free_curve(Curve *cu)
 {
-
        freeNurblist(&cu->nurb);
        BLI_freelistN(&cu->bev);
        freedisplist(&cu->disp);
+       BKE_free_editfont(cu);
        
        if(cu->editnurb) {
                freeNurblist(cu->editnurb);
@@ -105,6 +120,7 @@ void free_curve(Curve *cu)
        }
 
        unlink_curve(cu);
+       BKE_free_animdata((ID *)cu);
        
        if(cu->mat) MEM_freeN(cu->mat);
        if(cu->str) MEM_freeN(cu->str);
@@ -133,6 +149,18 @@ Curve *add_curve(char *name, int type)
        
        cu->bb= unit_boundbox();
        
+       if(type==OB_FONT) {
+               cu->vfont= cu->vfontb= cu->vfonti= cu->vfontbi= get_builtin_font();
+               cu->vfont->id.us+=4;
+               cu->str= MEM_mallocN(12, "str");
+               strcpy(cu->str, "Text");
+               cu->pos= 4;
+               cu->strinfo= MEM_callocN(12*sizeof(CharInfo), "strinfo new");
+               cu->totbox= cu->actbox= 1;
+               cu->tb= MEM_callocN(MAXTEXTBOX*sizeof(TextBox), "textbox");
+               cu->tb[0].w = cu->tb[0].h = 0.0;
+       }
+       
        return cu;
 }
 
@@ -162,6 +190,8 @@ Curve *copy_curve(Curve *cu)
        cun->bev.first= cun->bev.last= 0;
        cun->path= 0;
 
+       cun->editnurb= NULL;
+
 #if 0  // XXX old animation system
        /* single user ipo too */
        if(cun->ipo) cun->ipo= copy_ipo(cun->ipo);
@@ -561,8 +591,8 @@ static void makecyclicknots(float *knots, short pnts, short order)
 }
 
 
-/* type - 0: uniform, 1: endpoints, 2: bezier, note, cyclic nurbs are always uniform */
-void makeknots(Nurb *nu, short uv, short type)
+
+void makeknots(Nurb *nu, short uv)
 {
        if( (nu->type & 7)==CU_NURBS ) {
                if(uv == 1) {
@@ -573,7 +603,7 @@ void makeknots(Nurb *nu, short uv, short type)
                                        calcknots(nu->knotsu, nu->pntsu, nu->orderu, 0);  /* cyclic should be uniform */
                                        makecyclicknots(nu->knotsu, nu->pntsu, nu->orderu);
                                } else {
-                                       calcknots(nu->knotsu, nu->pntsu, nu->orderu, type);
+                                       calcknots(nu->knotsu, nu->pntsu, nu->orderu, nu->flagu>>1);
                                }
                        }
                        else nu->knotsu= NULL;
@@ -586,7 +616,7 @@ void makeknots(Nurb *nu, short uv, short type)
                                        calcknots(nu->knotsv, nu->pntsv, nu->orderv, 0);  /* cyclic should be uniform */
                                        makecyclicknots(nu->knotsv, nu->pntsv, nu->orderv);
                                } else {
-                                       calcknots(nu->knotsv, nu->pntsv, nu->orderv, type);
+                                       calcknots(nu->knotsv, nu->pntsv, nu->orderv, nu->flagv>>1);
                                }
                        }
                        else nu->knotsv= NULL;
@@ -1542,8 +1572,8 @@ void makeBevelList(Object *ob)
        while(nu) {
                
                /* check if we will calculate tilt data */
-               do_tilt = ((nu->type & CU_2D) && (cu->flag & CU_3D)==0) ? 0 : 1;
-               do_radius = (do_tilt || cu->bevobj) ? 1 : 0; /* normal display uses the radius, better just to calculate them */
+               do_tilt = CU_DO_TILT(cu, nu);
+               do_radius = CU_DO_RADIUS(cu, nu); /* normal display uses the radius, better just to calculate them */
                
                /* check we are a single point? also check we are not a surface and that the orderu is sane,
                 * enforced in the UI but can go wrong possibly */
@@ -2340,7 +2370,7 @@ void sethandlesNurb(ListBase *editnurb, short code)
        if(code==1 || code==2) {
                nu= editnurb->first;
                while(nu) {
-                       if( (nu->type & 7)==1) {
+                       if( (nu->type & 7)==CU_BEZIER) {
                                bezt= nu->bezt;
                                a= nu->pntsu;
                                while(a--) {
@@ -2370,7 +2400,7 @@ void sethandlesNurb(ListBase *editnurb, short code)
                } else {
                        /* Toggle */
                        while(nu) {
-                               if( (nu->type & 7)==1) {
+                               if( (nu->type & 7)==CU_BEZIER) {
                                        bezt= nu->bezt;
                                        a= nu->pntsu;
                                        while(a--) {
@@ -2387,7 +2417,7 @@ void sethandlesNurb(ListBase *editnurb, short code)
                }
                nu= editnurb->first;
                while(nu) {
-                       if( (nu->type & 7)==1) {
+                       if( (nu->type & 7)==CU_BEZIER) {
                                bezt= nu->bezt;
                                a= nu->pntsu;
                                while(a--) {