General tidying of Grease Pencil code...
authorJoshua Leung <aligorith@gmail.com>
Wed, 1 Oct 2008 08:23:08 +0000 (08:23 +0000)
committerJoshua Leung <aligorith@gmail.com>
Wed, 1 Oct 2008 08:23:08 +0000 (08:23 +0000)
source/blender/src/drawgpencil.c
source/blender/src/gpencil.c

index fb21d94f39a42305751103fb41abf8043176e5b1..b38bd6b2b63e6020cd5662c8274bf39d338bb164 100644 (file)
@@ -80,7 +80,7 @@
 #include "blendef.h"
 #include "butspace.h"
 
-#include "PIL_time.h"                  /* sleep                                */
+#include "PIL_time.h"
 #include "mydevice.h"
 
 /* ************************************************** */
@@ -447,7 +447,7 @@ static void gp_draw_stroke_point (bGPDspoint *points, short thickness, short sfl
                        
                        /* need to translate drawing position, but must reset after too! */
                        glTranslatef(co[0],  co[1], 0.); 
-                       gluDisk( qobj, 0.0,  thickness, 32, 1); 
+                       gluDisk(qobj, 0.0,  thickness, 32, 1); 
                        glTranslatef(-co[0],  -co[1], 0.);
                        
                        gluDeleteQuadric(qobj);
@@ -524,7 +524,9 @@ static void gp_draw_stroke (bGPDspoint *points, int totpoints, short thickness,
                glEnd();
        }
        
-       /* tesselation code: currently only enabled with rt != 0 */
+       /* tesselation code - draw stroke as series of connected quads with connection
+        * edges rotated to minimise shrinking artifacts, and rounded endcaps
+        */
        else 
        { 
                bGPDspoint *pt1, *pt2;
@@ -723,7 +725,7 @@ static void gp_draw_strokes (bGPDframe *gpf, int offsx, int offsy, int winx, int
        glColor4f(color[0], color[1], color[2], color[3]);
        
        for (gps= gpf->strokes.first; gps; gps= gps->next) {
-               /* check if stroke can be drawn */
+               /* check if stroke can be drawn - checks here generally fall into pairs */
                if ((dflag & GP_DRAWDATA_ONLY3D) && !(gps->flag & GP_STROKE_3DSPACE))
                        continue;
                if (!(dflag & GP_DRAWDATA_ONLY3D) && (gps->flag & GP_STROKE_3DSPACE))
@@ -876,13 +878,13 @@ static void gp_draw_data (bGPdata *gpd, int offsx, int offsy, int winx, int winy
                                BIF_ThemeColor(TH_TEXT_HI);
                        
                        if (actlay->actframe) {
-                               sprintf(printable, "GPencil: Layer ('%s'), Frame (%d) %s", 
+                               sprintf(printable, "GPencil: Layer ('%s'), Frame (%d)%s", 
                                        actlay->info, actlay->actframe->framenum,
-                                       ((gpd->flag & GP_DATA_EDITPAINT)?", Draw Mode On":"") );
+                                       ((gpd->flag & GP_DATA_EDITPAINT)?" , Draw Mode On":"") );
                        }
                        else {
-                               sprintf(printable, "GPencil: Layer ('%s'), Frame <None> %s", 
-                                       actlay->info, ((gpd->flag & GP_DATA_EDITPAINT)?", Draw Mode On":"") );
+                               sprintf(printable, "GPencil: Layer ('%s'), Frame <None>%s", 
+                                       actlay->info, ((gpd->flag & GP_DATA_EDITPAINT)?" , Draw Mode On":"") );
                        }
                }
                else {
index 9245d2f95f369b9c4bde944233b8ca67448bce3b..b9488d20200259f7dc0ea855a810b8c98a657cb9 100644 (file)
@@ -614,7 +614,6 @@ void gpencil_layer_delactive (bGPdata *gpd)
        /* free layer */        
        free_gpencil_frames(gpl);
        BLI_freelinkN(&gpd->layers, gpl);
-
 }
 
 /* ************************************************** */
@@ -1058,145 +1057,6 @@ static void gp_session_validatebuffer (tGPsdata *p)
        gpd->sbuffer_sflag= 0;
 }
 
-/* init new painting session */
-static void gp_session_initpaint (tGPsdata *p)
-{
-       /* clear previous data (note: is on stack) */
-       memset(p, 0, sizeof(tGPsdata));
-       
-       /* make sure the active view (at the starting time) is a 3d-view */
-       if (curarea == NULL) {
-               p->status= GP_STATUS_ERROR;
-               if (G.f & G_DEBUG) 
-                       printf("Error: No active view for painting \n");
-               return;
-       }
-       switch (curarea->spacetype) {
-               /* supported views first */
-               case SPACE_VIEW3D:
-               {
-                       View3D *v3d= curarea->spacedata.first;
-                       
-                       /* set current area */
-                       p->sa= curarea;
-                       
-                       /* check that gpencil data is allowed to be drawn */
-                       if ((v3d->flag2 & V3D_DISPGP)==0) {
-                               p->status= GP_STATUS_ERROR;
-                               if (G.f & G_DEBUG) 
-                                       printf("Error: In active view, Grease Pencil not shown \n");
-                               return;
-                       }
-               }
-                       break;
-               case SPACE_NODE:
-               {
-                       SpaceNode *snode= curarea->spacedata.first;
-                       
-                       /* set current area */
-                       p->sa= curarea;
-                       p->v2d= &snode->v2d;
-                       
-                       /* check that gpencil data is allowed to be drawn */
-                       if ((snode->flag & SNODE_DISPGP)==0) {
-                               p->status= GP_STATUS_ERROR;
-                               if (G.f & G_DEBUG) 
-                                       printf("Error: In active view, Grease Pencil not shown \n");
-                               return;
-                       }
-               }
-                       break;
-               case SPACE_SEQ:
-               {
-                       SpaceSeq *sseq= curarea->spacedata.first;
-                       
-                       /* set current area */
-                       p->sa= curarea;
-                       p->v2d= &sseq->v2d;
-                       
-                       /* check that gpencil data is allowed to be drawn */
-                       if (sseq->mainb == 0) {
-                               p->status= GP_STATUS_ERROR;
-                               if (G.f & G_DEBUG) 
-                                       printf("Error: In active view (sequencer), active mode doesn't support Grease Pencil \n");
-                               return;
-                       }
-                       if ((sseq->flag & SEQ_DRAW_GPENCIL)==0) {
-                               p->status= GP_STATUS_ERROR;
-                               if (G.f & G_DEBUG) 
-                                       printf("Error: In active view, Grease Pencil not shown \n");
-                               return;
-                       }
-               }
-                       break;  
-               case SPACE_IMAGE:
-               {
-                       SpaceImage *sima= curarea->spacedata.first;
-                       
-                       /* set the current area */
-                       p->sa= curarea;
-                       p->v2d= &sima->v2d;
-                       p->ibuf= BKE_image_get_ibuf(sima->image, &sima->iuser);
-               }
-                       break;
-               /* unsupported views */
-               default:
-               {
-                       p->status= GP_STATUS_ERROR;
-                       if (G.f & G_DEBUG) 
-                               printf("Error: Active view not appropriate for Grease Pencil drawing \n");
-                       return;
-               }
-                       break;
-       }
-       
-       /* get gp-data */
-       p->gpd= gpencil_data_getactive(p->sa);
-       if (p->gpd == NULL) {
-               short ok;
-               
-               p->gpd= gpencil_data_addnew();
-               ok= gpencil_data_setactive(p->sa, p->gpd);
-               
-               /* most of the time, the following check isn't needed */
-               if (ok == 0) {
-                       /* free gpencil data as it can't be used */
-                       free_gpencil_data(p->gpd);
-                       p->gpd= NULL;
-                       p->status= GP_STATUS_ERROR;
-                       if (G.f & G_DEBUG) 
-                               printf("Error: Could not assign newly created Grease Pencil data to active area \n");
-                       return;
-               }
-       }
-       
-       /* set edit flags */
-       G.f |= G_GREASEPENCIL;
-       
-       /* clear out buffer (stored in gp-data) in case something contaminated it */
-       gp_session_validatebuffer(p);
-}
-
-/* cleanup after a painting session */
-static void gp_session_cleanup (tGPsdata *p)
-{
-       bGPdata *gpd= p->gpd;
-       
-       /* error checking */
-       if (gpd == NULL)
-               return;
-       
-       /* free stroke buffer */
-       if (gpd->sbuffer) {
-               MEM_freeN(gpd->sbuffer);
-               gpd->sbuffer= NULL;
-       }
-       
-       /* clear flags */
-       gpd->sbuffer_size= 0;
-       gpd->sbuffer_sflag= 0;
-}
-
 /* check if the current mouse position is suitable for adding a new point */
 static short gp_stroke_filtermval (tGPsdata *p, short mval[2], short pmval[2])
 {
@@ -1615,6 +1475,145 @@ static void gp_stroke_doeraser (tGPsdata *p)
 
 /* ---------- 'Paint' Tool ------------ */
 
+/* init new painting session */
+static void gp_session_initpaint (tGPsdata *p)
+{
+       /* clear previous data (note: is on stack) */
+       memset(p, 0, sizeof(tGPsdata));
+       
+       /* make sure the active view (at the starting time) is a 3d-view */
+       if (curarea == NULL) {
+               p->status= GP_STATUS_ERROR;
+               if (G.f & G_DEBUG) 
+                       printf("Error: No active view for painting \n");
+               return;
+       }
+       switch (curarea->spacetype) {
+               /* supported views first */
+               case SPACE_VIEW3D:
+               {
+                       View3D *v3d= curarea->spacedata.first;
+                       
+                       /* set current area */
+                       p->sa= curarea;
+                       
+                       /* check that gpencil data is allowed to be drawn */
+                       if ((v3d->flag2 & V3D_DISPGP)==0) {
+                               p->status= GP_STATUS_ERROR;
+                               if (G.f & G_DEBUG) 
+                                       printf("Error: In active view, Grease Pencil not shown \n");
+                               return;
+                       }
+               }
+                       break;
+               case SPACE_NODE:
+               {
+                       SpaceNode *snode= curarea->spacedata.first;
+                       
+                       /* set current area */
+                       p->sa= curarea;
+                       p->v2d= &snode->v2d;
+                       
+                       /* check that gpencil data is allowed to be drawn */
+                       if ((snode->flag & SNODE_DISPGP)==0) {
+                               p->status= GP_STATUS_ERROR;
+                               if (G.f & G_DEBUG) 
+                                       printf("Error: In active view, Grease Pencil not shown \n");
+                               return;
+                       }
+               }
+                       break;
+               case SPACE_SEQ:
+               {
+                       SpaceSeq *sseq= curarea->spacedata.first;
+                       
+                       /* set current area */
+                       p->sa= curarea;
+                       p->v2d= &sseq->v2d;
+                       
+                       /* check that gpencil data is allowed to be drawn */
+                       if (sseq->mainb == 0) {
+                               p->status= GP_STATUS_ERROR;
+                               if (G.f & G_DEBUG) 
+                                       printf("Error: In active view (sequencer), active mode doesn't support Grease Pencil \n");
+                               return;
+                       }
+                       if ((sseq->flag & SEQ_DRAW_GPENCIL)==0) {
+                               p->status= GP_STATUS_ERROR;
+                               if (G.f & G_DEBUG) 
+                                       printf("Error: In active view, Grease Pencil not shown \n");
+                               return;
+                       }
+               }
+                       break;  
+               case SPACE_IMAGE:
+               {
+                       SpaceImage *sima= curarea->spacedata.first;
+                       
+                       /* set the current area */
+                       p->sa= curarea;
+                       p->v2d= &sima->v2d;
+                       p->ibuf= BKE_image_get_ibuf(sima->image, &sima->iuser);
+               }
+                       break;
+               /* unsupported views */
+               default:
+               {
+                       p->status= GP_STATUS_ERROR;
+                       if (G.f & G_DEBUG) 
+                               printf("Error: Active view not appropriate for Grease Pencil drawing \n");
+                       return;
+               }
+                       break;
+       }
+       
+       /* get gp-data */
+       p->gpd= gpencil_data_getactive(p->sa);
+       if (p->gpd == NULL) {
+               short ok;
+               
+               p->gpd= gpencil_data_addnew();
+               ok= gpencil_data_setactive(p->sa, p->gpd);
+               
+               /* most of the time, the following check isn't needed */
+               if (ok == 0) {
+                       /* free gpencil data as it can't be used */
+                       free_gpencil_data(p->gpd);
+                       p->gpd= NULL;
+                       p->status= GP_STATUS_ERROR;
+                       if (G.f & G_DEBUG) 
+                               printf("Error: Could not assign newly created Grease Pencil data to active area \n");
+                       return;
+               }
+       }
+       
+       /* set edit flags */
+       G.f |= G_GREASEPENCIL;
+       
+       /* clear out buffer (stored in gp-data) in case something contaminated it */
+       gp_session_validatebuffer(p);
+}
+
+/* cleanup after a painting session */
+static void gp_session_cleanup (tGPsdata *p)
+{
+       bGPdata *gpd= p->gpd;
+       
+       /* error checking */
+       if (gpd == NULL)
+               return;
+       
+       /* free stroke buffer */
+       if (gpd->sbuffer) {
+               MEM_freeN(gpd->sbuffer);
+               gpd->sbuffer= NULL;
+       }
+       
+       /* clear flags */
+       gpd->sbuffer_size= 0;
+       gpd->sbuffer_sflag= 0;
+}
+
 /* init new stroke */
 static void gp_paint_initstroke (tGPsdata *p, short paintmode)
 {