[Bf-blender-cvs] [d421adb83e8] blender2.8: Gizmo: de-duplicate poll logic

Campbell Barton noreply at git.blender.org
Tue Sep 18 08:02:57 CEST 2018


Commit: d421adb83e8d39bd9d74ea3d526326b70e93c341
Author: Campbell Barton
Date:   Tue Sep 18 16:10:07 2018 +1000
Branches: blender2.8
https://developer.blender.org/rBd421adb83e8d39bd9d74ea3d526326b70e93c341

Gizmo: de-duplicate poll logic

Checking the active tool or operator was a common way to check
if the gizmo was still in use.

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

A	source/blender/editors/include/ED_gizmo_utils.h
M	source/blender/editors/mesh/editmesh_add_gizmo.c
M	source/blender/editors/mesh/editmesh_bisect.c
M	source/blender/editors/mesh/editmesh_extrude.c
M	source/blender/editors/mesh/editmesh_extrude_spin_gizmo.c
M	source/blender/editors/space_view3d/view3d_gizmo_preselect.c
M	source/blender/editors/space_view3d/view3d_gizmo_ruler.c
M	source/blender/editors/transform/transform_gizmo_3d.c
M	source/blender/editors/util/CMakeLists.txt
A	source/blender/editors/util/gizmo_utils.c

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

diff --git a/source/blender/editors/include/ED_gizmo_utils.h b/source/blender/editors/include/ED_gizmo_utils.h
new file mode 100644
index 00000000000..16b460f6ba5
--- /dev/null
+++ b/source/blender/editors/include/ED_gizmo_utils.h
@@ -0,0 +1,42 @@
+/*
+ * ***** 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.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file ED_gizmo_utils.h
+ *  \ingroup editors
+ *
+ * \name Generic Gizmo Utilities.
+ */
+
+#ifndef __ED_GIZMO_UTILS_H__
+#define __ED_GIZMO_UTILS_H__
+
+struct bContext;
+struct wmGizmoGroupType;
+
+/** Wrapper function (operator name can't be guessed). */
+bool ED_gizmo_poll_or_unlink_delayed_from_operator(
+        const struct bContext *C, struct wmGizmoGroupType *gzgt,
+        const char *idname);
+
+/** Use this as poll function directly for: #wmGizmoGroupType.poll */
+bool ED_gizmo_poll_or_unlink_delayed_from_tool(
+        const bContext *C, struct wmGizmoGroupType *gzgt);
+
+#endif  /* __ED_GIZMO_UTILS_H__ */
diff --git a/source/blender/editors/mesh/editmesh_add_gizmo.c b/source/blender/editors/mesh/editmesh_add_gizmo.c
index 38fc7d58dcf..d56d9513fc8 100644
--- a/source/blender/editors/mesh/editmesh_add_gizmo.c
+++ b/source/blender/editors/mesh/editmesh_add_gizmo.c
@@ -35,6 +35,7 @@
 #include "BKE_editmesh.h"
 
 #include "ED_gizmo_library.h"
+#include "ED_gizmo_utils.h"
 #include "ED_mesh.h"
 #include "ED_object.h"
 #include "ED_screen.h"
