[Bf-blender-cvs] [e9ae8a3] GPencil_EditStrokes: GP Onion Skinning: Custom before/after colours and ranges

Joshua Leung noreply at git.blender.org
Tue Oct 14 15:32:28 CEST 2014


Commit: e9ae8a382faa5ee2e688ad865d95429643df16bd
Author: Joshua Leung
Date:   Wed Oct 15 02:03:58 2014 +1300
Branches: GPencil_EditStrokes
https://developer.blender.org/rBe9ae8a382faa5ee2e688ad865d95429643df16bd

GP Onion Skinning: Custom before/after colours and ranges

It is now possible to set different colors for ghosts "before" and "after" the
current frame, and to separately control how many are displayed on each side.

To use custom colors, it is necessary to firstly toggle the color-wheel icon-toggle
(located beside the Onion Skinning) checkbox. This will make both before and after
strokes get drawn using custom colors. I tried having separate toggles, but that
was too clumsy.


TODO:
* Some version-patching code will be needed to initialise the colours and fields
  so that they work when loading old files. I've reused the old field for the
  "before" range, so that at least something will be usable there.
* Some code cleanup is in order to make this code a bit nicer

===================================================================

M	release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M	source/blender/editors/gpencil/drawgpencil.c
M	source/blender/makesdna/DNA_gpencil_types.h
M	source/blender/makesrna/intern/rna_gpencil.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
index 1292c14..b493d81 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -278,6 +278,8 @@ class GreasePencilDataPanel():
             col.prop(gpl, "line_width", slider=True)
             col.prop(gpl, "show_x_ray")
 
+            layout.separator()
+
             # Full-Row - Frame Locking
             row = layout.row()
             row.active = not gpl.lock
@@ -289,14 +291,30 @@ class GreasePencilDataPanel():
                 lock_label = "Lock Frame"
             row.prop(gpl, "lock_frame", text=lock_label, icon='UNLOCKED')
 
+            layout.separator()
+
             # Onion skinning
             col = layout.column(align=True)
             col.active = not gpl.lock
-            col.prop(gpl, "use_onion_skinning")
 
-            subcol = col.column()
-            subcol.active = gpl.use_onion_skinning
-            subcol.prop(gpl, "ghost_range_max", text="Frames")
+            row = col.row()
+            row.prop(gpl, "use_onion_skinning")
+            row.prop(gpl, "use_ghost_custom_colors", text="", icon='COLOR')
+
+            split = col.split(percentage = 0.5)
+            split.active = gpl.use_onion_skinning
+
+            # - Before Frames
+            sub = split.column(align=True)
+            row = sub.row(align=True)
+            row.active = gpl.use_ghost_custom_colors
+            row.prop(gpl, "before_color", text="")
+            sub.prop(gpl, "ghost_before_range", text="Before")
+
 
