[Bf-blender-cvs] [c685c19df95] blender2.8: Drivers UI (Part of T55145): Add "Show Drivers Editor" entry to RMB menus

Joshua Leung noreply at git.blender.org
Tue May 22 16:44:21 CEST 2018


Commit: c685c19df9513a3263e78b417a87fc102840437e
Author: Joshua Leung
Date:   Tue May 22 16:18:09 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBc685c19df9513a3263e78b417a87fc102840437e

Drivers UI (Part of T55145): Add "Show Drivers Editor" entry to RMB menus

This commit adds an operator, "Show Drivers Editor", to the RMB menu when
clicking on properties.

As per T54653, this will open a new Graph Editor instance in a new/separate
window (much like how the User Preferences show up in a popup window now),
and will configure all the relevant panels so that you can see and edit the
driver settings immediately without doing a lot of the view configuration steps
that were previously needed.

When doing so on a property that is driven, the driver/fcurve for that property
will be made active in the editor, ready for you to start editing its settings
without having to hunt it down again first.

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

M	source/blender/editors/interface/interface_handlers.c
M	source/blender/editors/screen/screen_ops.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm_window.c

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

diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 2f91fb86b36..6332d006dbb 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -6774,6 +6774,9 @@ static bool ui_but_menu(bContext *C, uiBut *but)
 				uiItemO(layout, CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Paste Driver"),
 				        ICON_NONE, "ANIM_OT_paste_driver_button");
 			}
+			
+			uiItemO(layout, CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Open Drivers Editor"),
+			        ICON_DRIVER, "SCREEN_OT_drivers_editor_show");
 		}
 		else if (but->flag & (UI_BUT_ANIMATED_KEY | UI_BUT_ANIMATED)) {
 			/* pass */
@@ -6796,6 +6799,9 @@ static bool ui_but_menu(bContext *C, uiBut *but)
 				uiItemO(layout, CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Paste Driver"),
 				        ICON_NONE, "ANIM_OT_paste_driver_button");
 			}
+			
+			uiItemO(layout, CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Open Drivers Editor"),
+			        ICON_NONE, "SCREEN_OT_drivers_editor_show");
 		}
 		
 		/* Keying Sets */
diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c
index 3d28a131763..0a3c1f3d261 100644
--- a/source/blender/editors/screen/screen_ops.c
+++ b/source/blender/editors/screen/screen_ops.c
@@ -39,6 +39,7 @@
 
 #include "BLT_translation.h"
 
+#include "DNA_anim_types.h"
 #include "DNA_armature_types.h"
 #include "DNA_lattice_types.h"
 #include "DNA_object_types.h"
@@ -53,6 +54,7 @@
 
 #include "BKE_context.h"
 #include "BKE_customdata.h"
+#include "BKE_fcurve.h"
 #include "BKE_global.h"
 #include "BKE_icons.h"
 #include "BKE_main.h"
@@ -70,6 +72,7 @@
 
 #include "DEG_depsgraph.h"
 
+#include "ED_anim_api.h"
 #include "ED_armature.h"
 #include "ED_clip.h"
 #include "ED_image.h"
@@ -4189,6 +4192,74 @@ static void SCREEN_OT_userpref_show(struct wmOperatorType *ot)
 
 /** \} */
 
+/* -------------------------------------------------------------------- */
+/** \name Show Drivers Editor Operator
+ * \{ */
+
+static int drivers_editor_show_invoke(bContext *C, wmOperator *op, const wmEvent *event)
+{
+	PointerRNA ptr = {{NULL}};
+	PropertyRNA *prop = NULL;
+	int index = -1;
+	uiBut *but = NULL;
+	
+	int sizex = 900 * UI_DPI_FAC;
+	int sizey = 580 * UI_DPI_FAC;
+	
+	/* Get active property to show driver for
+	 * - Need to grab it first, or else this info disappears
+	 *   after we've created the window
+	 */
+	but = UI_context_active_but_prop_get(C, &ptr, &prop, &index);
+	
+	/* changes context! */
+	if (WM_window_open_temp(C, event->x, event->y, sizex, sizey, WM_WINDOW_DRIVERS) != NULL) {
+		/* activate driver F-Curve for the property under the cursor */
+		if (but) {
+			FCurve *fcu;
+			bool driven, special;
+			
+			fcu = rna_get_fcurve_context_ui(C,
+			                                &ptr, prop, index,
+			                                NULL, NULL, &driven, &special);
+			if (fcu) {
+				/* Isolate this F-Curve... */
+				bAnimContext ac;
+				if (ANIM_animdata_get_context(C, &ac)) {
+					int filter = ANIMFILTER_DATA_VISIBLE | ANIMFILTER_NODUPLIS;
+					ANIM_deselect_anim_channels(&ac, ac.data, ac.datatype, 0, ACHANNEL_SETFLAG_CLEAR);
+					ANIM_set_active_channel(&ac, ac.data, ac.datatype, filter, fcu, ANIMTYPE_FCURVE);
+				}
+				else {
+					/* Just blindly isolate... This isn't the best, and shouldn't happen, but may be enough... */
+					fcu->flag |= (FCURVE_ACTIVE | FCURVE_SELECTED);
+				}
+			}
+		}
+		
+		return OPERATOR_FINISHED;
+	}
+	else {
+		BKE_report(op->reports, RPT_ERROR, "Failed to open window!");
+		return OPERATOR_CANCELLED;
+	}
+}
+
+
+static void SCREEN_OT_drivers_editor_show(struct wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Show Drivers Editor";
+	ot->description = "Show drivers editor in a separate window";
+	ot->idname = "SCREEN_OT_drivers_editor_show";
+	
+	/* api callbacks */
+	ot->invoke = drivers_editor_show_invoke;
+	ot->poll = ED_operator_screenactive;
+}
+
+/** \} */
+
 /* -------------------------------------------------------------------- */
 /** \name New Screen Operator
  * \{ */
