[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22882] branches/blender2.5/blender/source /blender/editors/gpencil: Grease Pencil: Drawing Improvements

Joshua Leung aligorith at gmail.com
Sun Aug 30 06:48:37 CEST 2009


Revision: 22882
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22882
Author:   aligorith
Date:     2009-08-30 06:48:34 +0200 (Sun, 30 Aug 2009)

Log Message:
-----------
Grease Pencil: Drawing Improvements 

* Smooth strokes can now be drawn again, with normal (i.e. reasonably speedy feedback again). 
Previously slow drawing was caused by a bad notifier being used - the full screen was redrawn each time instead of just the relevant region. Now, only the relevant region is redrawn while drawing, and a proper flush is done for the rest of the screen at the end.

* Made drawing straight lines a proper drawing 'mode' for Grease Pencil now. Use the Ctrl-D-LMB hotkey to draw straight lines in this way. The (buffer) line drawn now will accurately represent the final straight line instead of drawing the freehand path taken as before.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/editors/gpencil/gpencil_edit.c
    branches/blender2.5/blender/source/blender/editors/gpencil/gpencil_intern.h
    branches/blender2.5/blender/source/blender/editors/gpencil/gpencil_ops.c
    branches/blender2.5/blender/source/blender/editors/gpencil/gpencil_paint.c

Modified: branches/blender2.5/blender/source/blender/editors/gpencil/gpencil_edit.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/gpencil/gpencil_edit.c	2009-08-30 03:10:03 UTC (rev 22881)
+++ branches/blender2.5/blender/source/blender/editors/gpencil/gpencil_edit.c	2009-08-30 04:48:34 UTC (rev 22882)
@@ -169,7 +169,7 @@
 	}
 	
 	/* notifiers */
-	WM_event_add_notifier(C, NC_SCREEN|ND_GPENCIL|NA_EDITED, NULL); // XXX please work!
+	WM_event_add_notifier(C, NC_SCREEN|ND_GPENCIL|NA_EDITED, NULL); // XXX need a nicer one that will work	
 	
 	return OPERATOR_FINISHED;
 }
@@ -216,7 +216,7 @@
 	}
 	
 	/* notifiers */
-	WM_event_add_notifier(C, NC_SCREEN|ND_GPENCIL|NA_EDITED, NULL); // XXX please work!
+	WM_event_add_notifier(C, NC_SCREEN|ND_GPENCIL|NA_EDITED, NULL); // XXX need a nicer one that will work	
 	
 	return OPERATOR_FINISHED;
 }

Modified: branches/blender2.5/blender/source/blender/editors/gpencil/gpencil_intern.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/gpencil/gpencil_intern.h	2009-08-30 03:10:03 UTC (rev 22881)
+++ branches/blender2.5/blender/source/blender/editors/gpencil/gpencil_intern.h	2009-08-30 04:48:34 UTC (rev 22882)
@@ -40,6 +40,13 @@
 
 void GPENCIL_OT_draw(struct wmOperatorType *ot);
 
+/* Paint Modes for operator*/
+typedef enum eGPencil_PaintModes {
+	GP_PAINTMODE_DRAW = 0,
+	GP_PAINTMODE_ERASER,
+	GP_PAINTMODE_DRAW_STRAIGHT,
+} eGPencil_PaintModes;
+
 /* buttons editing --- */
 
 void GPENCIL_OT_data_add(struct wmOperatorType *ot);

Modified: branches/blender2.5/blender/source/blender/editors/gpencil/gpencil_ops.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/gpencil/gpencil_ops.c	2009-08-30 03:10:03 UTC (rev 22881)
+++ branches/blender2.5/blender/source/blender/editors/gpencil/gpencil_ops.c	2009-08-30 04:48:34 UTC (rev 22882)
@@ -56,9 +56,12 @@
 	/* Draw */
 		/* draw */
 	WM_keymap_add_item(keymap, "GPENCIL_OT_draw", LEFTMOUSE, KM_PRESS, 0, DKEY);
+		/* draw - straight lines */
+	kmi=WM_keymap_add_item(keymap, "GPENCIL_OT_draw", LEFTMOUSE, KM_PRESS, KM_CTRL, DKEY);
+		RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_DRAW_STRAIGHT);
 		/* erase */
 	kmi=WM_keymap_add_item(keymap, "GPENCIL_OT_draw", RIGHTMOUSE, KM_PRESS, 0, DKEY);
-		RNA_enum_set(kmi->ptr, "mode", 1); // XXX need to make the defines for this public (this is GP_PAINTMODE_ERASER)
+		RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_ERASER);
 }
 
 /* ****************************************** */

Modified: branches/blender2.5/blender/source/blender/editors/gpencil/gpencil_paint.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/gpencil/gpencil_paint.c	2009-08-30 03:10:03 UTC (rev 22881)
+++ branches/blender2.5/blender/source/blender/editors/gpencil/gpencil_paint.c	2009-08-30 04:48:34 UTC (rev 22882)
@@ -69,16 +69,6 @@
 #include "gpencil_intern.h"
 
 /* ******************************************* */
