[Bf-blender-cvs] [cdd915e9e96] blender2.8: UI: status bar cursor keymap display

Campbell Barton noreply at git.blender.org
Tue Jun 26 12:19:55 CEST 2018


Commit: cdd915e9e9646b9dcb83999712f48546fb830c1f
Author: Campbell Barton
Date:   Tue Jun 26 12:18:54 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBcdd915e9e9646b9dcb83999712f48546fb830c1f

UI: status bar cursor keymap display

Show mouse button actions in status bar, based on context,
modifiers and active tool.

See: T54861

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

M	release/scripts/startup/bl_ui/space_statusbar.py
M	source/blender/blenloader/intern/readfile.c
M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface_templates.c
M	source/blender/makesdna/DNA_windowmanager_types.h
M	source/blender/makesrna/intern/rna_ui_api.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm_event_system.c
M	source/blender/windowmanager/intern/wm_window.c

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

diff --git a/release/scripts/startup/bl_ui/space_statusbar.py b/release/scripts/startup/bl_ui/space_statusbar.py
index 3a6fc4925d8..a738eb315e7 100644
--- a/release/scripts/startup/bl_ui/space_statusbar.py
+++ b/release/scripts/startup/bl_ui/space_statusbar.py
@@ -39,11 +39,7 @@ class STATUSBAR_HT_header(Header):
     def draw_left(self, context):
         layout = self.layout
 
-        row = layout.row(align=True)
-        if (bpy.data.filepath):
-            row.label(text=bpy.data.filepath, translate=False)
-        if bpy.data.is_dirty:
-            row.label("(Modified)")
+        layout.template_cursor_keymap()
 
     def draw_center(self, context):
         layout = self.layout
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 9c5d59d2404..138cd868db0 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -6946,6 +6946,7 @@ static void direct_link_windowmanager(FileData *fd, wmWindowManager *wm)
 		win->ghostwin = NULL;
 		win->gwnctx = NULL;
 		win->eventstate = NULL;
+		win->cursor_keymap_status = NULL;
 		win->tweak = NULL;
 #ifdef WIN32
 		win->ime_data = NULL;
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 0666691607d..d4285f5a96e 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -1065,6 +1065,7 @@ void uiTemplateHeader3D_mode(uiLayout *layout, struct bContext *C);
 void uiTemplateHeader3D(uiLayout *layout, struct bContext *C);
 void uiTemplateEditModeSelection(uiLayout *layout, struct bContext *C);
 void uiTemplateReportsBanner(uiLayout *layout, struct bContext *C);
+void uiTemplateCursorKeymap(uiLayout *layout, struct bContext *C);
 void uiTemplateKeymapItemProperties(uiLayout *layout, struct PointerRNA *ptr);
 void uiTemplateComponentMenu(uiLayout *layout, struct PointerRNA *ptr, const char *propname, const char *name);
 void uiTemplateNodeSocket(uiLayout *layout, struct bContext *C, float *color);
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 61cb0cda8c8..c2bea466015 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -4295,6 +4295,24 @@ void uiTemplateReportsBanner(uiLayout *layout, bContext *C)
 	         NULL, 0.0f, 0.0f, 0, 0, "");
 }
 
+
+void uiTemplateCursorKeymap(uiLayout *layout, struct bContext *C)
+{
+	wmWindow *win = CTX_wm_window(C);
+	for (int i = 0; i < 3; i++) {
+		uiLayout *box = uiLayoutRow(layout, true);
+		for (int j = 0; j < 2; j++) {
+			const char *msg = WM_window_cursor_keymap_status_get(win, i, j);
+			if ((j == 0) || (msg != NULL)) {
+				uiItemL(box, msg, j == 0 ? (ICON_MOUSE_LMB + i) : ICON_MOUSE_DRAG);
+			}
+		}
+		if (i != 2) {
+			uiItemSpacer(layout);
+		}
+	}
+}
+
 /********************************* Keymap *************************************/
 
 static void keymap_item_modified(bContext *UNUSED(C), void *kmi_p, void *UNUSED(unused))
