[Bf-blender-cvs] [7d985fcc1b3] blender2.8: 3D View: move x-ray toggle to operator

Campbell Barton noreply at git.blender.org
Wed Nov 21 20:51:13 CET 2018


Commit: 7d985fcc1b3d2812321bf9006fd459bbbae78803
Author: Campbell Barton
Date:   Thu Nov 22 06:44:09 2018 +1100
Branches: blender2.8
https://developer.blender.org/rB7d985fcc1b3d2812321bf9006fd459bbbae78803

3D View: move x-ray toggle to operator

Allows binding to a key.

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

M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/editors/space_view3d/view3d_edit.c
M	source/blender/editors/space_view3d/view3d_intern.h
M	source/blender/editors/space_view3d/view3d_ops.c

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

diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 53008311a2b..b301cc6a2e1 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -3842,24 +3842,16 @@ class VIEW3D_MT_shading_pie(Menu):
         pie.prop_enum(view.shading, "type", value='WIREFRAME')
         pie.prop_enum(view.shading, "type", value='SOLID')
 
-        if context.mode == 'POSE':
-            pie.prop(view.overlay, "show_bone_select", icon='XRAY')
+        xray_active = (
+            (context.mode in {'POSE', 'EDIT_MESH'}) or
+            (view.shading.type in {'SOLID', 'WIREFRAME'})
+        )
+        if xray_active:
+            sub = pie
         else:
-            xray_active = (
-                (context.mode in 'EDIT_MESH') or
-                (view.shading.type in {'SOLID', 'WIREFRAME'})
-            )
-
-            if xray_active:
-                sub = pie
-            else:
-                sub = pie.row()
-                sub.active = False
-
-            if view.shading.type == 'WIREFRAME':
-                sub.prop(view.shading, "show_xray_wireframe", text="Toggle X-Ray", icon='XRAY')
-            else:
-                sub.prop(view.shading, "show_xray", text="Toggle X-Ray", icon='XRAY')
+            sub = pie.row()
+            sub.active = False
+        sub.operator("view3d.toggle_xray", text="Toggle X-Ray", icon='XRAY')
 
         pie.prop(view.overlay, "show_overlays", text="Toggle Overlays", icon='OVERLAY')
         pie.prop_enum(view.shading, "type", value='MATERIAL')
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index dea28b75745..82e0511afe5 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -4918,3 +4918,51 @@ void VIEW3D_OT_toggle_shading(wmOperatorType *ot)
 }
 
 /** \} */
+
+
+/* -------------------------------------------------------------------- */
+/** \name Toggle XRay
+ * \{ */
+
+static int toggle_xray_exec(bContext *C, wmOperator *op)
+{
+	View3D *v3d = CTX_wm_view3d(C);
+	ScrArea *sa = CTX_wm_area(C);
+	Object *obact = CTX_data_active_object(C);
+
+	if (obact && obact->mode & OB_MODE_POSE) {
+		v3d->overlay.flag ^= V3D_OVERLAY_BONE_SELECT;
+	}
+	else {
+		const bool xray_active = (
+		        (obact && (obact->mode & OB_MODE_EDIT)) ||
+		        ELEM(v3d->shading.type, OB_WIRE, OB_SOLID));
+
+		if (v3d->shading.type == OB_WIRE) {
+			v3d->shading.flag ^= V3D_SHADING_XRAY_WIREFRAME;
+		}
+		else {
+			v3d->shading.flag ^= V3D_SHADING_XRAY;
+		}
+		if (!xray_active) {
+			BKE_report(op->reports, RPT_INFO, "X-Ray not available in current mode");
+		}
+	}
+
+	ED_area_tag_redraw(sa);
+
+	return OPERATOR_FINISHED;
+}
+
+void VIEW3D_OT_toggle_xray(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Toggle X-Ray";
+	ot->idname = "VIEW3D_OT_toggle_xray";
+
+	/* api callbacks */
+	ot->exec = toggle_xray_exec;
+	ot->poll = ED_operator_view3d_active;
+}
+
+/** \} */
diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h
index 8c21497dd53..05f2d8f67e1 100644
--- a/source/blender/editors/space_view3d/view3d_intern.h
+++ b/source/blender/editors/space_view3d/view3d_intern.h
@@ -104,6 +104,7 @@ void VIEW3D_OT_render_border(struct wmOperatorType *ot);
 void VIEW3D_OT_clear_render_border(struct wmOperatorType *ot);
 void VIEW3D_OT_zoom_border(struct wmOperatorType *ot);
 void VIEW3D_OT_toggle_shading(struct wmOperatorType *ot);
+void VIEW3D_OT_toggle_xray(struct wmOperatorType *ot);
 
 void view3d_boxview_copy(struct ScrArea *sa, struct ARegion *ar);
 void view3d_boxview_sync(struct ScrArea *sa, struct ARegion *ar);
diff --git a/source/blender/editors/space_view3d/view3d_ops.c b/source/blender/editors/space_view3d/view3d_ops.c
index 0c916ebf2a3..2dbe0a0b843 100644
--- a/source/blender/editors/space_view3d/view3d_ops.c
+++ b/source/blender/editors/space_view3d/view3d_ops.c
@@ -224,6 +224,7 @@ void view3d_operatortypes(void)
 	WM_operatortype_append(VIEW3D_OT_snap_cursor_to_active);
 
 	WM_operatortype_append(VIEW3D_OT_toggle_shading);
+	WM_operatortype_append(VIEW3D_OT_toggle_xray);
 	WM_operatortype_append(VIEW3D_OT_toggle_matcap_flip);
 
 	WM_operatortype_append(VIEW3D_OT_ruler_add);



More information about the Bf-blender-cvs mailing list