-/* Context Wrangling... */
-
-/* check if context is suitable for drawing */
-static int gpencil_draw_poll (bContext *C)
-{
-	// TODO: must check context for Grease Pencil data...
-	return 1;
-}
-
-/* ******************************************* */
 /* 'Globals' and Defines */
 
 /* Temporary 'Stroke' Operation data */
@@ -121,12 +111,6 @@
 	GP_STATUS_DONE			/* painting done */
 };
 
-/* values for tGPsdata->paintmode */
-enum {
-	GP_PAINTMODE_DRAW = 0,
-	GP_PAINTMODE_ERASER
-};
-
 /* Return flags for adding points to stroke buffer */
 enum {
 	GP_STROKEADD_INVALID	= -2,		/* error occurred - insufficient info to do so */
@@ -138,7 +122,6 @@
 /* Runtime flags */
 enum {
 	GP_PAINTFLAG_FIRSTRUN		= (1<<0),	/* operator just started */
-	GP_PAINTFLAG_STRAIGHTLINES	= (1<<1),	/* only take the endpoints of a stroke */
 };
 
 /* ------ */
@@ -152,17 +135,22 @@
 	/* minimum length of new segment before new point can be added */
 #define MIN_EUCLIDEAN_PX	(U.gp_euclideandist)
 
-/* macro to test if only converting endpoints - only for use when converting!  */	
-// XXX for now, don't test for editpaint too...
-//#define GP_BUFFER2STROKE_ENDPOINTS ((gpd->flag & GP_DATA_EDITPAINT) && (p->flags & GP_PAINTFLAG_STRAIGHTLINES))
-#define GP_BUFFER2STROKE_ENDPOINTS ((p->flags & GP_PAINTFLAG_STRAIGHTLINES))
-
 /* ------ */
 /* Forward defines for some functions... */
 
 static void gp_session_validatebuffer(tGPsdata *p);
 
 /* ******************************************* */
+/* Context Wrangling... */
+
+/* check if context is suitable for drawing */
+static int gpencil_draw_poll (bContext *C)
+{
+	/* check if current context can support GPencil data */
+	return (gpencil_data_get_pointers(C, NULL) != NULL);
+}
+
+/* ******************************************* */
 /* Calculations/Conversions */
 
 /* Stroke Editing ---------------------------- */
@@ -258,26 +246,68 @@
 	bGPdata *gpd= p->gpd;
 	tGPspoint *pt;
 	
-	/* check if still room in buffer */
-	if (gpd->sbuffer_size >= GP_STROKE_BUFFER_MAX)
-		return GP_STROKEADD_OVERFLOW;
+	/* check painting mode */
+	if (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT) {
+		/* straight lines only - i.e. only store start and end point in buffer */
+		if (gpd->sbuffer_size == 0) {
+			/* first point in buffer (start point) */
+			pt= (tGPspoint *)(gpd->sbuffer);
+			
+			/* store settings */
+			pt->x= mval[0];
+			pt->y= mval[1];
+			pt->pressure= pressure;
+			
+			/* increment buffer size */
+			gpd->sbuffer_size++;
+		}
+		else {
+			/* normally, we just reset the endpoint to the latest value 
+			 *	- assume that pointers for this are always valid...
+			 */
+			pt= ((tGPspoint *)(gpd->sbuffer) + 1);
+			
+			/* store settings */
+			pt->x= mval[0];
+			pt->y= mval[1];
+			pt->pressure= pressure;
+			
+			/* if this is just the second point we've added, increment the buffer size
+			 * so that it will be drawn properly...
+			 * otherwise, just leave it alone, otherwise we get problems
+			 */
+			if (gpd->sbuffer_size != 2)
+				gpd->sbuffer_size= 2;
+		}
+		
+		/* can keep carrying on this way :) */
+		return GP_STROKEADD_NORMAL;
+	}
+	else if (p->paintmode == GP_PAINTMODE_DRAW) { /* normal drawing */
+		/* check if still room in buffer */
+		if (gpd->sbuffer_size >= GP_STROKE_BUFFER_MAX)
+			return GP_STROKEADD_OVERFLOW;
+		
+		/* get pointer to destination point */
+		pt= ((tGPspoint *)(gpd->sbuffer) + gpd->sbuffer_size);
+		
+		/* store settings */
+		pt->x= mval[0];
+		pt->y= mval[1];
+		pt->pressure= pressure;
+		
+		/* increment counters */
+		gpd->sbuffer_size++;
+		
+		/* check if another operation can still occur */
+		if (gpd->sbuffer_size == GP_STROKE_BUFFER_MAX)
+			return GP_STROKEADD_FULL;
+		else
+			return GP_STROKEADD_NORMAL;
+	}
 	
-	/* get pointer to destination point */
-	pt= ((tGPspoint *)(gpd->sbuffer) + gpd->sbuffer_size);
-	
-	/* store settings */
-	pt->x= mval[0];
-	pt->y= mval[1];
-	pt->pressure= pressure;
-	
-	/* increment counters */
-	gpd->sbuffer_size++;
-	
-	/* check if another operation can still occur */
-	if (gpd->sbuffer_size == GP_STROKE_BUFFER_MAX)
-		return GP_STROKEADD_FULL;
-	else
-		return GP_STROKEADD_NORMAL;
+	/* just say it's normal for now, since we don't have another state... */
+	return GP_STROKEADD_NORMAL;
 }
 
 /* smooth a stroke (in buffer) before storing it */
