[Bf-blender-cvs] [bb45d48] GPencil_EditStrokes: GPencil Editing: "Stroke Edit Mode"

Joshua Leung noreply at git.blender.org
Wed Oct 22 15:42:22 CEST 2014


Commit: bb45d48c1b91052d5d223cabfacf90dd8f4eeaf4
Author: Joshua Leung
Date:   Thu Oct 23 02:11:25 2014 +1300
Branches: GPencil_EditStrokes
https://developer.blender.org/rBbb45d48c1b91052d5d223cabfacf90dd8f4eeaf4

GPencil Editing: "Stroke Edit Mode"

Changed the way that the keybindings for the editing tools for strokes work,
to be less clunky to work with.

Now, instead of holding down DKEY, you instead enter "Stroke Edit Mode" (via
a toggle button in the "Edit Strokes" button in the toolbar). This enables a
keymap (Grease Pencil Stroke Edit Mode) which is only active when this setting
is enabled; the keybindings in this keymap are designed so that pressing the
normal hotkeys will affect the strokes as expected (instead of whatever else
may be in the viewport at the time instead).

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

M	release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M	source/blender/editors/gpencil/gpencil_ops.c
M	source/blender/editors/screen/area.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 2864cc5..8bb240c 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -89,15 +89,25 @@ class GreasePencilStrokeEditPanel():
     bl_category = "Grease Pencil"
     bl_region_type = 'TOOLS'
 
+    @classmethod
+    def poll(cls, context):
+        return (context.gpencil_data is not None)
+
     @staticmethod
     def draw(self, context):
         layout = self.layout
 
+        gpd = context.gpencil_data
+        edit_ok = context.editable_gpencil_strokes and gpd.use_stroke_edit_mode
+
         col = layout.column(align=True)
+        col.prop(gpd, "use_stroke_edit_mode", text="Enable Edit Mode", icon='EDIT', toggle=True)
+
+        col.separator()
 
         col.label(text="Select:")
         subcol = col.column(align=True)
-        subcol.active = bool(context.editable_gpencil_strokes)
+        subcol.active = edit_ok
         subcol.operator("gpencil.select_all", text="Select All")
         subcol.operator("gpencil.select_circle")
 
@@ -105,14 +115,14 @@ class GreasePencilStrokeEditPanel():
 
         col.label(text="Edit:")
         subcol = col.column(align=True)
-        subcol.active = bool(context.editable_gpencil_strokes)
+        subcol.active = edit_ok
         subcol.operator("gpencil.strokes_duplicate", text="Duplicate")
         subcol.operator("transform.mirror", text="Mirror").gpencil_strokes = True
 
         col.separator()
 
         subcol = col.column(align=True)
-        subcol.active = bool(context.editable_gpencil_strokes)
+        subcol.active = edit_ok
         subcol.operator("transform.translate").gpencil_strokes = True   # icon='MAN_TRANS'
         subcol.operator("transform.rotate").gpencil_strokes = True      # icon='MAN_ROT'
         subcol.operator("transform.resize", text="Scale").gpencil_strokes = True      # icon='MAN_SCALE'
diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index 5a98f0f..8d7fbc9 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -36,6 +36,10 @@
 
 #include "BLI_blenlib.h"
 
+#include "BKE_context.h"
+
+#include "DNA_gpencil_types.h"
+
 #include "WM_api.h"
 #include "WM_types.h"
 
@@ -47,9 +51,10 @@
 #include "gpencil_intern.h"
 
 /* ****************************************** */
-/* Generic Editing Keymap */
+/* Grease Pencil Keymaps */
 
-void ED_keymap_gpencil(wmKeyConfig *keyconf)
+/* Generic Drawing Keymap */
+static void ed_keymap_gpencil_general(wmKeyConfig *keyconf)
 {
 	wmKeyMap *keymap = WM_keymap_find(keyconf, "Grease Pencil", 0, 0);
 	wmKeyMapItem *kmi;
@@ -71,49 +76,80 @@ void ED_keymap_gpencil(wmKeyConfig *keyconf)
 	kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_draw", RIGHTMOUSE, KM_PRESS, 0, DKEY);
 	RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_ERASER);
 	
