[Bf-blender-cvs] [80b1620] GPencil_Editing_Stage3: GPencil: Moved Stroke Placement settings from GP datablock to tool settings

Joshua Leung noreply at git.blender.org
Sat Dec 5 15:46:42 CET 2015


Commit: 80b1620cf33991a4c307f77357209ae6139196bf
Author: Joshua Leung
Date:   Sun Dec 6 03:46:15 2015 +1300
Branches: GPencil_Editing_Stage3
https://developer.blender.org/rB80b1620cf33991a4c307f77357209ae6139196bf

GPencil: Moved Stroke Placement settings from GP datablock to tool settings

This commit moves the Stroke Placement settings from being a per-datablock
setting to being stored in tool settings instead. The main reason this was
done was to resolve a usability issue with the old way: in order to set this
setting, you had to first create a GP datablock to be able to see the settings!

Now, by having these as tool settings (as they should have been from the start),
they can be always visible (even when there isn't a datablock yet), meaning that
it will work as expected from the very first stroke.


Implementation Notes:
* There are separate Stroke Placement properties for the different editor types.
  e.g. 3D View, Sequencer Preview, Image Editor, and all other 2D Views

* I couldn't get the version patching code working (to port over placement settings
  from the GP datablock attached to the active scene), as this was causing crashes
  and other general weirdness when loading old files. The code to do this is there,
  but #if 0'ed out.

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

M	release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M	source/blender/blenkernel/intern/scene.c
M	source/blender/blenloader/intern/versioning_270.c
M	source/blender/blenloader/intern/versioning_defaults.c
M	source/blender/editors/gpencil/gpencil_paint.c
M	source/blender/makesdna/DNA_gpencil_types.h
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/intern/rna_gpencil.c
M	source/blender/makesrna/intern/rna_scene.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 ee1ff62..5dacfed 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -22,23 +22,34 @@
 from bpy.types import Menu, UIList
 
 
-def gpencil_stroke_placement_settings(context, layout, gpd):
+def gpencil_stroke_placement_settings(context, layout):
+    if context.space_data.type == 'VIEW_3D':
+        propname = "gpencil_stroke_placement_view3d"
+    elif context.space_data.type == 'SEQUENCE_EDITOR':
+        propname = "gpencil_stroke_placement_sequencer_preview"
+    elif context.space_data.type == 'IMAGE_EDITOR':
+        propname = "gpencil_stroke_placement_image_edit"
+    else:
+        propname = "gpencil_stroke_placement_view2d"
+
+    ts = context.tool_settings
+
     col = layout.column(align=True)
 
     col.label(text="Stroke Placement:")
 
     row = col.row(align=True)
-    row.prop_enum(gpd, "draw_mode", 'VIEW')
-    row.prop_enum(gpd, "draw_mode", 'CURSOR')
+    row.prop_enum(ts, propname, 'VIEW')
+    row.prop_enum(ts, propname, 'CURSOR')
 
     if context.space_data.type == 'VIEW_3D':
         row = col.row(align=True)
-        row.prop_enum(gpd, "draw_mode", 'SURFACE')
-        row.prop_enum(gpd, "draw_mode", 'STROKE')
+        row.prop_enum(ts, propname, 'SURFACE')
+        row.prop_enum(ts, propname, 'STROKE')
 
         row = col.row(align=False)
-        row.active = gpd.draw_mode in {'SURFACE', 'STROKE'}
-        row.prop(gpd, "use_stroke_endpoints")
+        row.active = getattr(ts, propname) in {'SURFACE', 'STROKE'}
+        row.prop(ts, "use_gpencil_stroke_endpoints")
 
 
 class GreasePencilDrawingToolsPanel:
@@ -74,12 +85,14 @@ class GreasePencilDrawingToolsPanel:
                 row.prop(context.tool_settings, "grease_pencil_source", expand=True)
             elif context.space_data.type == 'CLIP_EDITOR':
                 row.prop(context.space_data, "grease_pencil_source", expand=True)
+        
+        col.separator()
+
+        gpencil_stroke_placement_settings(context, col)
 
         gpd = context.gpencil_data
-        if gpd:
-            col.separator()
-            gpencil_stroke_placement_settings(context, col, gpd)
 
+        if gpd:
             layout.separator()
             layout.separator()
 
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 7e179fd..b2ef693 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -791,6 +791,12 @@ void BKE_scene_init(Scene *sce)
 		gp_brush->strength = 0.5f;
 		gp_brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
 	}
+	
+	/* GP Stroke Placement */
+	sce->toolsettings->gpencil_v3d_align = GP_PROJECT_VIEWSPACE;
+	sce->toolsettings->gpencil_v2d_align = GP_PROJECT_VIEWSPACE;
+	sce->toolsettings->gpencil_seq_align = GP_PROJECT_VIEWSPACE;
+	sce->toolsettings->gpencil_ima_align = GP_PROJECT_VIEWSPACE;
 }
 
 Scene *BKE_scene_add(Main *bmain, const char *name)
diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c
index 473cbf6..e6005da 100644
--- a/source/blender/blenloader/intern/versioning_270.c
+++ b/source/blender/blenloader/intern/versioning_270.c
@@ -38,6 +38,7 @@
 #include "DNA_camera_types.h"
 #include "DNA_cloth_types.h"
 #include "DNA_constraint_types.h"
+#include "DNA_gpencil_types.h"
 #include "DNA_sdna_types.h"
 #include "DNA_sequence_types.h"
 #include "DNA_space_types.h"
@@ -983,6 +984,33 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
 				brush->size = 50;
 				brush->strength = 1.0f;
 			}
+			
+			if (!DNA_struct_elem_find(fd->filesdna, "ToolSettings", "char", "gpencil_v3d_align")) {
+#if 0 /* XXX: Cannot do this, as we get random crashes... */
+				if (scene->gpd) {
+					bGPdata *gpd = scene->gpd;
+					
+					/* Copy over the settings stored in the GP datablock linked to the scene, for minimal disruption */
+					ts->gpencil_v3d_align = 0;
+					
+					if (gpd->flag & GP_DATA_VIEWALIGN)    ts->gpencil_v3d_align |= GP_PROJECT_VIEWSPACE;
+					if (gpd->flag & GP_DATA_DEPTH_VIEW)   ts->gpencil_v3d_align |= GP_PROJECT_DEPTH_VIEW;
+					if (gpd->flag & GP_DATA_DEPTH_STROKE) ts->gpencil_v3d_align |= GP_PROJECT_DEPTH_STROKE;
+					
+					if (gpd->flag & GP_DATA_DEPTH_STROKE_ENDPOINTS)
+						ts->gpencil_v3d_align |= GP_PROJECT_DEPTH_STROKE_ENDPOINTS;
+				}
+				else {
+					/* Default to cursor for all standard 3D views */
+					ts->gpencil_v3d_align = GP_PROJECT_VIEWSPACE;
+				}
+#endif
+				
+				ts->gpencil_v3d_align = GP_PROJECT_VIEWSPACE;
+				ts->gpencil_v2d_align = GP_PROJECT_VIEWSPACE;
+				ts->gpencil_seq_align = GP_PROJECT_VIEWSPACE;
+				ts->gpencil_ima_align = GP_PROJECT_VIEWSPACE;
+			}
 		}
 	}
 }
diff --git a/source/blender/blenloader/intern/versioning_defaults.c b/source/blender/blenloader/intern/versioning_defaults.c
index c949ea6..eb0d392 100644
--- a/source/blender/blenloader/intern/versioning_defaults.c
+++ b/source/blender/blenloader/intern/versioning_defaults.c
@@ -131,6 +131,11 @@ void BLO_update_defaults_startup_blend(Main *bmain)
 				brush->strength = 0.5f;
 				brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
 			}
