[Bf-blender-cvs] [46c871b4aee] master: GP: Cleanup Paint Poll method

Antonioya noreply at git.blender.org
Wed Feb 13 16:48:50 CET 2019


Commit: 46c871b4aee88e43ce6677bafdea63839abf242a
Author: Antonioya
Date:   Wed Feb 13 16:48:16 2019 +0100
Branches: master
https://developer.blender.org/rB46c871b4aee88e43ce6677bafdea63839abf242a

GP: Cleanup Paint Poll method

The poll was checking things related to all annotations, but now the check must be only for grease pencil objects and 3D view.

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

M	source/blender/editors/gpencil/gpencil_paint.c

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

diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 4a1bfda2dfc..fdde5d16266 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -279,33 +279,33 @@ static bool gpencil_draw_poll(bContext *C)
 {
 	if (ED_operator_regionactive(C)) {
 		ScrArea *sa = CTX_wm_area(C);
-		if (!ELEM(sa->spacetype, SPACE_VIEW3D)) {
-			/* check if current context can support GPencil data */
-			if (ED_gpencil_data_get_pointers(C, NULL) != NULL) {
-				/* check if Grease Pencil isn't already running */
-				if (ED_gpencil_session_active() == 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");
-			}
-			return 0;
-		}
 		/* 3D Viewport */
-		else {
-			if (ED_gpencil_session_active() == 0) {
-				return 1;
-			}
-			else {
-				return 0;
-			}
+		if (sa->spacetype != SPACE_VIEW3D) {
+			return false;
+		}
+
+		/* check if Grease Pencil isn't already running */
+		if (ED_gpencil_session_active() != 0) {
+			CTX_wm_operator_poll_msg_set(C, "Grease Pencil operator is already active");
+			return false;
+		}
+
+		/* only grease pencil object type */
+		Object *ob = CTX_data_active_object(C);
+		if ((ob == NULL) || (ob->type != OB_GPENCIL)) {
+			return false;
+		}
+
+		bGPdata *gpd = (bGPdata *)ob->data;
+		if (!GPENCIL_PAINT_MODE(gpd)) {
+			return false;
 		}
+
+		return true;
 	}
 	else {
 		CTX_wm_operator_poll_msg_set(C, "Active region not set");
-		return 0;
+		return false;
 	}
 }
 
@@ -3178,28 +3178,25 @@ static int gpencil_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event
 	}
 
 	/* enable paint mode */
-	if (p->sa->spacetype == SPACE_VIEW3D) {
-
 		/* handle speed guide events before drawing inside view3d */
-		if (!ELEM(p->paintmode, GP_PAINTMODE_ERASER, GP_PAINTMODE_SET_CP)) {
-			gpencil_guide_event_handling(C, op, event, p);
-		}
-
-		Object *ob = CTX_data_active_object(C);
-		if (ob && (ob->type == OB_GPENCIL) && ((p->gpd->flag & GP_DATA_STROKE_PAINTMODE) == 0)) {
-			/* FIXME: use the mode switching operator, this misses notifiers, messages. */
-			/* Just set paintmode flag... */
-			p->gpd->flag |= GP_DATA_STROKE_PAINTMODE;
-			/* disable other GP modes */
-			p->gpd->flag &= ~GP_DATA_STROKE_EDITMODE;
-			p->gpd->flag &= ~GP_DATA_STROKE_SCULPTMODE;
-			p->gpd->flag &= ~GP_DATA_STROKE_WEIGHTMODE;
-			/* set workspace mode */
-			ob->restore_mode = ob->mode;
-			ob->mode = OB_MODE_PAINT_GPENCIL;
-			/* redraw mode on screen */
-			WM_event_add_notifier(C, NC_SCENE | ND_MODE, NULL);
-		}
+	if (!ELEM(p->paintmode, GP_PAINTMODE_ERASER, GP_PAINTMODE_SET_CP)) {
+		gpencil_guide_event_handling(C, op, event, p);
+	}
+
+	Object *ob = CTX_data_active_object(C);
+	if (ob && (ob->type == OB_GPENCIL) && ((p->gpd->flag & GP_DATA_STROKE_PAINTMODE) == 0)) {
+		/* FIXME: use the mode switching operator, this misses notifiers, messages. */
+		/* Just set paintmode flag... */
+		p->gpd->flag |= GP_DATA_STROKE_PAINTMODE;
+		/* disable other GP modes */
+		p->gpd->flag &= ~GP_DATA_STROKE_EDITMODE;
+		p->gpd->flag &= ~GP_DATA_STROKE_SCULPTMODE;
+		p->gpd->flag &= ~GP_DATA_STROKE_WEIGHTMODE;
+		/* set workspace mode */
+		ob->restore_mode = ob->mode;
+		ob->mode = OB_MODE_PAINT_GPENCIL;
+		/* redraw mode on screen */
+		WM_event_add_notifier(C, NC_SCENE | ND_MODE, NULL);
 	}
 
 	WM_event_add_notifier(C, NC_GPENCIL | NA_EDITED, NULL);



More information about the Bf-blender-cvs mailing list