diff options
author | Joshua Leung <aligorith@gmail.com> | 2008-09-07 15:36:52 +0400 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2008-09-07 15:36:52 +0400 |
commit | e0fad0e6a1844f06f41866f4499aa9aedb5ec307 (patch) | |
tree | cd0b30243f374784915dacb203f36953e1b156f8 /source/blender | |
parent | 0bf03ef2f16870aa7a86c33accb4ba69de50c256 (diff) |
Grease Pencil - Stick to View for Sequencer:
The 'Stick to View' feature now works in the sequencer (image previews)
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/include/BIF_drawseq.h | 2 | ||||
-rw-r--r-- | source/blender/src/drawgpencil.c | 68 | ||||
-rw-r--r-- | source/blender/src/drawseq.c | 17 | ||||
-rw-r--r-- | source/blender/src/gpencil.c | 70 |
4 files changed, 116 insertions, 41 deletions
diff --git a/source/blender/include/BIF_drawseq.h b/source/blender/include/BIF_drawseq.h index 462075cdf3d..85a6c7a9e2d 100644 --- a/source/blender/include/BIF_drawseq.h +++ b/source/blender/include/BIF_drawseq.h @@ -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); diff --git a/source/blender/src/drawgpencil.c b/source/blender/src/drawgpencil.c index d1c1e4a5ac6..6e897052218 100644 --- a/source/blender/src/drawgpencil.c +++ b/source/blender/src/drawgpencil.c @@ -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); } diff --git a/source/blender/src/drawseq.c b/source/blender/src/drawseq.c index 71a777c9056..d7346a1ed21 100644 --- a/source/blender/src/drawseq.c +++ b/source/blender/src/drawseq.c @@ -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); diff --git a/source/blender/src/gpencil.c b/source/blender/src/gpencil.c index 9a2988e6e6d..fa3ada89a3a 100644 --- a/source/blender/src/gpencil.c +++ b/source/blender/src/gpencil.c @@ -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; } |