[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15755] trunk/blender/source/blender: Grease Pencil - Backend work:

Joshua Leung aligorith at gmail.com
Fri Jul 25 09:11:08 CEST 2008


Revision: 15755
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15755
Author:   aligorith
Date:     2008-07-25 09:11:08 +0200 (Fri, 25 Jul 2008)

Log Message:
-----------
Grease Pencil - Backend work:

Just preparation work for an eraser tool (as well as the code of a failed attempt at an implementation).

Modified Paths:
--------------
    trunk/blender/source/blender/include/BDR_gpencil.h
    trunk/blender/source/blender/makesdna/DNA_gpencil_types.h
    trunk/blender/source/blender/src/drawgpencil.c
    trunk/blender/source/blender/src/editnode.c
    trunk/blender/source/blender/src/gpencil.c
    trunk/blender/source/blender/src/space.c

Modified: trunk/blender/source/blender/include/BDR_gpencil.h
===================================================================
--- trunk/blender/source/blender/include/BDR_gpencil.h	2008-07-25 05:39:48 UTC (rev 15754)
+++ trunk/blender/source/blender/include/BDR_gpencil.h	2008-07-25 07:11:08 UTC (rev 15755)
@@ -69,6 +69,6 @@
 void gpencil_delete_menu(void);
 
 //short gpencil_paint(short mousebutton);
-short gpencil_do_paint(struct ScrArea *sa);
+short gpencil_do_paint(struct ScrArea *sa, short mousebutton);
 
 #endif /*  BDR_GPENCIL_H */

Modified: trunk/blender/source/blender/makesdna/DNA_gpencil_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_gpencil_types.h	2008-07-25 05:39:48 UTC (rev 15754)
+++ trunk/blender/source/blender/makesdna/DNA_gpencil_types.h	2008-07-25 07:11:08 UTC (rev 15755)
@@ -59,6 +59,8 @@
 #define GP_STROKE_3DSPACE		(1<<0)
 	/* stroke is in 2d-space */
 #define GP_STROKE_2DSPACE		(1<<1)