diff --git a/source/blender/makesdna/DNA_windowmanager_types.h b/source/blender/makesdna/DNA_windowmanager_types.h
index 19d4ab10165..e41058f356b 100644
--- a/source/blender/makesdna/DNA_windowmanager_types.h
+++ b/source/blender/makesdna/DNA_windowmanager_types.h
@@ -232,6 +232,9 @@ typedef struct wmWindow {
 
 	/* custom drawing callbacks */
 	ListBase drawcalls;
+
+	/* Private runtime info to show text in the status bar. */
+	void *cursor_keymap_status;
 } wmWindow;
 
 #ifdef ime_data
diff --git a/source/blender/makesrna/intern/rna_ui_api.c b/source/blender/makesrna/intern/rna_ui_api.c
index 9377ef8a925..702bcf15462 100644
--- a/source/blender/makesrna/intern/rna_ui_api.c
+++ b/source/blender/makesrna/intern/rna_ui_api.c
@@ -1021,6 +1021,9 @@ void RNA_api_ui_layout(StructRNA *srna)
 	func = RNA_def_function(srna, "template_reports_banner", "uiTemplateReportsBanner");
 	RNA_def_function_flag(func, FUNC_USE_CONTEXT);
 
+	func = RNA_def_function(srna, "template_cursor_keymap", "uiTemplateCursorKeymap");
+	RNA_def_function_flag(func, FUNC_USE_CONTEXT);
+
 	func = RNA_def_function(srna, "template_node_link", "uiTemplateNodeLink");
 	parm = RNA_def_pointer(func, "ntree", "NodeTree", "", "");
 	RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 6b1825edf3e..ace9acf0e8a 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -602,6 +602,9 @@ bool        WM_event_is_tablet(const struct wmEvent *event);
 bool        WM_event_is_ime_switch(const struct wmEvent *event);
 #endif
 
+const char *WM_window_cursor_keymap_status_get(const struct wmWindow *win, int button_index, int type_index);
+void WM_window_cursor_keymap_status_refresh(struct bContext *C, struct wmWindow *win);
+
 /* wm_tooltip.c */
 typedef struct ARegion *(*wmTooltipInitFn)(struct bContext *, struct ARegion *, bool *);
 
@@ -618,4 +621,3 @@ void WM_tooltip_refresh(struct bContext *C, struct wmWindow *win);
 #endif
 
 #endif /* __WM_API_H__ */
-
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index 6047f801037..55e8970c77e 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -499,6 +499,14 @@ void wm_event_do_notifiers(bContext *C)
 	}
 
 	wm_event_do_refresh_wm_and_depsgraph(C);
+
+	/* Status bar */
+	if (wm->winactive) {
+		win = wm->winactive;
+		CTX_wm_window_set(C, win);
+		WM_window_cursor_keymap_status_refresh(C, win);
+		CTX_wm_window_set(C, NULL);
+	}
 }
 
 static int wm_event_always_pass(const wmEvent *event)
@@ -2773,6 +2781,40 @@ static bool wm_event_pie_filter(wmWindow *win, const wmEvent *event)
 	}
 }
 
+#ifdef USE_WORKSPACE_TOOL
+static void wm_event_manipulator_temp_handler_apply(
+        bContext *C, ScrArea *sa, ARegion *ar, wmEventHandler *sneaky_handler)
+{
+	if (ar->regiontype == RGN_TYPE_WINDOW) {
+		bToolRef_Runtime *tref_rt = sa->runtime.tool ? sa->runtime.tool->runtime : NULL;
+		if (tref_rt && tref_rt->keymap[0]) {
+			wmKeyMap *km = WM_keymap_find_all(
+			        C, tref_rt->keymap, sa->spacetype, RGN_TYPE_WINDOW);
+			if (km != NULL) {
+				sneaky_handler->keymap = km;
+				sneaky_handler->keymap_tool = sa->runtime.tool;
+
+				/* Handle widgets first. */
+				wmEventHandler *handler_last = ar->handlers.last;
+				while (handler_last && handler_last->manipulator_map == NULL) {
+					handler_last = handler_last->prev;
+				}
+				/* Head of list or after last manipulator. */
+				BLI_insertlinkafter(&ar->handlers, handler_last, sneaky_handler);
+			}
+		}
+	}
+}
+
+static void wm_event_manipulator_temp_handler_clear(
+        bContext *UNUSED(C), ScrArea *UNUSED(sa), ARegion *ar, wmEventHandler *sneaky_handler)
+{
+	if (sneaky_handler->keymap) {
+		BLI_remlink(&ar->handlers, sneaky_handler);
+	}
+}
+#endif  /* USE_WORKSPACE_TOOL */
+
 /* called in main loop */
 /* goes over entire hierarchy:  events -> window -> screen -> area -> region */
 void wm_event_do_handlers(bContext *C)
