Grease Pencil - Stick to View for Sequencer:
authorJoshua Leung <aligorith@gmail.com>
Sun, 7 Sep 2008 11:36:52 +0000 (11:36 +0000)
committerJoshua Leung <aligorith@gmail.com>
Sun, 7 Sep 2008 11:36:52 +0000 (11:36 +0000)
The 'Stick to View' feature now works in the sequencer (image previews)

source/blender/include/BIF_drawseq.h
source/blender/src/drawgpencil.c
source/blender/src/drawseq.c
source/blender/src/gpencil.c

index 462075cdf3dfa71d7eb6841bfa1a33cf5497f243..85a6c7a9e2d62d7f75fd13496fc824dd3926008a 100644 (file)
@@ -33,6 +33,8 @@
 struct ScrArea;
 struct Sequence;
 
+#define SEQ_ZOOM_FAC(szoom) (szoom > 0)? (szoom) : (szoom == 0)? (1.0) : (-1.0/szoom)
+
 void drawprefetchseqspace(struct ScrArea *sa, void *spacedata);
 void drawseqspace(struct ScrArea *sa, void *spacedata);
 void set_special_seq_update(int val);
index d1c1e4a5ac68ad5d1586c8d51a42ff355fc390fe..6e8970522180f96ad0b994972e1436813783f8cd 100644 (file)
@@ -60,6 +60,7 @@
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
 #include "BIF_butspace.h"
+#include "BIF_drawseq.h"
 #include "BIF_graphics.h"
 #include "BIF_interface.h"
 #include "BIF_mywindow.h"
@@ -310,7 +311,7 @@ short draw_gpencil_panel (uiBlock *block, bGPdata *gpd, ScrArea *sa)
                /* 'view align' button (naming depends on context) */
                if (sa->spacetype == SPACE_VIEW3D)
                        uiDefButBitI(block, TOG, GP_DATA_VIEWALIGN, B_REDR, "Sketch in 3D", 170, 205, 150, 20, &gpd->flag, 0, 0, 0, 0, "New strokes are added in 3D-space");
-               else if (sa->spacetype != SPACE_SEQ) /* not available for sequencer yet */
+               else
                        uiDefButBitI(block, TOG, GP_DATA_VIEWALIGN, B_REDR, "Stick to View", 170, 205, 150, 20, &gpd->flag, 0, 0, 0, 0, "New strokes are added on 2d-canvas");
        }
        
