[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34051] trunk/blender: Grease Pencil Todos : "Sketching Sessions"

Joshua Leung aligorith at gmail.com
Tue Jan 4 04:14:02 CET 2011


Revision: 34051
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=34051
Author:   aligorith
Date:     2011-01-04 04:14:01 +0100 (Tue, 04 Jan 2011)

Log Message:
-----------
Grease Pencil Todos: "Sketching Sessions"

Due to popular request and usability considerations, this commit
reintroduces functionality similar to 2.4's "Draw Mode" for Grease
Pencil.

In the toolbar under the Draw/Line/Eraser buttons, you can find the
"Use Sketching Sessions" toggle, which enables this feature. This is a
per-scene setting, and defaults to off, so that the current 2.5
behaviour is still the default (i.e. the Grease Pencil operator will
only do a single stroke at a time).

With this option enabled, drawing with Grease Pencil will enter a
semi-modal state where you can draw multiple strokes without needing
to keep holding the DKEY throughout (though you'll still need to do so
to start the strokes, unless you use some toolbar buttons), while
still being able to manipulate the viewport. Header help-text prints
show the appropriate keybindings (i.e. press ESCKEY or ENTER to end
the sketching session).

Notes:
- To aid maintainability of the 3D-View toolbar code, I've taken the
liberty to factor out the groups of widgets which commonly occur in
most of the toolbars into separate functions (namely "Repeat" and
"Grease Pencil"). Perhaps it might make it slightly harder to newbies
to the toolbar code to grasp, though the physics panels are far worse
;)
- I've reshuffled some code in the Grease Pencil code to separate out
the various states of operation again more clearly, though some more
work is still needed there (TODO)
- There can now be only one Grease Pencil operator running at a time
- Redoing Grease Pencil operations where sketching sessions was
enabled still needs work. Namely, a way of delimiting the set of
points recorded into strokes is still needed (TODO)
- Ultimately, it should be possible to switch tools midway through a
session. Currently sessions are limited to only being able to be used
with a single drawing mode (TODO)
- After ending a drawing session, the titlebar contols may not work on
Windows without manually making the main window lose focus and then
regain (i.e. click on some other window in toolbar, then come back).
This may be related to (bug #25480)

Modified Paths:
--------------
    trunk/blender/release/scripts/ui/space_view3d_toolbar.py
    trunk/blender/source/blender/editors/gpencil/gpencil_paint.c
    trunk/blender/source/blender/editors/include/ED_gpencil.h
    trunk/blender/source/blender/makesdna/DNA_scene_types.h
    trunk/blender/source/blender/makesrna/intern/rna_scene.c

Modified: trunk/blender/release/scripts/ui/space_view3d_toolbar.py
===================================================================
--- trunk/blender/release/scripts/ui/space_view3d_toolbar.py	2011-01-03 19:45:08 UTC (rev 34050)
+++ trunk/blender/release/scripts/ui/space_view3d_toolbar.py	2011-01-04 03:14:01 UTC (rev 34051)
@@ -25,6 +25,29 @@
     bl_region_type = 'TOOLS'
 
 
+# **************** standard tool clusters ******************
+
+# History/Repeat tools
+def draw_repeat_tools(context, layout):
+    col = layout.column(align=True)
+    col.label(text="Repeat:")
+    col.operator("screen.repeat_last")
+    col.operator("screen.repeat_history", text="History...")
+
+# Grease Pencil tools
+def draw_gpencil_tools(context, layout):
+    col = layout.column(align=True)
+    
+    col.label(text="Grease Pencil:")
+    
+    row = col.row()
+    row.operator("gpencil.draw", text="Draw").mode = 'DRAW'
+    row.operator("gpencil.draw", text="Line").mode = 'DRAW_STRAIGHT'
+    row.operator("gpencil.draw", text="Erase").mode = 'ERASER'
+    
+    row = col.row()
+    row.prop(context.tool_settings, "use_grease_pencil_sessions")
+
 # ********** default tools for objectmode ****************
 
 
@@ -63,17 +86,9 @@
         col.operator("anim.keyframe_insert_menu", text="Insert")
         col.operator("anim.keyframe_delete_v3d", text="Remove")
 
-        col = layout.column(align=True)
-        col.label(text="Repeat:")
-        col.operator("screen.repeat_last")
-        col.operator("screen.repeat_history", text="History...")
+        draw_repeat_tools(context, layout)
 
-        col = layout.column(align=True)
-        col.label(text="Grease Pencil:")
-        row = col.row()
-        row.operator("gpencil.draw", text="Draw").mode = 'DRAW'
-        row.operator("gpencil.draw", text="Line").mode = 'DRAW_STRAIGHT'
-        row.operator("gpencil.draw", text="Erase").mode = 'ERASER'
+        draw_gpencil_tools(context, layout)
 
 # ********** default tools for editmode_mesh ****************
 
@@ -131,17 +146,9 @@
         col.operator("mesh.faces_shade_smooth", text="Smooth")
         col.operator("mesh.faces_shade_flat", text="Flat")
 
-        col = layout.column(align=True)
-        col.label(text="Repeat:")
-        col.operator("screen.repeat_last")
-        col.operator("screen.repeat_history", text="History...")
+        draw_repeat_tools(context, layout)
 
-        col = layout.column(align=True)
-        col.label(text="Grease Pencil:")
-        row = col.row()
-        row.operator("gpencil.draw", text="Draw").mode = 'DRAW'
-        row.operator("gpencil.draw", text="Line").mode = 'DRAW_STRAIGHT'
-        row.operator("gpencil.draw", text="Erase").mode = 'ERASER'
+        draw_gpencil_tools(context, layout)
 
 
 class VIEW3D_PT_tools_meshedit_options(View3DPanel, bpy.types.Panel):
@@ -202,17 +209,9 @@
         col.operator("curve.extrude")
         col.operator("curve.subdivide")
 
-        col = layout.column(align=True)
-        col.label(text="Repeat:")
-        col.operator("screen.repeat_last")
-        col.operator("screen.repeat_history", text="History...")
+        draw_repeat_tools(context, layout)
 
-        col = layout.column(align=True)
-        col.label(text="Grease Pencil:")
-        row = col.row()
-        row.operator("gpencil.draw", text="Draw").mode = 'DRAW'
-        row.operator("gpencil.draw", text="Line").mode = 'DRAW_STRAIGHT'
-        row.operator("gpencil.draw", text="Erase").mode = 'ERASER'
+        draw_gpencil_tools(context, layout)
 
 # ********** default tools for editmode_surface ****************
 
@@ -242,17 +241,9 @@
         col.operator("curve.extrude")
         col.operator("curve.subdivide")
 
-        col = layout.column(align=True)
-        col.label(text="Repeat:")
-        col.operator("screen.repeat_last")
-        col.operator("screen.repeat_history", text="History...")
+        draw_repeat_tools(context, layout)
 
-        col = layout.column(align=True)
-        col.label(text="Grease Pencil:")
-        row = col.row()
-        row.operator("gpencil.draw", text="Draw").mode = 'DRAW'
-        row.operator("gpencil.draw", text="Line").mode = 'DRAW_STRAIGHT'
-        row.operator("gpencil.draw", text="Erase").mode = 'ERASER'
+        draw_gpencil_tools(context, layout)
 
 # ********** default tools for editmode_text ****************
 
@@ -281,10 +272,7 @@
         col.operator("font.style_toggle", text="Italic").style = 'ITALIC'
         col.operator("font.style_toggle", text="Underline").style = 'UNDERLINE'
 
-        col = layout.column(align=True)
-        col.label(text="Repeat:")
-        col.operator("screen.repeat_last")
-        col.operator("screen.repeat_history", text="History...")
+        draw_repeat_tools(context, layout)
 
 
 # ********** default tools for editmode_armature ****************
@@ -314,17 +302,9 @@
         col.operator("armature.extrude_move")
         col.operator("armature.subdivide", text="Subdivide")
 
-        col = layout.column(align=True)
-        col.label(text="Repeat:")
-        col.operator("screen.repeat_last")
-        col.operator("screen.repeat_history", text="History...")
+        draw_repeat_tools(context, layout)
 
-        col = layout.column(align=True)
-        col.label(text="Grease Pencil:")
-        row = col.row()
-        row.operator("gpencil.draw", text="Draw").mode = 'DRAW'
-        row.operator("gpencil.draw", text="Line").mode = 'DRAW_STRAIGHT'
-        row.operator("gpencil.draw", text="Erase").mode = 'ERASER'
+        draw_gpencil_tools(context, layout)
 
 
 class VIEW3D_PT_tools_armatureedit_options(View3DPanel, bpy.types.Panel):
@@ -355,17 +335,9 @@
         col.operator("transform.rotate")
         col.operator("transform.resize", text="Scale")
 
-        col = layout.column(align=True)
-        col.label(text="Repeat:")
-        col.operator("screen.repeat_last")
-        col.operator("screen.repeat_history", text="History...")
+        draw_repeat_tools(context, layout)
 
-        col = layout.column(align=True)
-        col.label(text="Grease Pencil:")
-        row = col.row()
-        row.operator("gpencil.draw", text="Draw").mode = 'DRAW'
-        row.operator("gpencil.draw", text="Line").mode = 'DRAW_STRAIGHT'
-        row.operator("gpencil.draw", text="Erase").mode = 'ERASER'
+        draw_gpencil_tools(context, layout)
 
 # ********** default tools for editmode_lattice ****************
 
@@ -386,17 +358,9 @@
         col = layout.column(align=True)
         col.operator("lattice.make_regular")
 
-        col = layout.column(align=True)
-        col.label(text="Repeat:")
-        col.operator("screen.repeat_last")
-        col.operator("screen.repeat_history", text="History...")
+        draw_repeat_tools(context, layout)
 
-        col = layout.column(align=True)
-        col.label(text="Grease Pencil:")
-        row = col.row()
-        row.operator("gpencil.draw", text="Draw").mode = 'DRAW'
-        row.operator("gpencil.draw", text="Line").mode = 'DRAW_STRAIGHT'
-        row.operator("gpencil.draw", text="Erase").mode = 'ERASER'
+        draw_gpencil_tools(context, layout)
 
 
 # ********** default tools for posemode ****************
@@ -437,17 +401,9 @@
         col.operator("anim.keyframe_insert_menu", text="Insert")
         col.operator("anim.keyframe_delete_v3d", text="Remove")
 
-        col = layout.column(align=True)
-        col.label(text="Repeat:")
-        col.operator("screen.repeat_last")
-        col.operator("screen.repeat_history", text="History...")
+        draw_repeat_tools(context, layout)
 
-        col = layout.column(align=True)
-        col.label(text="Grease Pencil:")
-        row = col.row()
-        row.operator("gpencil.draw", text="Draw").mode = 'DRAW'
-        row.operator("gpencil.draw", text="Line").mode = 'DRAW_STRAIGHT'
-        row.operator("gpencil.draw", text="Erase").mode = 'ERASER'
+        draw_gpencil_tools(context, layout)
 
 
 class VIEW3D_PT_tools_posemode_options(View3DPanel, bpy.types.Panel):

Modified: trunk/blender/source/blender/editors/gpencil/gpencil_paint.c
===================================================================
--- trunk/blender/source/blender/editors/gpencil/gpencil_paint.c	2011-01-03 19:45:08 UTC (rev 34050)
+++ trunk/blender/source/blender/editors/gpencil/gpencil_paint.c	2011-01-04 03:14:01 UTC (rev 34051)
@@ -141,17 +141,21 @@
 /* check if context is suitable for drawing */
 static int gpencil_draw_poll (bContext *C)
 {
-	if(ED_operator_regionactive(C)) {
+	if (ED_operator_regionactive(C)) {
 		/* check if current context can support GPencil data */
-		if(gpencil_data_get_pointers(C, NULL) != NULL) {
-			return 1;
+		if (gpencil_data_get_pointers(C, NULL) != NULL) {
+			/* check if Grease Pencil isn't already running */
+			if ((G.f & G_GREASEPENCIL) == 0)
+				return 1;
+			else
+				CTX_wm_operator_poll_msg_set(C, "Grease Pencil operator is already active");
 		}
 		else {
-			CTX_wm_operator_poll_msg_set(C, "failed to find grease pencil data to draw into");
+			CTX_wm_operator_poll_msg_set(C, "Failed to find Grease Pencil data to draw into");
 		}
 	}
 	else {
-		CTX_wm_operator_poll_msg_set(C, "active region not set");
+		CTX_wm_operator_poll_msg_set(C, "Active region not set");
 	}
 	
 	return 0;
@@ -161,7 +165,7 @@
 static int 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))) ? 1:0;
+	return ((gpd->sbuffer_sflag & GP_STROKE_3DSPACE) && (p->gpd->flag & (GP_DATA_DEPTH_VIEW | GP_DATA_DEPTH_STROKE)));
 }
 
 /* ******************************************* */
@@ -1015,9 +1019,6 @@
 	/* set edit flags - so that buffer will get drawn */
 	G.f |= G_GREASEPENCIL;
 	
-	/* set initial run flag */
-	p->flags |= GP_PAINTFLAG_FIRSTRUN;
-	
 	/* clear out buffer (stored in gp-data), in case something contaminated it */
 	gp_session_validatebuffer(p);
 	
@@ -1080,6 +1081,9 @@
 	p->paintmode= paintmode;
 	if (p->paintmode == GP_PAINTMODE_ERASER)
 		p->gpd->sbuffer_sflag |= GP_STROKE_ERASER;
+		
+	/* set 'initial run' flag, which is only used to denote when a new stroke is starting */
+	p->flags |= GP_PAINTFLAG_FIRSTRUN;
 	
 	/* check if points will need to be made in view-aligned space */
 	if (p->gpd->flag & GP_DATA_VIEWALIGN) {
@@ -1236,7 +1240,7 @@
 	}
 	
 	/* cleanup */
-	if(gpencil_project_check(p)) {
+	if (gpencil_project_check(p)) {
 		View3D *v3d= p->sa->spacedata.first;
 		

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list