[Bf-blender-cvs] [d2519c2aa1d] blender2.8: Gizmo: option to switch between normal/xyz widgets

Campbell Barton noreply at git.blender.org
Tue Oct 2 10:18:01 CEST 2018


Commit: d2519c2aa1ded2eedd12697c251ce74f20fb92e8
Author: Campbell Barton
Date:   Tue Oct 2 18:16:00 2018 +1000
Branches: blender2.8
https://developer.blender.org/rBd2519c2aa1ded2eedd12697c251ce74f20fb92e8

Gizmo: option to switch between normal/xyz widgets

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

M	release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
M	source/blender/editors/mesh/editmesh_extrude_gizmo.c

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

diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index 48ec56c3927..8abf988c946 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -681,6 +681,9 @@ class _defs_edit_mesh:
 
     @ToolDef.from_fn
     def extrude():
+        def draw_settings(context, layout, tool):
+            props = tool.gizmo_group_properties("MESH_GGT_extrude")
+            layout.prop(props, "axis_type", expand=True)
         return dict(
             text="Extrude Region",
             icon="ops.mesh.extrude_region_move",
@@ -691,6 +694,7 @@ class _defs_edit_mesh:
                  dict(TRANSFORM_OT_translate=dict(release_confirm=True)),
                  dict(type='EVT_TWEAK_A', value='ANY')),
             ),
+            draw_settings=draw_settings,
         )
 
     @ToolDef.from_fn
diff --git a/source/blender/editors/mesh/editmesh_extrude_gizmo.c b/source/blender/editors/mesh/editmesh_extrude_gizmo.c
index 88f5ad95d70..63c3d326942 100644
--- a/source/blender/editors/mesh/editmesh_extrude_gizmo.c
+++ b/source/blender/editors/mesh/editmesh_extrude_gizmo.c
@@ -36,10 +36,12 @@
 #include "BKE_global.h"
 
 #include "RNA_access.h"
+#include "RNA_define.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
 #include "WM_message.h"
+#include "WM_toolsystem.h"
 
 #include "ED_screen.h"
 #include "ED_transform.h"
@@ -57,6 +59,11 @@
 /** \name Extrude Gizmo
  * \{ */
 
+enum {
+	EXTRUDE_AXIS_NORMAL = 0,
+	EXTRUDE_AXIS_XYZ = 1,
+};
+
 static const float extrude_button_scale = 0.15f;
 static const float extrude_button_offset_scale = 1.5f;
 static const float extrude_arrow_scale = 1.0f;
@@ -84,6 +91,7 @@ typedef struct GizmoExtrudeGroup {
 	} data;
 
 	wmOperatorType *ot_extrude;
+	PropertyRNA *gzgt_axis_type_prop;
 } GizmoExtrudeGroup;
 
 static void gizmo_mesh_extrude_orientation_matrix_set(
@@ -132,7 +140,10 @@ static void gizmo_mesh_extrude_setup(const bContext *UNUSED(C), wmGizmoGroup *gz
 		}
 	}
 
-	ggd->ot_extrude = WM_operatortype_find("MESH_OT_extrude_context_move", true);
+	{
+		ggd->ot_extrude = WM_operatortype_find("MESH_OT_extrude_context_move", true);
+		ggd->gzgt_axis_type_prop = RNA_struct_type_find_property(gzgroup->type->srna, "axis_type");
+	}
 
 	for (int i = 0; i < 3; i++) {
 		UI_GetThemeColor3fv(TH_AXIS_X + i, ggd->invoke_xyz_no[i]->color);
@@ -195,8 +206,19 @@ static void gizmo_mesh_extrude_refresh(const bContext *C, wmGizmoGroup *gzgroup)
 	}
 
 	Scene *scene = CTX_data_scene(C);