@@ -287,7 +317,7 @@
 	int i=0, cmx=gpd->sbuffer_size;
 	
 	/* only smooth if smoothing is enabled, and we're not doing a straight line */
-	if (!(U.gp_settings & GP_PAINT_DOSMOOTH) || GP_BUFFER2STROKE_ENDPOINTS)
+	if (!(U.gp_settings & GP_PAINT_DOSMOOTH) || (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT))
 		return;
 	
 	/* don't try if less than 2 points in buffer */
@@ -320,7 +350,7 @@
 	short i, j;
 	
 	/* only simplify if simlification is enabled, and we're not doing a straight line */
-	if (!(U.gp_settings & GP_PAINT_DOSIMPLIFY) || GP_BUFFER2STROKE_ENDPOINTS)
+	if (!(U.gp_settings & GP_PAINT_DOSIMPLIFY) || (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT))
 		return;
 	
 	/* don't simplify if less than 4 points in buffer */
@@ -388,11 +418,10 @@
 	tGPspoint *ptc;
 	int i, totelem;
 	
-	/* get total number of points to allocate space for:
-	 *	- in 'Draw Mode', holding the Ctrl-Modifier will only take endpoints
-	 *	- otherwise, do whole stroke
+	/* get total number of points to allocate space for 
+	 *	- drawing straight-lines only requires the endpoints
 	 */
-	if (GP_BUFFER2STROKE_ENDPOINTS)
+	if (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT)
 		totelem = (gpd->sbuffer_size >= 2) ? 2: gpd->sbuffer_size;
 	else
 		totelem = gpd->sbuffer_size;
@@ -416,8 +445,8 @@
 	gps->flag= gpd->sbuffer_sflag;
 	
 	/* copy points from the buffer to the stroke */
-	if (GP_BUFFER2STROKE_ENDPOINTS) {
-		/* 'Draw Mode' + Ctrl-Modifier - only endpoints */
+	if (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT) {
+		/* straight lines only -> only endpoints */
 		{
 			/* first point */
 			ptc= gpd->sbuffer;
@@ -1013,7 +1042,6 @@
 {
 	tGPsdata *p;
 	int paintmode= RNA_enum_get(op->ptr, "mode");
-	int straightLines= RNA_boolean_get(op->ptr, "straight_lines");
 	
 	/* check context */
 	p= op->customdata= gp_session_initpaint(C);
@@ -1033,10 +1061,6 @@
 	/* radius for eraser circle is defined in userprefs now */
 	p->radius= U.gp_eraser;
 	
-	/* set line-drawing settings (straight or freehand lines) */
-	if (straightLines)
-		p->flags |= GP_PAINTFLAG_STRAIGHTLINES;
-	
 	/* everything is now setup ok */
 	return 1;
 }
@@ -1126,8 +1150,8 @@
 {
 	tGPsdata *p= op->customdata;
 	ARegion *ar= p->ar;
-	PointerRNA itemptr;
-	float mousef[2];
+	//PointerRNA itemptr;
+	//float mousef[2];
 	int tablet=0;
 
 	/* convert from window-space to area-space mouse coordintes */
@@ -1162,6 +1186,7 @@
 			return;
 	}
 	
+#if 0 // NOTE: disabled for now, since creating this data is currently useless anyways (and slows things down)
 	/* fill in stroke data (not actually used directly by gpencil_draw_apply) */
 	RNA_collection_add(op->ptr, "stroke", &itemptr);
 
@@ -1169,12 +1194,13 @@
 	mousef[1]= p->mval[1];
 	RNA_float_set_array(&itemptr, "mouse", mousef);
 	RNA_float_set(&itemptr, "pressure", p->pressure);
+#endif 
 	
 	/* apply the current latest drawing point */
 	gpencil_draw_apply(C, op, p);
 	
 	/* force refresh */
-	WM_event_add_notifier(C, NC_SCREEN|ND_GPENCIL|NA_EDITED, NULL); // XXX please work!
+	ED_region_tag_redraw(p->ar); /* just active area for now, since doing whole screen is too slow */
 }
 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list