+	
+	/* Menus --------------------------------------- */
+	
+	/* Pie Menu - For standard tools */
+	WM_keymap_add_menu_pie(keymap, "GPENCIL_PIE_tool_palette", DKEY, KM_DBL_CLICK, 0, 0);
+}
+
+/* ==================== */
+
+/* Poll callback for stroke editing mode */
+static int gp_stroke_editmode_poll(bContext *C)
+{
+	bGPdata *gpd = CTX_data_gpencil_data(C);
+	return (gpd && (gpd->flag & GP_DATA_STROKE_EDITMODE));
+}
+
+/* Stroke Editing Keymap - Only when editmode is enabled */
+static void ed_keymap_gpencil_editing(wmKeyConfig *keyconf)
+{
+	wmKeyMap *keymap = WM_keymap_find(keyconf, "Grease Pencil Stroke Edit Mode", 0, 0);
+	wmKeyMapItem *kmi;
+	
+	/* set poll callback - so that this keymap only gets enabled when stroke editmode is enabled */
+	keymap->poll = gp_stroke_editmode_poll;
+	
 	/* Selection ------------------------------------- */
 	/* select all */
-	kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_select_all", AKEY, KM_PRESS, 0, DKEY);
+	kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_select_all", AKEY, KM_PRESS, 0, 0);
 	RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE);
 	
-	// XXX? This is quite awkward to use...
-	kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_select_all", IKEY, KM_PRESS, KM_CTRL, DKEY);
+	kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0);
 	RNA_enum_set(kmi->ptr, "action", SEL_INVERT);
 	
 	/* circle select */
-	WM_keymap_add_item(keymap, "GPENCIL_OT_select_circle", CKEY, KM_PRESS, 0, DKEY);
+	WM_keymap_add_item(keymap, "GPENCIL_OT_select_circle", CKEY, KM_PRESS, 0, 0);
 	
 	/* normal select */
-	//WM_keymap_add_item(keymap, "GPENCIL_OT_select", RIGHTMOUSE, KM_PRESS, 0, DKEY);
+	WM_keymap_add_item(keymap, "GPENCIL_OT_select", SELECTMOUSE, KM_PRESS, 0, 0);
 	
-	kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_select", RIGHTMOUSE, KM_PRESS, KM_SHIFT, DKEY);
+	kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
 	RNA_boolean_set(kmi->ptr, "extend", true);
 	RNA_boolean_set(kmi->ptr, "toggle", true);
 	
 	/* whole stroke select */
-	kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_select", WKEY, KM_PRESS, 0, DKEY);
+	kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_select", SELECTMOUSE, KM_PRESS, KM_ALT, 0);
 	RNA_boolean_set(kmi->ptr, "entire_strokes", true);
 	
 	
 	/* Editing ----------------------------------------- */
-	WM_keymap_add_item(keymap, "GPENCIL_OT_strokes_duplicate", EKEY, KM_PRESS, 0, DKEY);
 	