-            # XXX: replace "frames" with a split for "before" and "after",
-            # each of which contains a color/toggle for using that + number of frames
+            # - After Frames
+            sub = split.column(align=True)
+            row = sub.row(align=True)
+            row.active = gpl.use_ghost_custom_colors
+            row.prop(gpl, "after_color", text="")
+            sub.prop(gpl, "ghost_after_range", text="After")
diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c
index 8d9b64a..b680fc1 100644
--- a/source/blender/editors/gpencil/drawgpencil.c
+++ b/source/blender/editors/gpencil/drawgpencil.c
@@ -714,8 +714,18 @@ static void gp_draw_data(bGPdata *gpd, int offsx, int offsy, int winx, int winy,
 		
 		/* draw 'onionskins' (frame left + right) */
 		if (gpl->flag & GP_LAYER_ONIONSKIN) {
-			/* drawing method - only immediately surrounding (gstep = 0),
-			 * or within a frame range on either side (gstep > 0)*/
+			/* Drawing method - only immediately surrounding (gstep = 0),
+			 * or within a frame range on either side (gstep > 0)
+			 */
+			
+			/* 1) Draw Previous Frames First */
+			if (gpl->flag & GP_LAYER_GHOST_PREVCOL) {
+				copy_v3_v3(tcolor, gpl->gcolor_prev);
+			}
+			else {
+				copy_v3_v3(tcolor, gpl->color);
+			}
+			
 			if (gpl->gstep) {
 				bGPDframe *gf;
 				float fac;
@@ -732,38 +742,52 @@ static void gp_draw_data(bGPdata *gpd, int offsx, int offsy, int winx, int winy,
 					else 
 						break;
 				}
+			}
+			else {
+				/* draw the strokes for the ghost frames (at half of the alpha set by user) */
+				if (gpf->prev) {
+					tcolor[3] = (color[3] / 7);
+					gp_draw_strokes(gpf->prev, offsx, offsy, winx, winy, dflag, debug, lthick, tcolor);
+				}
+			}
+			
+			
+			/* 2) Now draw next frames */
+			if (gpl->flag & GP_LAYER_GHOST_NEXTCOL) {
+				copy_v3_v3(tcolor, gpl->gcolor_next);
+			}
+			else {
+				copy_v3_v3(tcolor, gpl->color);
+			}
+			
+			if (gpl->gstep_next) {
+				bGPDframe *gf;
+				float fac;
 				
 				/* now draw next frames */
 				for (gf = gpf->next; gf; gf = gf->next) {
 					/* check if frame is drawable */
-					if ((gf->framenum - gpf->framenum) <= gpl->gstep) {
+					if ((gf->framenum - gpf->framenum) <= gpl->gstep_next) {
 						/* alpha decreases with distance from curframe index */
-						fac = 1.0f - ((float)(gf->framenum - gpf->framenum) / (float)(gpl->gstep + 1));
+						fac = 1.0f - ((float)(gf->framenum - gpf->framenum) / (float)(gpl->gstep_next + 1));
 						tcolor[3] = color[3] * fac * 0.66f;
 						gp_draw_strokes(gf, offsx, offsy, winx, winy, dflag, debug, lthick, tcolor);
 					}
 					else 
 						break;
 				}
-				
-				/* restore alpha */
-				glColor4fv(color);
 			}
 			else {
 				/* draw the strokes for the ghost frames (at half of the alpha set by user) */
-				if (gpf->prev) {
-					tcolor[3] = (color[3] / 7);
-					gp_draw_strokes(gpf->prev, offsx, offsy, winx, winy, dflag, debug, lthick, tcolor);
-				}
-				
 				if (gpf->next) {
 					tcolor[3] = (color[3] / 4);
 					gp_draw_strokes(gpf->next, offsx, offsy, winx, winy, dflag, debug, lthick, tcolor);
 				}
-				
-				/* restore alpha */
-				glColor4fv(color);
 			}
+			
+			/* 3) restore alpha */
+			copy_v4_v4(tcolor, color);
+			glColor4fv(color);
 		}
 		
 		/* draw the strokes already in active frame */
diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h
index dab1e93..d4f3cf6 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -108,9 +108,14 @@ typedef struct bGPDlayer {
 	ListBase frames;		/* list of annotations to display for frames (bGPDframe list) */
 	bGPDframe *actframe;	/* active frame (should be the frame that is currently being displayed) */
 	
-	int flag;				/* settings for layer */
+	short flag;				/* settings for layer */
 	short thickness;		/* current thickness to apply to strokes */
-	short gstep;			/* max number of frames between active and ghost to show (0=only those on either side) */
+	
+	short gstep;			/* Ghosts Before: max number of ghost frames to show between active frame and the one before it (0 = only the ghost itself) */
+	short gstep_next;		/* Ghosts After:  max number of ghost frames to show after active frame and the following it    (0 = only the ghost itself) */
+	
+	float gcolor_prev[3];	/* optional color for ghosts before the active frame */
+	float gcolor_next[3];	/* optional color for ghosts after the active frame */
 	
 	float color[4];			/* color that should be used to draw all the strokes in this layer */
 	
@@ -128,14 +133,18 @@ typedef enum eGPDlayer_Flag {
 	GP_LAYER_ACTIVE			= (1 << 2),
 	/* draw points of stroke for debugging purposes */
 	GP_LAYER_DRAWDEBUG 		= (1 << 3),
-	/* do onionskinning */
+	/* do onion skinning */
 	GP_LAYER_ONIONSKIN		= (1 << 4),
 	/* for editing in Action Editor */
 	GP_LAYER_SELECT			= (1 << 5),
 	/* current frame for layer can't be changed */
 	GP_LAYER_FRAMELOCK		= (1 << 6),
 	/* don't render xray (which is default) */
-	GP_LAYER_NO_XRAY		= (1 << 7)
+	GP_LAYER_NO_XRAY		= (1 << 7),
+	/* use custom color for ghosts before current frame */
+	GP_LAYER_GHOST_PREVCOL	= (1 << 8),
+	/* use custom color for ghosts after current frame */
+	GP_LAYER_GHOST_NEXTCOL	= (1 << 9)
 } eGPDlayer_Flag;
 
 /* Grease-Pencil Annotations - 'DataBlock' */
diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c
index 8b77125..7048c49 100644
--- a/source/blender/makesrna/intern/rna_gpencil.c
+++ b/source/blender/makesrna/intern/rna_gpencil.c
@@ -610,7 +610,7 @@ static void rna_def_gpencil_layer(BlenderRNA *brna)
 	/* Line Thickness */
 	prop = RNA_def_property(srna, "line_width", PROP_INT, PROP_PIXEL);
 	RNA_def_property_int_sdna(prop, NULL, "thickness");
-	RNA_def_property_range(prop, 1, 10);
+	RNA_def_property_range(prop, 1, 10); /* 10 px limit comes from Windows OpenGL limits for natively-drawn strokes */
 	RNA_def_property_ui_text(prop, "Thickness", "Thickness of strokes (in pixels)");
 	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
 	
@@ -620,12 +620,39 @@ static void rna_def_gpencil_layer(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Onion Skinning", "Ghost frames on either side of frame");
 	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
 	
-	prop = RNA_def_property(srna, "ghost_range_max", PROP_INT, PROP_NONE);
+	prop = RNA_def_property(srna, "ghost_before_range", PROP_INT, PROP_NONE);
 	RNA_def_property_int_sdna(prop, NULL, "gstep");
 	RNA_def_property_range(prop, 0, 120);
-	RNA_def_property_ui_text(prop, "Max Ghost Range",
-	                         "Maximum number of frames on either side of the active frame to show "
-	                         "(0 = show the 'first' available sketch on either side)");
+	RNA_def_property_ui_text(prop, "Frames Before",
+	                         "Maximum number of frames to show before current frame "
+	                         "(0 = show only the previous sketch)");
+	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
+	
+	prop = RNA_def_property(srna, "ghost_after_range", PROP_INT, PROP_NONE);
+	RNA_def_property_int_sdna(prop, NULL, "gstep_next");
+	RNA_def_property_range(prop, 0, 120);
+	RNA_def_property_ui_text(prop, "Frames After",
+	                         "Maximum number of frames to show after current frame "
+	                         "(0 = show only the next sketch)");
+	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
+	
+	prop = RNA_def_property(srna, "use_ghost_custom_colors", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_LAYER_GHOST_PREVCOL | GP_LAYER_GHOST_NEXTCOL);
+	RNA_def_property_ui_text(prop, "Use Custom Ghost Colors", "Use custom colors for ghost frames");
+	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
+	
+	prop = RNA_def_property(srna, "before_color", PROP_FLOAT, PROP_COLOR_GAMMA);
+	RNA_def_property_float_sdna(prop, NULL, "gcolor_prev");
+	RNA_def_property_array(prop, 3);
+	RNA_def_property_range(prop, 0.0f, 1.0f);
+	RNA_def_property_ui_text(prop, "Before Color", "Base color for ghosts before the active frame");
+	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
+	
+	prop = RNA_def_property(srna, "after_color", PROP_FLOAT, PROP_COLOR_GAMMA);
+	RNA_def_property_float_sdna(prop, NULL, "gcolor_next");
+	RNA_def_property_arr

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list