+			
+			ts->gpencil_v3d_align = GP_PROJECT_VIEWSPACE;
+			ts->gpencil_v2d_align = GP_PROJECT_VIEWSPACE;
+			ts->gpencil_seq_align = GP_PROJECT_VIEWSPACE;
+			ts->gpencil_ima_align = GP_PROJECT_VIEWSPACE;
 		}
 
 		scene->gm.lodflag |= SCE_LOD_USE_HYST;
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 5c02ef0..a724a27 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -95,6 +95,8 @@ typedef struct tGPsdata {
 	bGPDlayer *gpl;     /* layer we're working on */
 	bGPDframe *gpf;     /* frame we're working on */
 	
+	char *align_flag;   /* projection-mode flags (toolsettings) */
+	
 	short status;       /* current status of painting */
 	short paintmode;    /* mode for painting */
 	
@@ -204,7 +206,7 @@ static int gpencil_draw_poll(bContext *C)
 static bool gpencil_project_check(tGPsdata *p)
 {
 	bGPdata *gpd = p->gpd;
-	return ((gpd->sbuffer_sflag & GP_STROKE_3DSPACE) && (p->gpd->flag & (GP_DATA_DEPTH_VIEW | GP_DATA_DEPTH_STROKE)));
+	return ((gpd->sbuffer_sflag & GP_STROKE_3DSPACE) && (*p->align_flag & (GP_PROJECT_DEPTH_VIEW | GP_PROJECT_DEPTH_STROKE)));
 }
 
 /* ******************************************* */
@@ -1001,6 +1003,7 @@ static bool gp_session_initdata(bContext *C, tGPsdata *p)
 	bGPdata **gpd_ptr = NULL;
 	ScrArea *curarea = CTX_wm_area(C);
 	ARegion *ar = CTX_wm_region(C);
+	ToolSettings *ts = CTX_data_tool_settings(C);
 	
 	/* make sure the active view (at the starting time) is a 3d-view */
 	if (curarea == NULL) {
@@ -1030,6 +1033,7 @@ static bool gp_session_initdata(bContext *C, tGPsdata *p)
 			/* CAUTION: If this is the "toolbar", then this will change on the first stroke */
 			p->sa = curarea;
 			p->ar = ar;
+			p->align_flag = &ts->gpencil_v3d_align;
 			
 			if (ar->regiondata == NULL) {
 				p->status = GP_STATUS_ERROR;
@@ -1047,6 +1051,7 @@ static bool gp_session_initdata(bContext *C, tGPsdata *p)
 			p->sa = curarea;
 			p->ar = ar;
 			p->v2d = &ar->v2d;
+			p->align_flag = &ts->gpencil_v2d_align;
 			break;
 		}
 		case SPACE_SEQ:
@@ -1057,6 +1062,7 @@ static bool gp_session_initdata(bContext *C, tGPsdata *p)
 			p->sa = curarea;
 			p->ar = ar;
 			p->v2d = &ar->v2d;
+			p->align_flag = &ts->gpencil_seq_align;
 			
 			/* check that gpencil data is allowed to be drawn */
 			if (sseq->mainb == SEQ_DRAW_SEQUENCE) {
@@ -1075,6 +1081,7 @@ static bool gp_session_initdata(bContext *C, tGPsdata *p)
 			p->sa = curarea;
 			p->ar = ar;
 			p->v2d = &ar->v2d;
+			p->align_flag = &ts->gpencil_ima_align;
 			break;
 		}
 		case SPACE_CLIP:
@@ -1091,6 +1098,7 @@ static bool gp_session_initdata(bContext *C, tGPsdata *p)
 			p->sa = curarea;
 			p->ar = ar;
 			p->v2d = &ar->v2d;
+			p->align_flag = &ts->gpencil_v2d_align;
 			
 			invert_m4_m4(p->imat, sc->unistabmat);
 			
@@ -1196,6 +1204,7 @@ static void gp_session_cleanup(tGPsdata *p)
 /* init new stroke */
 static void gp_paint_initstroke(tGPsdata *p, short paintmode)
 {
+	
 	/* get active layer (or add a new one if non-existent) */
 	p->gpl = gpencil_layer_getactive(p->gpd);
 	if (p->gpl == NULL) {
@@ -1251,7 +1260,7 @@ static void gp_paint_initstroke(tGPsdata *p, short paintmode)
 	
 	/* when drawing in the camera view, in 2D space, set the subrect */
 	p->subrect = NULL;
-	if (!(p->gpd->flag & GP_DATA_VIEWALIGN)) {
+	if ((*p->align_flag & GP_PROJECT_VIEWSPACE) == 0) {
 		if (p->sa->spacetype == SPACE_VIEW3D) {
 			View3D *v3d = p->sa->spacedata.first;
 			RegionView3D *rv3d = p->ar->regiondata;
@@ -1279,7 +1288,7 @@ static void gp_paint_initstroke(tGPsdata *p, short paintmode)
 	
 	
 	/* check if points will need to be made in view-aligned space */
-	if (p->gpd->flag & GP_DATA_VIEWALIGN) {
+	if (*p->align_flag & GP_PROJECT_VIEWSPACE) {
 		switch (p->sa->spacetype) {
 			case SPACE_VIEW3D:
 			{
@@ -1308,7 +1317,7 @@ static void gp_paint_initstroke(tGPsdata *p, short paintmode)
 				if (ELEM(NULL, sima, sima->image)) {
 					/* make strokes be drawn in screen space */
 					p->gpd->sbuffer_sflag &= ~GP_STROKE_2DSPACE;
-					p->gpd->flag &= ~GP_DATA_VIEWALIGN;
+					*(p->align_flag) &= ~GP_PROJECT_VIEWSPACE;
 				}
 				else {
 					p->gpd->sbuffer_sflag |= GP_STROKE_2DSPACE;
diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h
index 053581f..be4cfbe 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -190,6 +190,7 @@ typedef enum eGPdata_Flag {
 	/* is the block overriding all clicks? */
 	/* GP_DATA_EDITPAINT = (1 << 3), */
 	
+/* ------------------------------------------------ DEPRECATED */
 	/* new strokes are added in viewport space */
 	GP_DATA_VIEWALIGN	= (1 << 4),
 	
@@ -198,6 +199,7 @@ typedef enum eGPdata_Flag {
 	GP_DATA_DEPTH_STROKE = (1 << 6),
 
 	GP_DATA_DEPTH_STROKE_ENDPOINTS = (

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list