[Bf-blender-cvs] [06e188a] GPencil_EditStrokes: GPencil Strokes: Select All Operator

Joshua Leung noreply at git.blender.org
Sun Sep 28 17:26:53 CEST 2014


Commit: 06e188adb7d17d0ea86f79108307eee34aa1b1be
Author: Joshua Leung
Date:   Sat Sep 27 02:28:24 2014 +1200
Branches: GPencil_EditStrokes
https://developer.blender.org/rB06e188adb7d17d0ea86f79108307eee34aa1b1be

GPencil Strokes: Select All Operator

Added a "Select All" operator for Grease Pencil strokes which will
select all strokes on visible layers.

Usage:
* <D> A      = Select All  (i.e. hold down D and press A)
* <D> Ctrl I = Invert All  (NOTE: this one may be removed, as it's quite awkward)

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

M	source/blender/editors/gpencil/gpencil_intern.h
M	source/blender/editors/gpencil/gpencil_ops.c
A	source/blender/editors/gpencil/gpencil_select.c
M	source/blender/editors/space_view3d/space_view3d.c

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

diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index 28eb135..3a9c812 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -52,6 +52,10 @@ typedef enum eGPencil_PaintModes {
 	GP_PAINTMODE_DRAW_POLY
 } eGPencil_PaintModes;
 
+/* stroke editing ----- */
+
+void GPENCIL_OT_select_all(struct wmOperatorType *ot);
+
 /* buttons editing --- */
 
 void GPENCIL_OT_data_add(struct wmOperatorType *ot);
diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index 75ff089..d6e009e 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -53,23 +53,31 @@ void ED_keymap_gpencil(wmKeyConfig *keyconf)
 	wmKeyMap *keymap = WM_keymap_find(keyconf, "Grease Pencil", 0, 0);
 	wmKeyMapItem *kmi;
 	
-	/* Draw */
-
+	/* Draw  --------------------------------------- */
 	/* draw */
 	kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_draw", LEFTMOUSE, KM_PRESS, 0, DKEY);
 	RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_DRAW);
-
+	
 	/* 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);
-
+	
 	/* draw - poly lines */
 	kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_draw", RIGHTMOUSE, KM_PRESS, KM_CTRL, DKEY);
 	RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_DRAW_POLY);
-
+	
 	/* erase */
 	kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_draw", RIGHTMOUSE, KM_PRESS, 0, DKEY);
 	RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_ERASER);
+	
+	/* Selection ------------------------------------- */
+	/* select all */
+	kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_select_all", AKEY, KM_PRESS, 0, DKEY);
+	RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE);
+	
+	// XXX?
+	kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_select_all", IKEY, KM_PRESS, KM_CTRL, DKEY);
+	RNA_enum_set(kmi->ptr, "action", SEL_INVERT);
 }
 
 /* ****************************************** */
@@ -80,6 +88,10 @@ void ED_operatortypes_gpencil(void)
 	
 	WM_operatortype_append(GPENCIL_OT_draw);
 	
+	/* Editing (Strokes) ------------ */
+	
+	WM_operatortype_append(GPENCIL_OT_select_all);
+	
 	/* Editing (Buttons) ------------ */
 	
 	WM_operatortype_append(GPENCIL_OT_data_add);
diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c
new file mode 100644
index 0000000..039d9ca
--- /dev/null
+++ b/source/blender/editors/gpencil/gpencil_select.c
@@ -0,0 +1,168 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2014, Blender Foundation, Joshua Leung
+ * This is a new part of Blender
+ *
+ * Contributor(s): Joshua Leung
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/gpencil/gpencil_select.c
+ *  \ingroup edgpencil
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <math.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_math.h"
+#include "BLI_blenlib.h"
+#include "BLI_utildefines.h"
+
+#include "DNA_anim_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_space_types.h"
+#include "DNA_view3d_types.h"
+#include "DNA_gpencil_types.h"
+
+#include "BKE_context.h"
+#include "BKE_curve.h"
+#include "BKE_depsgraph.h"
+#include "BKE_fcurve.h"
+#include "BKE_global.h"
+#include "BKE_gpencil.h"
+#include "BKE_library.h"
+#include "BKE_object.h"
+#include "BKE_report.h"
+#include "BKE_scene.h"
+#include "BKE_screen.h"
+#include "BKE_tracking.h"
+
+#include "UI_interface.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "UI_view2d.h"
+
+#include "ED_gpencil.h"
+#include "ED_view3d.h"
+#include "ED_keyframing.h"
+
+#include "gpencil_intern.h"
+
+/* ********************************************** */
+/* Polling callbacks */
+
+static int gpencil_select_poll(bContext *C)
+{
+	bGPdata *gpd = ED_gpencil_data_get_active(C);
+	bGPDlayer *gpl = gpencil_layer_getactive(gpd);
+
+	/* only if there's an active layer with an active frame */
+	return (gpl && gpl->actframe);
+}
+
+/* ********************************************** */
+/* Select All Operator */
+
+static int gpencil_select_all_exec(bContext *C, wmOperator *op)
+{
+	bGPdata *gpd = ED_gpencil_data_get_active(C);
+	bGPDlayer *gpl;
+	int action = RNA_enum_get(op->ptr, "action");
+	
+	/* for "toggle", test for existing selected strokes */
+	if (action == SEL_TOGGLE) {
+		action = SEL_SELECT;
+		
+		for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+			if (!(gpl->flag & GP_LAYER_HIDE) && (gpl->actframe)) {
+				bGPDframe *gpf = gpl->actframe;
+				bGPDstroke *gps;
+				
+				for (gps = gpf->strokes.first; gps; gps = gps->next) {
+					if (gps->flag & GP_STROKE_SELECT) {
+						action = SEL_DESELECT;
+						break;
+					}
+				}
+			}
+			
+			if (action != SEL_SELECT)
+				break;
+		}
+	}
+	
+	/* select or deselect all strokes */
+	for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+		if (!(gpl->flag & GP_LAYER_HIDE) && (gpl->actframe)) {
+			bGPDframe *gpf = gpl->actframe;
+			bGPDstroke *gps;
+			
+			for (gps = gpf->strokes.first; gps; gps = gps->next) {
+				switch (action) {
+					case SEL_SELECT:	
+						gps->flag |= GP_STROKE_SELECT;
+						break;
+					case SEL_DESELECT:
+						gps->flag &= ~GP_STROKE_SELECT;
+						break;
+					case SEL_INVERT:
+						gps->flag ^= GP_STROKE_SELECT;
+						break;
+				}
+			}
+		}
+	}
+	
+	/* updates */
+	WM_event_add_notifier(C, NC_GPENCIL | NA_SELECTED, NULL);
+	return OPERATOR_FINISHED;
+}
+
+void GPENCIL_OT_select_all(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "(De)select All Strokes";
+	ot->idname = "GPENCIL_OT_select_all";
+	ot->description = "Change selection of all Grease Pencil strokes currently visible";
+	
+	/* callbacks */
+	ot->exec = gpencil_select_all_exec;
+	ot->poll = gpencil_select_poll;
+	
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+	
+	WM_operator_properties_select_all(ot);
+}
+
+/* ********************************************** */
+
+ 
\ No newline at end of file
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index 8b76ec3..3ab851e 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -957,8 +957,9 @@ static void view3d_main_area_listener(bScreen *sc, ScrArea *sa, ARegion *ar, wmN
 
 			break;
 		case NC_GPENCIL:
-			if (wmn->action == NA_EDITED)
+			if (ELEM(wmn->action, NA_EDITED, NA_SELECTED)) {
 				ED_region_tag_redraw(ar);
+			}
 			break;
 	}
 }




More information about the Bf-blender-cvs mailing list