@@ -411,8 +412,8 @@ static void gp_draw_stroke_point (bGPDspoint *points, short thickness, short sfl
                        co[1]= points->y;
                }
                else if (sflag & GP_STROKE_2DIMAGE) {
-                       co[0]= points->x;
-                       co[1]= points->y;
+                       co[0]= (points->x * winx) + offsx;
+                       co[1]= (points->y * winy) + offsy;
                }
                else {
                        co[0]= (points->x / 1000 * winx);
@@ -480,8 +481,12 @@ static void gp_draw_stroke_3d (bGPDspoint *points, int totpoints, short thicknes
 static void gp_draw_stroke (bGPDspoint *points, int totpoints, short thickness, short dflag, short sflag, 
                                                        short debug, int offsx, int offsy, int winx, int winy)
 {      
-       /* if thickness is less than GP_DRAWTHICKNESS_SPECIAL, 'smooth' opengl lines look better */
-       if ((thickness < GP_DRAWTHICKNESS_SPECIAL) || (dflag & GP_DRAWDATA_ONLYI2D)) {
+       /* if thickness is less than GP_DRAWTHICKNESS_SPECIAL, 'smooth' opengl lines look better
+        *      - but NOT if Image Editor 'image-based' stroke
+        */
+       if ( (thickness < GP_DRAWTHICKNESS_SPECIAL) || 
+                ((curarea->spacetype==SPACE_IMAGE) && (dflag & GP_DRAWDATA_ONLYV2D)) ) 
+       {
                bGPDspoint *pt;
                int i;
                
@@ -491,8 +496,8 @@ static void gp_draw_stroke (bGPDspoint *points, int totpoints, short thickness,
                                glVertex2f(pt->x, pt->y);
                        }
                        else if (sflag & GP_STROKE_2DIMAGE) {
-                               const float x= pt->x;
-                               const float y= pt->y;
+                               const float x= (pt->x * winx) + offsx;
+                               const float y= (pt->y * winy) + offsy;
                                
                                glVertex2f(x, y);
                        }
@@ -505,7 +510,10 @@ static void gp_draw_stroke (bGPDspoint *points, int totpoints, short thickness,
                }
                glEnd();
        }
-       else { /* tesselation code: currently only enabled with rt != 0 */
+       
+       /* tesselation code: currently only enabled with rt != 0 */
+       else 
+       { 
                bGPDspoint *pt1, *pt2;
                float pm[2];
                int i;
@@ -526,8 +534,10 @@ static void gp_draw_stroke (bGPDspoint *points, int totpoints, short thickness,
                                s1[0]= pt2->x;          s1[1]= pt2->y;
                        }
                        else if (sflag & GP_STROKE_2DIMAGE) {
-                               s0[0]= pt1->x;          s0[1]= pt1->y;
-                               s1[0]= pt2->x;          s1[1]= pt2->y;
+                               s0[0]= (pt1->x * winx) + offsx;                 
+                               s0[1]= (pt1->y * winy) + offsy;
+                               s1[0]= (pt2->x * winx) + offsx;         
+                               s1[1]= (pt2->y * winy) + offsy;
                        }
                        else {
                                s0[0]= (pt1->x / 1000 * winx);
@@ -672,9 +682,8 @@ static void gp_draw_stroke (bGPDspoint *points, int totpoints, short thickness,
                                glVertex2f(pt->x, pt->y);
                        }
                        else if (sflag & GP_STROKE_2DIMAGE) {
-                                       // fixme
-                               const float x= pt->x;
-                               const float y= pt->y;
+                               const float x= (pt->x * winx) + offsx;
+                               const float y= (pt->y * winy) + offsy;
                                
                                glVertex2f(x, y);
                        }
@@ -889,7 +898,7 @@ void draw_gpencil_2dimage (ScrArea *sa, ImBuf *ibuf)
 {
        bGPdata *gpd;
        int offsx, offsy, sizex, sizey;
-       int dflag = 0;
+       int dflag = GP_DRAWDATA_NOSTATUS;
        
        /* check that we have grease-pencil stuff to draw */
        if (ELEM(NULL, sa, ibuf)) return;
@@ -902,13 +911,39 @@ void draw_gpencil_2dimage (ScrArea *sa, ImBuf *ibuf)
                {
                        SpaceImage *sima= (SpaceImage *)sa->spacedata.first;
                        
-                       // fixme... are these settings still needed?
+                       /* just draw using standard scaling (settings here are currently ignored anyways) */
+                       // FIXME: the opengl poly-strokes don't draw at right thickness when done this way, so disabled
                        offsx= 0;
                        offsy= 0;
                        sizex= sa->winx;
                        sizey= sa->winy;
                        
                        myortho2(sima->v2d.cur.xmin, sima->v2d.cur.xmax, sima->v2d.cur.ymin, sima->v2d.cur.ymax);
+                       
+                       dflag |= GP_DRAWDATA_ONLYV2D;
+               }
+                       break;
+                       
+               case SPACE_SEQ: /* sequence */
+               {
+                       SpaceSeq *sseq= (SpaceSeq *)sa->spacedata.first;
+                       float zoom, zoomx, zoomy;
+                       
+                       /* calculate accessory values */
+                       zoom= SEQ_ZOOM_FAC(sseq->zoom);
+                       if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
+                               zoomx = zoom * ((float)G.scene->r.xasp / (float)G.scene->r.yasp);
+                               zoomy = zoom;
+                       } 
+                       else
+                               zoomx = zoomy = zoom;
+                       
+                       sizex= zoomx * ibuf->x;
+                       sizey= zoomy * ibuf->y;
+                       offsx= (sa->winx-sizex)/2 + sseq->xof;
+                       offsy= (sa->winy-sizey)/2 + sseq->yof;
+                       
+                       dflag |= GP_DRAWDATA_ONLYI2D;
                }
                        break;
                        
@@ -917,12 +952,13 @@ void draw_gpencil_2dimage (ScrArea *sa, ImBuf *ibuf)
                        offsy= 0;
                        sizex= sa->winx;
                        sizey= sa->winy;
+                       
+                       dflag |= GP_DRAWDATA_ONLYI2D;
                        break;
        }
        
        
        /* draw it! */
-       dflag = (GP_DRAWDATA_ONLYI2D|GP_DRAWDATA_NOSTATUS);
        gp_draw_data(gpd, offsx, offsy, sizex, sizey, dflag);
 }
 
index 71a777c90564d1899d8e5e5743b9cd949da25fd4..d7346a1ed21e2aa729e0766a660324f7d4ef9e89 100644 (file)
@@ -922,17 +922,11 @@ static void draw_image_seq(ScrArea *sa)
 
        if(ibuf->rect_float && ibuf->rect==NULL)
                IMB_rect_from_float(ibuf);
-
-       if (sseq->zoom > 0) {
-               zoom = sseq->zoom;
-       } else if (sseq->zoom == 0) {
-               zoom = 1.0;
-       } else {
-               zoom = -1.0/sseq->zoom;
-       }
-
+       
        /* needed for gla draw */
        glaDefine2DArea(&curarea->winrct);
+       
+       zoom= SEQ_ZOOM_FAC(sseq->zoom);
        if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
                zoomx = zoom * ((float)G.scene->r.xasp / (float)G.scene->r.yasp);
                zoomy = zoom;
@@ -976,7 +970,10 @@ static void draw_image_seq(ScrArea *sa)
                setlinestyle(0);
                glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
        }
-
+       
+       /* draw grease-pencil (image aligned) */
+       if (sseq->flag & SEQ_DRAW_GPENCIL)
+               draw_gpencil_2dimage(sa, ibuf);
 
        if (free_ibuf) {
                IMB_freeImBuf(ibuf);
index 9a2988e6e6d89744be3573c7d9849aa17c7f64e6..fa3ada89a3a1cade818ab9f0bb0c958cf96d1614 100644 (file)
@@ -67,6 +67,7 @@
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
 #include "BIF_butspace.h"
+#include "BIF_drawseq.h"
 #include "BIF_editarmature.h"
 #include "BIF_editview.h"
 #include "BIF_graphics.h"
@@ -694,7 +695,6 @@ static void gp_strokepoint_convertcoords (bGPDstroke *gps, bGPDspoint *pt, float
 {
        if (gps->flag & GP_STROKE_3DSPACE) {
                /* directly use 3d-coordinates */
-               // FIXME: maybe we need to counterotate this for object rotation?
                VecCopyf(p3d, &pt->x);
        }
        else {
@@ -1246,17 +1246,45 @@ static void gp_stroke_convertcoords (tGPsdata *p, short mval[], float out[])
                out[1]= y;
        }
        
-       /* 2d - on image 'canvas' (asume that p->v2d is set) */
-       else if ( (gpd->sbuffer_sflag & GP_STROKE_2DIMAGE) && 
-                         (p->v2d) && (p->ibuf) ) 
+       /* 2d - on image 'canvas' (assume that p->v2d is set) */
+       else if ( (gpd->sbuffer_sflag & GP_STROKE_2DIMAGE) && (p->v2d) ) 
        {
-               float x, y;
-               
-               /* convert to 'canvas' coordinates (not need to adjust to canvas) */
-               areamouseco_to_ipoco(p->v2d, mval, &x, &y);
-               
-               out[0]= x;
-               out[1]= y;
+               /* for now - space specific */
+               switch (p->sa->spacetype) {
+                       case SPACE_SEQ: /* sequencer */
+                       {
+                               SpaceSeq *sseq= (SpaceSeq *)p->sa->spacedata.first;
+                               int sizex, sizey, offsx, offsy, rectx, recty;
+                               float zoom, zoomx, zoomy;
+                               
+                               /* calculate zoom factor */
+                               zoom= SEQ_ZOOM_FAC(sseq->zoom);
+                               if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
+                                       zoomx = zoom * ((float)G.scene->r.xasp / (float)G.scene->r.yasp);
+                                       zoomy = zoom;
+                               } 
+                               else
+                                       zoomx = zoomy = zoom;
+                               
+                               /* calculate rect size */
+                               rectx= (G.scene->r.size*G.scene->r.xsch)/100;
+                               recty= (G.scene->r.size*G.scene->r.ysch)/100; 
+                               sizex= zoomx * rectx;
+                               sizey= zoomy * recty;
+                               offsx= (p->sa->winx-sizex)/2 + sseq->xof;
+                               offsy= (p->sa->winy-sizey)/2 + sseq->yof;
+                               
+                               /* calculate new points */
+                               out[0]= (float)(mval[0] - offsx) / (float)sizex;
+                               out[1]= (float)(mval[1] - offsy) / (float)sizey;
+                       }
+                               break;
+                               
+                       default: /* just use raw mouse coordinates - BAD! */
+                               out[0]= mval[0];
+                               out[1]= mval[1];
+                               break;
+               }               
        }
        
        /* 2d - relative to screen (viewport area) */
@@ -1487,6 +1515,11 @@ static void gp_stroke_eraser_dostroke (tGPsdata *p, short mval[], short mvalo[],
                        x0= xyval[0];
                        y0= xyval[1];
                }
+               else if (gps->flag & GP_STROKE_2DIMAGE) {                       
+                       ipoco_to_areaco_noclip(p->v2d, &gps->points->x, xyval);
+                       x0= xyval[0];
+                       y0= xyval[1];
+               }
                else {
                        x0= (gps->points->x / 1000 * p->sa->winx);
                        y0= (gps->points->y / 1000 * p->sa->winy);
@@ -1530,6 +1563,15 @@ static void gp_stroke_eraser_dostroke (tGPsdata *p, short mval[], short mvalo[],
                                x1= xyval[0];
                                y1= xyval[1];
                        }
+                       else if (gps->flag & GP_STROKE_2DIMAGE) {
+                               ipoco_to_areaco_noclip(p->v2d, &pt1->x, xyval);
+                               x0= xyval[0];
+                               y0= xyval[1];
+                               
+                               ipoco_to_areaco_noclip(p->v2d, &pt2->x, xyval);
+                               x1= xyval[0];
+                               y1= xyval[1];
+                       }
                        else {
                                x0= (pt1->x / 1000 * p->sa->winx);
                                y0= (pt1->y / 1000 * p->sa->winy);
@@ -1553,8 +1595,6 @@ static void gp_stroke_eraser_dostroke (tGPsdata *p, short mval[], short mvalo[],
        }
 }
 
-/* -------- */
-
 /* erase strokes which fall under the eraser strokes */
 static void gp_stroke_doeraser (tGPsdata *p)
 {
@@ -1626,14 +1666,14 @@ static void gp_paint_initstroke (tGPsdata *p, short paintmode)
                        case SPACE_SEQ:
                        {
                                /* for now, this is not applicable here... */
-                               //p->gpd->sbuffer_sflag |= GP_STROKE_2DIMAGE;
+                               p->gpd->sbuffer_sflag |= GP_STROKE_2DIMAGE;
                        }
                                break;
                        case SPACE_IMAGE:
                        {
                                /* check if any ibuf available */
                                if (p->ibuf)
-                                       p->gpd->sbuffer_sflag |= GP_STROKE_2DIMAGE;
+                                       p->gpd->sbuffer_sflag |= GP_STROKE_2DSPACE;
                        }
                                break;
                }