+
+	int axis_type;
+	{
+		PointerRNA ptr;
+		bToolRef *tref = WM_toolsystem_ref_from_context((bContext *)C);
+		WM_toolsystem_ref_properties_ensure_from_gizmo_group(tref, gzgroup->type, &ptr);
+		axis_type = RNA_property_enum_get(&ptr, ggd->gzgt_axis_type_prop);
+	}
+
 	ggd->data.orientation_type = scene->orientation_type;
-	bool use_normal = (ggd->data.orientation_type != V3D_MANIP_NORMAL);
+	const bool use_normal = (
+	        (ggd->data.orientation_type != V3D_MANIP_NORMAL) ||
+	        (axis_type == EXTRUDE_AXIS_NORMAL));
 	const int axis_len_used = use_normal ? 4 : 3;
 
 	struct TransformBounds tbounds;
@@ -301,6 +323,18 @@ static void gizmo_mesh_extrude_refresh(const bContext *C, wmGizmoGroup *gzgroup)
 		        (ggd->adjust_xyz_no[i]->flag & WM_GIZMO_HIDDEN) ?
 		        ED_GIZMO_BUTTON_SHOW_HELPLINE : 0);
 	}
+
+	/* TODO: skip calculating axis which wont be used (above). */
+	switch (axis_type) {
+		case EXTRUDE_AXIS_NORMAL:
+			for (int i = 0; i < 3; i++) {
+				WM_gizmo_set_flag(ggd->invoke_xyz_no[i], WM_GIZMO_HIDDEN, true);
+			}
+			break;
+		case EXTRUDE_AXIS_XYZ:
+			WM_gizmo_set_flag(ggd->invoke_xyz_no[3], WM_GIZMO_HIDDEN, true);
+			break;
+	}
 }
 
 static int gizmo_cmp_temp_f(const void *gz_a_ptr, const void *gz_b_ptr)
@@ -340,6 +374,7 @@ static void gizmo_mesh_extrude_draw_prepare(const bContext *C, wmGizmoGroup *gzg
 static void gizmo_mesh_extrude_message_subscribe(
         const bContext *C, wmGizmoGroup *gzgroup, struct wmMsgBus *mbus)
 {
+	GizmoExtrudeGroup *ggd = gzgroup->customdata;
 	ARegion *ar = CTX_wm_region(C);
 
 	/* Subscribe to view properties */
@@ -353,6 +388,14 @@ static void gizmo_mesh_extrude_message_subscribe(
 		WM_msg_subscribe_rna_anon_prop(mbus, Scene, transform_orientation, &msg_sub_value_gz_tag_refresh);
 	}
 
+
+	WM_msg_subscribe_rna_params(
+	        mbus,
+	        &(const wmMsgParams_RNA){
+	            .ptr = (PointerRNA){.type = gzgroup->type->srna},
+	            .prop = ggd->gzgt_axis_type_prop,
+	        },
+	        &msg_sub_value_gz_tag_refresh, __func__);
 }
 
 void MESH_GGT_extrude(struct wmGizmoGroupType *gzgt)
@@ -370,6 +413,13 @@ void MESH_GGT_extrude(struct wmGizmoGroupType *gzgt)
 	gzgt->refresh = gizmo_mesh_extrude_refresh;
 	gzgt->draw_prepare = gizmo_mesh_extrude_draw_prepare;
 	gzgt->message_subscribe = gizmo_mesh_extrude_message_subscribe;
+
+	static const EnumPropertyItem axis_type_items[] = {
+		{EXTRUDE_AXIS_NORMAL, "NORMAL", 0, "Normal", "Only show normal axis"},
+		{EXTRUDE_AXIS_XYZ, "XYZ", 0, "XYZ", "Follow scene orientation"},
+		{0, NULL, 0, NULL, NULL}
+	};
+	RNA_def_enum(gzgt->srna, "axis_type", axis_type_items, 0, "Axis Type", "");
 }
 
 /** \} */



More information about the Bf-blender-cvs mailing list