-	kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_translate", GKEY, KM_PRESS, 0, DKEY);
-	RNA_boolean_set(kmi->ptr, "gpencil_strokes", true);
+	/* duplicate and move selected points */
+	WM_keymap_add_item(keymap, "GPENCIL_OT_strokes_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0);
 	
-	kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_rotate", RKEY, KM_PRESS, 0, DKEY);
-	RNA_boolean_set(kmi->ptr, "gpencil_strokes", true);
 	
-	kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_resize", SKEY, KM_PRESS, 0, DKEY);
+	/* Transform Tools */
+	kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_translate", GKEY, KM_PRESS, 0, 0);
 	RNA_boolean_set(kmi->ptr, "gpencil_strokes", true);
 	
-	kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_mirror", MKEY, KM_PRESS, 0, DKEY);
+	kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_rotate", RKEY, KM_PRESS, 0, 0);
 	RNA_boolean_set(kmi->ptr, "gpencil_strokes", true);
 	
+	kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_resize", SKEY, KM_PRESS, 0, 0);
+	RNA_boolean_set(kmi->ptr, "gpencil_strokes", true);
 	
-	/* Pie Menu */
-	/* XXX: This is currently still experimental! */
-	WM_keymap_add_menu_pie(keymap, "GPENCIL_PIE_tool_palette", DKEY, KM_DBL_CLICK, 0, 0);
+	kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_mirror", MKEY, KM_PRESS, KM_CTRL, 0);
+	RNA_boolean_set(kmi->ptr, "gpencil_strokes", true);
+}
+
+/* ==================== */
+
+void ED_keymap_gpencil(wmKeyConfig *keyconf)
+{
+	ed_keymap_gpencil_general(keyconf);
+	ed_keymap_gpencil_editing(keyconf);
 }
 
 /* ****************************************** */
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index 901ab67..f6e2d5c 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -1351,8 +1351,18 @@ static void ed_default_handlers(wmWindowManager *wm, ScrArea *sa, ListBase *hand
 	}
 	if (flag & ED_KEYMAP_GPENCIL) {
 		/* grease pencil */
-		wmKeyMap *keymap = WM_keymap_find(wm->defaultconf, "Grease Pencil", 0, 0);
-		WM_event_add_keymap_handler(handlers, keymap);
+		/* NOTE: This is now 2 keymaps - One for basic functionality, 
+		 *       and one that only applies when "Edit Mode" is enabled 
+		 *       for strokes.
+		 *
+		 *       For now, it's easier to just include both, 
+		 *       since you hardly want one without the other.
+		 */
+		wmKeyMap *keymap_general = WM_keymap_find(wm->defaultconf, "Grease Pencil", 0, 0);
+		wmKeyMap *keymap_edit = WM_keymap_find(wm->defaultconf, "Grease Pencil Stroke Edit Mode", 0, 0);
+		
+		WM_event_add_keymap_handler(handlers, keymap_general);
+		WM_event_add_keymap_handler(handlers, keymap_edit);
 	}
 	if (flag & ED_KEYMAP_HEADER) {
 		/* standard keymap for headers regions */
diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h
index 3662302..b13d4c5 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -191,6 +191,9 @@ typedef enum eGPdata_Flag {
 	GP_DATA_DEPTH_STROKE = (1 << 6),
 
 	GP_DATA_DEPTH_STROKE_ENDPOINTS = (1 << 7),
+	
+	/* Stroke Editing Mode - Toggle to enable alternative keymap for easier editing of stroke points */
+	GP_DATA_STROKE_EDITMODE	= (1 << 8)
 } eGPdata_Flag;
 
 #endif /*  __DNA_GPENCIL_TYPES_H__ */
diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c
index da017b2..fe70c81 100644
--- a/source/blender/makesrna/intern/rna_gpencil.c
+++ b/source/blender/makesrna/intern/rna_gpencil.c
@@ -788,7 +788,13 @@ static void rna_def_gpencil_data(BlenderRNA *brna)
 	RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_DATA_DEPTH_STROKE_ENDPOINTS);
 	RNA_def_property_ui_text(prop, "Only Endpoints", "Only use the first and last parts of the stroke for snapping");
 	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
-
+	
+	prop = RNA_def_property(srna, "use_stroke_edit_mode", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_DATA_STROKE_EDITMODE);
+	RNA_def_property_ui_text(prop, "Stroke Edit Mode", "Enable alternative keymap to make editing stroke points easier");
+	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
+	
+	/* API Functions */
 	func = RNA_def_function(srna, "clear", "rna_GPencil_clear");
 	RNA_def_function_ui_description(func, "Remove all the grease pencil data");
 }




More information about the Bf-blender-cvs mailing list