@@ -199,12 +200,7 @@ static void gizmo_placement_prop_matrix_set(
 
 static bool gizmo_mesh_placement_poll(const bContext *C, wmGizmoGroupType *gzgt)
 {
-	wmOperator *op = WM_operator_last_redo(C);
-	if (op == NULL || !STREQ(op->type->idname, "MESH_OT_primitive_cube_add_gizmo")) {
-		WM_gizmo_group_type_unlink_delayed_ptr(gzgt);
-		return false;
-	}
-	return true;
+	return ED_gizmo_poll_or_unlink_delayed_from_operator(C, gzgt, "MESH_OT_primitive_cube_add_gizmo");
 }
 
 static void gizmo_mesh_placement_modal_from_setup(
diff --git a/source/blender/editors/mesh/editmesh_bisect.c b/source/blender/editors/mesh/editmesh_bisect.c
index e35e97c0054..7aedd776b5d 100644
--- a/source/blender/editors/mesh/editmesh_bisect.c
+++ b/source/blender/editors/mesh/editmesh_bisect.c
@@ -50,6 +50,7 @@
 #include "ED_mesh.h"
 #include "ED_screen.h"
 #include "ED_view3d.h"
+#include "ED_gizmo_utils.h"
 
 #include "UI_resources.h"
 
@@ -642,12 +643,7 @@ static void gizmo_bisect_prop_angle_set(
 
 static bool gizmo_mesh_bisect_poll(const bContext *C, wmGizmoGroupType *gzgt)
 {
-	wmOperator *op = WM_operator_last_redo(C);
-	if (op == NULL || !STREQ(op->type->idname, "MESH_OT_bisect")) {
-		WM_gizmo_group_type_unlink_delayed_ptr(gzgt);
-		return false;
-	}
-	return true;
+	return ED_gizmo_poll_or_unlink_delayed_from_operator(C, gzgt, "MESH_OT_bisect");
 }
 
 static void gizmo_mesh_bisect_setup(const bContext *C, wmGizmoGroup *gzgroup)
diff --git a/source/blender/editors/mesh/editmesh_extrude.c b/source/blender/editors/mesh/editmesh_extrude.c
index d1050f1122f..c66999b135e 100644
--- a/source/blender/editors/mesh/editmesh_extrude.c
+++ b/source/blender/editors/mesh/editmesh_extrude.c
@@ -54,6 +54,7 @@
 #include "ED_transform.h"
 #include "ED_view3d.h"
 #include "ED_gizmo_library.h"
+#include "ED_gizmo_utils.h"
 
 #include "UI_resources.h"
 
@@ -417,20 +418,6 @@ static void gizmo_mesh_extrude_orientation_matrix_set(
 	}
 }
 
-static bool gizmo_mesh_extrude_poll(const bContext *C, wmGizmoGroupType *gzgt)
-{
-	ScrArea *sa = CTX_wm_area(C);
-	bToolRef_Runtime *tref_rt = sa->runtime.tool ? sa->runtime.tool->runtime : NULL;
-	if ((tref_rt == NULL) ||
-	    !STREQ(gzgt->idname, tref_rt->gizmo_group) ||
-	    !ED_operator_editmesh_view3d((bContext *)C))
-	{
-		WM_gizmo_group_type_unlink_delayed_ptr(gzgt);
-		return false;
-	}
-	return true;
-}
-
 static void gizmo_mesh_extrude_setup(const bContext *UNUSED(C), wmGizmoGroup *gzgroup)
 {
 	struct GizmoExtrudeGroup *ggd = MEM_callocN(sizeof(GizmoExtrudeGroup), __func__);
@@ -687,7 +674,7 @@ static void MESH_GGT_extrude(struct wmGizmoGroupType *gzgt)
 	gzgt->gzmap_params.spaceid = SPACE_VIEW3D;
 	gzgt->gzmap_params.regionid = RGN_TYPE_WINDOW;
 
-	gzgt->poll = gizmo_mesh_extrude_poll;
+	gzgt->poll = ED_gizmo_poll_or_unlink_delayed_from_tool;
 	gzgt->setup = gizmo_mesh_extrude_setup;
 	gzgt->refresh = gizmo_mesh_extrude_refresh;
 	gzgt->draw_prepare = gizmo_mesh_extrude_draw_prepare;
diff --git a/source/blender/editors/mesh/editmesh_extrude_spin_gizmo.c b/source/blender/editors/mesh/editmesh_extrude_spin_gizmo.c
index 800e679b8a9..bba5be4ba7d 100644
--- a/source/blender/editors/mesh/editmesh_extrude_spin_gizmo.c
+++ b/source/blender/editors/mesh/editmesh_extrude_spin_gizmo.c
@@ -32,6 +32,7 @@
 #include "WM_types.h"
 #include "WM_message.h"
 
+#include "ED_gizmo_utils.h"
 #include "ED_screen.h"
 #include "ED_view3d.h"
 
@@ -67,20 +68,6 @@ typedef struct GizmoGroupData_SpinInit {
 	} data;
 } GizmoGroupData_SpinInit;
 
-static bool gizmo_mesh_spin_init_poll(const bContext *C, wmGizmoGroupType *gzgt)
-{
-	ScrArea *sa = CTX_wm_area(C);
-	bToolRef_Runtime *tref_rt = sa->runtime.tool ? sa->runtime.tool->runtime : NULL;
-	if ((tref_rt == NULL) ||
-	    !STREQ(gzgt->idname, tref_rt->gizmo_group) ||
-	    !ED_operator_editmesh_view3d((bContext *)C))
-	{
-		WM_gizmo_group_type_unlink_delayed_ptr(gzgt);
-		return false;
-	}
-	return true;
-}
-
 static void gizmo_mesh_spin_init_setup(const bContext *UNUSED(C), wmGizmoGroup *gzgroup)
 {
 	/* alpha values for normal/highlighted states */
@@ -241,7 +228,7 @@ void MESH_GGT_spin(struct wmGizmoGroupType *gzgt)
 	gzgt->gzmap_params.spaceid = SPACE_VIEW3D;
 	gzgt->gzmap_params.regionid = RGN_TYPE_WINDOW;
 
-	gzgt->poll = gizmo_mesh_spin_init_poll;
+	gzgt->poll = ED_gizmo_poll_or_unlink_delayed_from_tool;
 	gzgt->setup = gizmo_mesh_spin_init_setup;
 	gzgt->refresh = gizmo_mesh_spin_init_refresh;
 	gzgt->message_subscribe = gizmo_mesh_spin_init_message_subscribe;
@@ -506,12 +493,7 @@ static void gizmo_spin_prop_angle_set(
 
 static bool gizmo_mesh_spin_redo_poll(const bContext *C, wmGizmoGroupType *gzgt)
 {
-	wmOperator *op = WM_operator_last_redo(C);
-	if (op == NULL || !STREQ(op->type->idname, "MESH_OT_spin")) {
-		WM_gizmo_group_type_unlink_delayed_ptr(gzgt);
-		return false;
-	}
-	return true;
+	return ED_gizmo_poll_or_unlink_delayed_from_operator(C, gzgt, "MESH_OT_spin");
 }
 
 
diff --git a/source/blender/editors/space_view3d/view3d_gizmo_preselect.c b/source/blender/editors/space_view3d/view3d_gizmo_preselect.c
index 7987134e84b..7b8e3a76c85 100644
--- a/source/blender/editors/space_view3d/view3d_gizmo_preselect.c
+++ b/source/blender/editors/space_view3d/view3d_gizmo_preselect.c
@@ -30,6 +30,7 @@
 
 #include "BKE_context.h"
 
+#include "ED_gizmo_utils.h"
 #include "ED_screen.h"
 
 #include "UI_resources.h"
@@ -49,18 +50,6 @@ struct GizmoGroupPreSelElem {
 	wmGizmo *gizmo;
 };
 
-static bool WIDGETGROUP_mesh_preselect_elem_poll(const bContext *C, wmGizmoGroupType *gzgt)
-{
-	bToolRef_Runtime *tref_rt = WM_toolsystem_runtime_from_context((bContext *)C);
-	if ((tref_rt == NULL) ||
-	    !STREQ(gzgt->idname, tref_rt->gizmo_group))
-	{
-		WM_gizmo_group_type_unlink_delayed_ptr(gzgt);
-		return false;
-	}
-	return true;
-}
-
 static void WIDGETGROUP_mesh_preselect_elem_setup(const bContext *UNUSED(C), wmGizmoGroup *gzgroup)
 {
 	const wmGizmoType *gzt_presel = WM_gizmotype_find("GIZMO_GT_mesh_preselect_elem_3d", true);
@@ -82,7 +71,7 @@ void VIEW3D_GGT_mesh_preselect_elem(wmGizmoGroupType *gzgt)
 	gzgt->gzmap_params.spaceid = SPACE_VIEW3D;
 	gzgt->gzmap_params.regionid = RGN_TYPE_WINDOW;
 
-	gzgt->poll = WIDGETGROUP_mesh_preselect_elem_poll;
+	gzgt->poll = ED_gizmo_poll_or_unlink_delayed_from_tool;
 	gzgt->setup = WIDGETGROUP_mesh_preselect_elem_setup;
 }
 
@@ -97,18 +86,6 @@ struct GizmoGroupPreSelEdgeRing {
 	wmGizmo *gizmo;
 };
 
-static bool WIDGETGROUP_mesh_preselect_edgering_poll(const bContext *C, wmGizmoGroupType *gzgt)
-{
-	bToolRef_Runtime *tref_rt = WM_toolsystem_runtime_from_context((bContext *)C);
-	if ((tref_rt == NULL) ||
-	    !STREQ(gzgt->idname, tref_rt->gizmo_group))
-	{
-		WM_gizmo_group_type_unlink_delayed_ptr(gzgt);
-		return false;
-	}
-	return true;
-}
-
 static void WIDGETGROUP_mesh_preselect_edgering_setup(const bContext *UNUSED(C), wmGizmoGroup *gzgroup)
 {
 	const wmGizmoType *gzt_presel = WM_gizmotype_find("GIZMO_GT_mesh_preselect_edgering_3d", true);
@@ -130,7 +107,7 @@ void VIEW3D_GGT_mesh_preselect_edgering(wmGizmoGroupType *gzgt)
 	gzgt->gzmap_params.spaceid = SPACE_VIEW3D;
 	gzgt->gzmap_params.regionid = RGN_TYPE_WINDOW;
 
-	gzgt->poll = WIDGETGROUP_mesh_preselect_edgering_poll;
+	gzgt->poll = ED_gizmo_poll_or_unlink_delayed_from_tool;
 	gzgt->setup = WIDGETGROUP_mesh_preselect_edgering_setup;
 }
 
diff --git a/source/blender/editors/space_view3d/view3d_gizmo_ruler.c b/source/blender/editors/space_view3d/view3d_gizmo_ruler.c
index 6bb6a022a82..62f66334516 100644
--- a/source/blender/editors/space_view3d/view3d_gizmo_ruler.c
+++ b/source/blender/editors/space_view3d/view3d_gizmo_ruler.c
@@ -45,6 +45,7 @@
 
 #include "BIF_gl.h"
 
+#include "ED_gizmo_utils.h"
 #include "ED_gpencil.h"
 #include "ED_screen.h"
 #include "ED_transform_snap_object_context.h"
@@ -975,18 +976,6 @@ void VIEW3D_GT_ruler_item(wmGizmoType *gzt)
 /** \name Ruler Gizmo Group
  * \{ */
 
-static bool WIDGETGROUP_ruler_poll(const bContext *C, wmGizmoGroupType *gzgt)
-{
-	bToolRef_Runtime *tref_rt = WM_toolsystem_runtime_from_context((bContext *)C);
-	if ((tref_rt == NULL) ||
-	    !STREQ(gzgt->idname, tr

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list