Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2018-09-18 09:10:07 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-09-18 09:15:06 +0300
commitd421adb83e8d39bd9d74ea3d526326b70e93c341 (patch)
tree4c5e16b5e2fcd8c587204aa85dde175a6951392a /source
parent0a3b66cfb573a91ba3b19f30ead4a026bdfa6873 (diff)
Gizmo: de-duplicate poll logic
Checking the active tool or operator was a common way to check if the gizmo was still in use.
Diffstat (limited to 'source')
-rw-r--r--source/blender/editors/include/ED_gizmo_utils.h42
-rw-r--r--source/blender/editors/mesh/editmesh_add_gizmo.c8
-rw-r--r--source/blender/editors/mesh/editmesh_bisect.c8
-rw-r--r--source/blender/editors/mesh/editmesh_extrude.c17
-rw-r--r--source/blender/editors/mesh/editmesh_extrude_spin_gizmo.c24
-rw-r--r--source/blender/editors/space_view3d/view3d_gizmo_preselect.c29
-rw-r--r--source/blender/editors/space_view3d/view3d_gizmo_ruler.c15
-rw-r--r--source/blender/editors/transform/transform_gizmo_3d.c17
-rw-r--r--source/blender/editors/util/CMakeLists.txt4
-rw-r--r--source/blender/editors/util/gizmo_utils.c64
10 files changed, 130 insertions, 98 deletions
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, tref_rt->gizmo_group))
- {
- WM_gizmo_group_type_unlink_delayed_ptr(gzgt);
- return false;
- }
- return true;
-}
-
static void WIDGETGROUP_ruler_setup(const bContext *C, wmGizmoGroup *gzgroup)
{
RulerInfo *ruler_info = MEM_callocN(sizeof(RulerInfo), __func__);
@@ -1015,7 +1004,7 @@ void VIEW3D_GGT_ruler(wmGizmoGroupType *gzgt)
gzgt->gzmap_params.spaceid = SPACE_VIEW3D;
gzgt->gzmap_params.regionid = RGN_TYPE_WINDOW;
- gzgt->poll = WIDGETGROUP_ruler_poll;
+ gzgt->poll = ED_gizmo_poll_or_unlink_delayed_from_tool;
gzgt->setup = WIDGETGROUP_ruler_setup;
}
diff --git a/source/blender/editors/transform/transform_gizmo_3d.c b/source/blender/editors/transform/transform_gizmo_3d.c
index 36af5eaf5f1..577e899a40f 100644
--- a/source/blender/editors/transform/transform_gizmo_3d.c
+++ b/source/blender/editors/transform/transform_gizmo_3d.c
@@ -76,6 +76,7 @@
#include "ED_gpencil.h"
#include "ED_screen.h"
#include "ED_gizmo_library.h"
+#include "ED_gizmo_utils.h"
#include "UI_resources.h"
@@ -1669,15 +1670,9 @@ static void WIDGETGROUP_gizmo_draw_prepare(const bContext *C, wmGizmoGroup *gzgr
static bool WIDGETGROUP_gizmo_poll(const struct bContext *C, struct wmGizmoGroupType *gzgt)
{
- /* it's a given we only use this in 3D view */
- 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);
+ if (!ED_gizmo_poll_or_unlink_delayed_from_tool(C, gzgt)) {
return false;
}
-
View3D *v3d = CTX_wm_view3d(C);
if (v3d->gizmo_flag & (V3D_GIZMO_HIDE | V3D_GIZMO_HIDE_TOOL)) {
return false;
@@ -1719,9 +1714,11 @@ struct XFormCageWidgetGroup {
static bool WIDGETGROUP_xform_cage_poll(const bContext *C, wmGizmoGroupType *gzgt)
{
- bToolRef_Runtime *tref_rt = WM_toolsystem_runtime_from_context((bContext *)C);
- if (!STREQ(gzgt->idname, tref_rt->gizmo_group)) {
- WM_gizmo_group_type_unlink_delayed_ptr(gzgt);
+ if (!ED_gizmo_poll_or_unlink_delayed_from_tool(C, gzgt)) {
+ return false;
+ }
+ View3D *v3d = CTX_wm_view3d(C);
+ if (v3d->gizmo_flag & (V3D_GIZMO_HIDE | V3D_GIZMO_HIDE_TOOL)) {
return false;
}
return true;
diff --git a/source/blender/editors/util/CMakeLists.txt b/source/blender/editors/util/CMakeLists.txt
index 4321365fb4f..82fced0a3c7 100644
--- a/source/blender/editors/util/CMakeLists.txt
+++ b/source/blender/editors/util/CMakeLists.txt
@@ -40,9 +40,10 @@ set(INC_SYS
)
set(SRC
- keymap_templates.c
ed_transverts.c
ed_util.c
+ gizmo_utils.c
+ keymap_templates.c
numinput.c
select_utils.c
@@ -57,6 +58,7 @@ set(SRC
../include/ED_datafiles.h
../include/ED_fileselect.h
../include/ED_gizmo_library.h
+ ../include/ED_gizmo_utils.h
../include/ED_gpencil.h
../include/ED_image.h
../include/ED_info.h
diff --git a/source/blender/editors/util/gizmo_utils.c b/source/blender/editors/util/gizmo_utils.c
new file mode 100644
index 00000000000..957ae221b0b
--- /dev/null
+++ b/source/blender/editors/util/gizmo_utils.c
@@ -0,0 +1,64 @@
+/*
+ * ***** 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 gizmo_utils.c
+ * \ingroup edutil
+ *
+ * \name Generic Gizmo Utilities.
+ */
+
+#include <string.h>
+
+#include "BLI_utildefines.h"
+
+#include "BKE_context.h"
+
+#include "DNA_workspace_types.h"
+
+#include "WM_types.h"
+#include "WM_api.h"
+#include "WM_toolsystem.h"
+
+#include "ED_gizmo_utils.h"
+
+bool ED_gizmo_poll_or_unlink_delayed_from_operator(
+ const bContext *C, wmGizmoGroupType *gzgt,
+ const char *idname)
+{
+ wmOperator *op = WM_operator_last_redo(C);
+ if (op == NULL || !STREQ(op->type->idname, idname)) {
+ WM_gizmo_group_type_unlink_delayed_ptr(gzgt);
+ return false;
+ }
+ return true;
+}
+
+/** Can use this as poll function directly. */
+bool ED_gizmo_poll_or_unlink_delayed_from_tool(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;
+}