@@ -2957,33 +2999,13 @@ void wm_event_do_handlers(bContext *C)
 									 * to fetch its current keymap.
 									 */
 									wmEventHandler sneaky_handler = {NULL};
-									if (ar->regiontype == RGN_TYPE_WINDOW) {
-										bToolRef_Runtime *tref_rt = sa->runtime.tool ? sa->runtime.tool->runtime : NULL;
-										if (tref_rt && tref_rt->keymap[0]) {
-											wmKeyMap *km = WM_keymap_find_all(
-											        C, tref_rt->keymap, sa->spacetype, RGN_TYPE_WINDOW);
-											if (km != NULL) {
-												sneaky_handler.keymap = km;
-												sneaky_handler.keymap_tool = sa->runtime.tool;
-
-												/* Handle widgets first. */
-												wmEventHandler *handler_last = ar->handlers.last;
-												while (handler_last && handler_last->manipulator_map == NULL) {
-													handler_last = handler_last->prev;
-												}
-												/* Head of list or after last manipulator. */
-												BLI_insertlinkafter(&ar->handlers, handler_last, &sneaky_handler);
-											}
-										}
-									}
+									wm_event_manipulator_temp_handler_apply(C, sa, ar, &sneaky_handler);
 #endif /* USE_WORKSPACE_TOOL */
 
 									action |= wm_handlers_do(C, event, &ar->handlers);
 
 #ifdef USE_WORKSPACE_TOOL
-									if (sneaky_handler.keymap) {
-										BLI_remlink(&ar->handlers, &sneaky_handler);
-									}
+									wm_event_manipulator_temp_handler_clear(C, sa, ar, &sneaky_handler);
 #endif /* USE_WORKSPACE_TOOL */
 
 									/* fileread case (python), [#29489] */
@@ -4206,3 +4228,232 @@ bool WM_event_is_ime_switch(const struct wmEvent *event)
 #endif
 
 /** \} */
+
+
+static wmKeyMapItem *wm_kmi_from_event(
+        bContext *C, wmWindowManager *wm,
+        ListBase *handlers, const wmEvent *event)
+{
+	for (wmEventHandler *handler = handlers->first; handler; handler = handler->next) {
+		/* during this loop, ui handlers for nested menus can tag multiple handlers free */
+		if (handler->flag & WM_HANDLER_DO_FREE) {
+			/* pass */
+		}
+		else if (handler_boundbox_test(handler, event)) { /* optional boundbox */
+			if (handler->keymap) {
+				wmKeyMap *keymap = WM_keymap_active(wm, handler->keymap);
+				if (WM_keymap_poll(C, keymap)) {
+					for (wmKeyMapItem *kmi = keymap->items.first; kmi; kmi = kmi->next) {
+						if (wm_eventmatch(event, kmi)) {
+							wmOperatorType *ot = WM_operatortype_find(kmi->idname, 0);
+							if (WM_operator_poll_context(C, ot, WM_OP_INVOKE_DEFAULT)) {
+								return kmi;
+							}
+						}
+					}
+				}
+			}
+		}
+	}
+	return NULL;
+}
+
+/* -------------------------------------------------------------------- */
+/** \name Cursor Keymap Status
+ *
+ * Show cursor keys in the status bar.
+ * This is done by detecting changes to the state - full keymap lookups are expensive
+ * so only perform this on changing tools, space types, pressing different modifier keys... etc.
+ * \{ */
+
+/** State storage to detect changes between calls to refresh the information. */
+st

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list