+	/* stroke is an "eraser" stroke */
+#define GP_STROKE_ERASER		(1<<2)
 
 
 /* Grease-Pencil Annotations - 'Frame'

Modified: trunk/blender/source/blender/src/drawgpencil.c
===================================================================
--- trunk/blender/source/blender/src/drawgpencil.c	2008-07-25 05:39:48 UTC (rev 15754)
+++ trunk/blender/source/blender/src/drawgpencil.c	2008-07-25 07:11:08 UTC (rev 15755)
@@ -415,6 +415,45 @@
 	}
 }
 
+/* draw a set of strokes */
+static void gp_draw_strokes (bGPDframe *gpf, int winx, int winy, int dflag, short debug, 
+							 short lthick, float color[4])
+{
+	bGPDstroke *gps;
+	
+	/* set color first (may need to reset it again later too) */
+	glColor4f(color[0], color[1], color[2], color[3]);
+	
+	for (gps= gpf->strokes.first; gps; gps= gps->next) {	
+		/* handle 'eraser' strokes differently */
+		if (gps->flag & GP_STROKE_ERASER) {
+			// FIXME: this method is a failed experiment
+#if 0
+			/* draw stroke twice, first time with 'white' to set a mask to invert
+			 * contents of framebuffer, then second-time the same again but to restore
+			 * the contents
+			 */
+			glEnable(GL_COLOR_LOGIC_OP); 
+			glLogicOp(GL_XOR);
+			
+			glColor4f(1, 1, 1, 1); /* white */
+			
+			gp_draw_stroke(gps->points, gps->totpoints, lthick, dflag, gps->flag, 0, winx, winy);
+			gp_draw_stroke(gps->points, gps->totpoints, lthick, dflag, gps->flag, 0, winx, winy);
+			
+			glDisable(GL_COLOR_LOGIC_OP);
+			
+			/* reset color for drawing next stroke */
+			glColor4f(color[0], color[1], color[2], color[3]);
+#endif
+		}
+		else {
+			/* just draw the stroke once */
+			gp_draw_stroke(gps->points, gps->totpoints, lthick, dflag, gps->flag, debug, winx, winy);
+		}
+	}
+}
+
 /* draw grease-pencil datablock */
 static void gp_draw_data (bGPdata *gpd, int winx, int winy, int dflag)
 {
@@ -430,11 +469,10 @@
 	/* loop over layers, drawing them */
 	for (gpl= gpd->layers.first; gpl; gpl= gpl->next) {
 		bGPDframe *gpf;
-		bGPDstroke *gps;
 		
 		short debug = (gpl->flag & GP_LAYER_DRAWDEBUG) ? 1 : 0;
 		short lthick= gpl->thickness;
-		float color[4];
+		float color[4], tcolor[4];
 		
 		/* don't draw layer if hidden */
 		if (gpl->flag & GP_LAYER_HIDE) 
@@ -452,6 +490,7 @@
 		/* set color, stroke thickness, and point size */
 		glLineWidth(lthick);
 		QUATCOPY(color, gpl->color); // just for copying 4 array elements
+		QUATCOPY(tcolor, gpl->color); // additional copy of color (for ghosting)
 		glColor4f(color[0], color[1], color[2], color[3]);
 		glPointSize(gpl->thickness + 2);
 		
@@ -467,11 +506,8 @@
 					/* check if frame is drawable */
 					if ((gpf->framenum - gf->framenum) <= gpl->gstep) {
 						/* alpha decreases with distance from curframe index */
-						glColor4f(color[0], color[1], color[2], (color[3]-(i*0.7)));
-						
-						for (gps= gf->strokes.first; gps; gps= gps->next) {	
-							gp_draw_stroke(gps->points, gps->totpoints, lthick, dflag, gps->flag, debug, winx, winy);
-						}
+						tcolor[3] = color[3] - (i * 0.7);
+						gp_draw_strokes(gpf, winx, winy, dflag, debug, lthick, tcolor);
 					}
 					else 
 						break;
@@ -482,11 +518,8 @@
 					/* check if frame is drawable */
 					if ((gf->framenum - gpf->framenum) <= gpl->gstep) {
 						/* alpha decreases with distance from curframe index */
-						glColor4f(color[0], color[1], color[2], (color[3]-(i*0.7)));
-						
-						for (gps= gf->strokes.first; gps; gps= gps->next) {								
-							gp_draw_stroke(gps->points, gps->totpoints, lthick, dflag, gps->flag, debug, winx, winy);
-						}
+						tcolor[3] = color[3] - (i * 0.7);
+						gp_draw_strokes(gpf, winx, winy, dflag, debug, lthick, tcolor);
 					}
 					else 
 						break;
@@ -497,19 +530,14 @@
 			}
 			else {
 				/* draw the strokes for the ghost frames (at half of the alpha set by user) */
-				glColor4f(color[0], color[1], color[2], (color[3] / 7));
-				
 				if (gpf->prev) {
-					for (gps= gpf->prev->strokes.first; gps; gps= gps->next) {
-						gp_draw_stroke(gps->points, gps->totpoints, lthick, dflag, gps->flag, debug, winx, winy);
-					}
+					tcolor[3] = (color[3] / 7);
+					gp_draw_strokes(gpf, winx, winy, dflag, debug, lthick, tcolor);
 				}
 				
-				glColor4f(color[0], color[1], color[2], (color[3] / 4));
 				if (gpf->next) {
-					for (gps= gpf->next->strokes.first; gps; gps= gps->next) {	
-						gp_draw_stroke(gps->points, gps->totpoints, lthick, dflag, gps->flag, debug, winx, winy);
-					}
+					tcolor[3] = (color[3] / 4);
+					gp_draw_strokes(gpf, winx, winy, dflag, debug, lthick, tcolor);
 				}
 				
 				/* restore alpha */
@@ -518,9 +546,8 @@
 		}
 		
 		/* draw the strokes already in active frame */
-		for (gps= gpf->strokes.first; gps; gps= gps->next) {	
-			gp_draw_stroke(gps->points, gps->totpoints, lthick, dflag, gps->flag, debug, winx, winy);
-		}
+		tcolor[3]= color[3];
+		gp_draw_strokes(gpf, winx, winy, dflag, debug, lthick, tcolor);
 		
 		/* Check if may need to draw the active stroke cache, only if this layer is the active layer
 		 * that is being edited. (Stroke cache is currently stored in gp-data)

Modified: trunk/blender/source/blender/src/editnode.c
===================================================================
--- trunk/blender/source/blender/src/editnode.c	2008-07-25 05:39:48 UTC (rev 15754)
+++ trunk/blender/source/blender/src/editnode.c	2008-07-25 07:11:08 UTC (rev 15755)
@@ -2400,7 +2400,7 @@
 		
 		switch(event) {
 		case LEFTMOUSE:
-			if(gpencil_do_paint(sa)) {
+			if(gpencil_do_paint(sa, L_MOUSE)) {
 				return;
 			}
 			else if(fromlib) {
@@ -2421,7 +2421,10 @@
 			break;
 			
 		case RIGHTMOUSE: 
-			if(find_indicated_socket(snode, &actnode, &actsock, SOCK_IN)) {
+			if(gpencil_do_paint(sa, R_MOUSE)) {
+				return;
+			}
+			else if(find_indicated_socket(snode, &actnode, &actsock, SOCK_IN)) {
 				if(actsock->flag & SOCK_SEL) {
 					snode->edittree->selin= NULL;
 					actsock->flag&= ~SOCK_SEL;

Modified: trunk/blender/source/blender/src/gpencil.c
===================================================================
--- trunk/blender/source/blender/src/gpencil.c	2008-07-25 05:39:48 UTC (rev 15754)
+++ trunk/blender/source/blender/src/gpencil.c	2008-07-25 07:11:08 UTC (rev 15755)
@@ -972,7 +972,7 @@
 /* ---------- 'Paint' Tool ------------ */
 
 /* init new stroke */
-static void gp_paint_initstroke (tGPsdata *p)
+static void gp_paint_initstroke (tGPsdata *p, short mousebutton)
 {	
 	/* get active layer (or add a new one if non-existent) */
 	p->gpl= gpencil_layer_getactive(p->gpd);
@@ -995,8 +995,17 @@
 	}
 	else
 		p->gpf->flag |= GP_FRAME_PAINT;
+	
+	/* set 'eraser' for this stroke if using eraser or right-mouse in action */
+	if ( get_activedevice() == 2 || (mousebutton & R_MOUSE) ) {
+		p->gpd->sbuffer_sflag |= GP_STROKE_ERASER;
 		
-	/* check if points will need to be made in 3d-space */
+		// for now: eraser isn't ready for prime-time yet, so no painting available here yet
+		p->status= GP_STATUS_ERROR;
+		return;
+	}
+	
+	/* check if points will need to be made in view-aligned space */
 	if (p->gpd->flag & GP_DATA_VIEWALIGN) {
 		switch (p->sa->spacetype) {
 			case SPACE_VIEW3D:
@@ -1069,7 +1078,7 @@
 		gp_session_cleanup(&p);
 		return 0;
 	}
-	gp_paint_initstroke(&p);
+	gp_paint_initstroke(&p, mousebutton);
 	if (p.status == GP_STATUS_ERROR) {
 		gp_session_cleanup(&p);
 		return 0;
@@ -1158,10 +1167,9 @@
 /* All event (loops) handling checking if stroke drawing should be initiated
  * should call this function.
  */
-short gpencil_do_paint (ScrArea *sa)
+short gpencil_do_paint (ScrArea *sa, short mousebutton)
 {
 	bGPdata *gpd = gpencil_data_getactive(sa);
-	short mousebutton = L_MOUSE; /* for now, this is always on L_MOUSE*/
 	short retval= 0;
 	
 	/* check if possible to do painting */

Modified: trunk/blender/source/blender/src/space.c
===================================================================
--- trunk/blender/source/blender/src/space.c	2008-07-25 05:39:48 UTC (rev 15754)
+++ trunk/blender/source/blender/src/space.c	2008-07-25 07:11:08 UTC (rev 15755)
@@ -1205,9 +1205,12 @@
 					return; /* return if event was processed (swallowed) by handler(s) */
 			}
 			
-			if(gpencil_do_paint(sa)) return;
+			if(gpencil_do_paint(sa, L_MOUSE)) return;
 			if(BIF_do_manipulator(sa)) return;
 		}
+		else if(event==RIGHTMOUSE) {
+			if(gpencil_do_paint(sa, R_MOUSE)) return;
+		}
 		
 		/* swap mouse buttons based on user preference */
 		if (U.flag & USER_LMOUSESELECT) {
@@ -4825,9 +4828,12 @@
 		if( uiDoBlocks(&curarea->uiblocks, event, 1)!=UI_NOTHING ) event= 0;
 		
 		/* grease-pencil defaults to leftmouse */
-		if(event==LEFTMOUSE) {
-			if(gpencil_do_paint(sa)) return;
+		if (event == LEFTMOUSE) {
+			if(gpencil_do_paint(sa, L_MOUSE)) return;
 		}
+		else if (event == RIGHTMOUSE) {
+			if(gpencil_do_paint(sa, R_MOUSE)) return;
+		}
 		
 		/* swap mouse buttons based on user preference */
 		if (U.flag & USER_LMOUSESELECT) {





More information about the Bf-blender-cvs mailing list