@@ -4514,6 +4585,7 @@ void ED_operatortypes_screen(void)
 	WM_operatortype_append(SCREEN_OT_screenshot);
 	WM_operatortype_append(SCREEN_OT_screencast);
 	WM_operatortype_append(SCREEN_OT_userpref_show);
+	WM_operatortype_append(SCREEN_OT_drivers_editor_show);
 	WM_operatortype_append(SCREEN_OT_region_blend);
 	WM_operatortype_append(SCREEN_OT_space_context_cycle);
 	
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 33222b2f1f1..bda22929ce8 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -136,6 +136,7 @@ void WM_opengl_context_release(void *context);
 enum {
 	WM_WINDOW_RENDER = 1,
 	WM_WINDOW_USERPREFS,
+	WM_WINDOW_DRIVERS,
 	// WM_WINDOW_FILESEL // UNUSED
 };
 
diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c
index 2c28819ee58..ef1e4d24e7f 100644
--- a/source/blender/windowmanager/intern/wm_window.c
+++ b/source/blender/windowmanager/intern/wm_window.c
@@ -937,6 +937,9 @@ wmWindow *WM_window_open_temp(bContext *C, int x, int y, int sizex, int sizey, i
 	if (type == WM_WINDOW_RENDER) {
 		ED_area_newspace(C, sa, SPACE_IMAGE, false);
 	}
+	else if (type == WM_WINDOW_DRIVERS) {
+		ED_area_newspace(C, sa, SPACE_IPO, false);
+	}
 	else {
 		ED_area_newspace(C, sa, SPACE_USERPREF, false);
 	}
@@ -944,12 +947,42 @@ wmWindow *WM_window_open_temp(bContext *C, int x, int y, int sizex, int sizey, i
 	ED_screen_change(C, screen);
 	ED_screen_refresh(CTX_wm_manager(C), win); /* test scale */
 	
+	/* do additional setup for specific editor type */
+	if (type == WM_WINDOW_DRIVERS) {
+		/* Configure editor - mode, tabs, framing */
+		SpaceIpo *sipo = (SpaceIpo *)sa->spacedata.first;
+		sipo->mode = SIPO_MODE_DRIVERS;
+		
+		ARegion *ar_props = BKE_area_find_region_type(sa, RGN_TYPE_UI);
+		if (ar_props) {
+			UI_panel_category_active_set(ar_props, "Drivers");
+			
+			ar_props->flag &= ~RGN_FLAG_HIDDEN;
+			/* XXX: Adjust width of this too? */
+			
+			ED_region_visibility_change_update(C, ar_props);
+		}
+		
+		ARegion *ar_main = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
+		if (ar_main) {
+			/* XXX: Ideally we recenter based on the range instead... */
+			ar_main->v2d.tot.xmin = -2.0f;
+			ar_main->v2d.tot.ymin = -2.0f;
+			ar_main->v2d.tot.xmax = 2.0f;
+			ar_main->v2d.tot.ymax = 2.0f;
+			
+			ar_main->v2d.cur = ar_main->v2d.tot;
+		}
+	}
+	
 	if (sa->spacetype == SPACE_IMAGE)
 		title = IFACE_("Blender Render");
 	else if (ELEM(sa->spacetype, SPACE_OUTLINER, SPACE_USERPREF))
 		title = IFACE_("Blender User Preferences");
 	else if (sa->spacetype == SPACE_FILE)
 		title = IFACE_("Blender File View");
+	else if (sa->spacetype == SPACE_IPO)
+		title = IFACE_("Blender Drivers Editor");
 	else
 		title = "Blender";



More information about the Bf-blender-cvs mailing list