[Bf-blender-cvs] [8d43ee1b082] blender-v3.2-release: Fix T97518: All buttons with eyedropper highlight if one is hovered

Julian Eisel noreply at git.blender.org
Fri May 13 17:56:32 CEST 2022


Commit: 8d43ee1b0823e6e5fae2fdceaee0a94d3d61f9b7
Author: Julian Eisel
Date:   Fri May 13 15:55:11 2022 +0200
Branches: blender-v3.2-release
https://developer.blender.org/rB8d43ee1b0823e6e5fae2fdceaee0a94d3d61f9b7

Fix T97518: All buttons with eyedropper highlight if one is hovered

Issue is that the operator acts on the active button, and also uses that in the
poll. So the actually active button would affect the poll of a different
button. For the superimposed icons we need to be able to execute these polls
properly for non-active buttons.

This enables temporarily overriding the active button for lookups via context.
While a bit of a hack it makes sense conceptually.

Reviewed By: Campbell Barton

Maniphest Tasks: T97518

Differential Revision: https://developer.blender.org/D14880

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

M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface.cc
M	source/blender/editors/interface/interface_handlers.c
M	source/blender/editors/interface/interface_intern.h

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

diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 9f4d6815287..1b61e87b140 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -184,26 +184,26 @@ enum {
 
 /** #uiBut.flag general state flags. */
 enum {
-  /* WARNING: the first 7 flags are internal (see #UI_SELECT definition). */
-  UI_BUT_ICON_SUBMENU = 1 << 7,
-  UI_BUT_ICON_PREVIEW = 1 << 8,
+  /* WARNING: the first 8 flags are internal (see #UI_SELECT definition). */
+  UI_BUT_ICON_SUBMENU = 1 << 8,
+  UI_BUT_ICON_PREVIEW = 1 << 9,
 
-  UI_BUT_NODE_LINK = 1 << 9,
-  UI_BUT_NODE_ACTIVE = 1 << 10,
-  UI_BUT_DRAG_LOCK = 1 << 11,
+  UI_BUT_NODE_LINK = 1 << 10,
+  UI_BUT_NODE_ACTIVE = 1 << 11,
+  UI_BUT_DRAG_LOCK = 1 << 12,
   /** Grayed out and un-editable. */
-  UI_BUT_DISABLED = 1 << 12,
+  UI_BUT_DISABLED = 1 << 13,
 
-  UI_BUT_ANIMATED = 1 << 13,
-  UI_BUT_ANIMATED_KEY = 1 << 14,
-  UI_BUT_DRIVEN = 1 << 15,
-  UI_BUT_REDALERT = 1 << 16,
+  UI_BUT_ANIMATED = 1 << 14,
+  UI_BUT_ANIMATED_KEY = 1 << 15,
+  UI_BUT_DRIVEN = 1 << 16,
+  UI_BUT_REDALERT = 1 << 17,
   /** Grayed out but still editable. */
-  UI_BUT_INACTIVE = 1 << 17,
-  UI_BUT_LAST_ACTIVE = 1 << 18,
-  UI_BUT_UNDO = 1 << 19,
-  UI_BUT_IMMEDIATE = 1 << 20,
-  UI_BUT_NO_UTF8 = 1 << 21,
+  UI_BUT_INACTIVE = 1 << 18,
+  UI_BUT_LAST_ACTIVE = 1 << 19,
+  UI_BUT_UNDO = 1 << 20,
+  UI_BUT_IMMEDIATE = 1 << 21,
+  UI_BUT_NO_UTF8 = 1 << 22,
 
   /** For popups, pressing return activates this button, overriding the highlighted button.
    * For non-popups this is just used as a display hint for the user to let them
diff --git a/source/blender/editors/interface/interface.cc b/source/blender/editors/interface/interface.cc
index b7098c26bcd..480044118f1 100644
--- a/source/blender/editors/interface/interface.cc
+++ b/source/blender/editors/interface/interface.cc
@@ -1861,15 +1861,32 @@ bool ui_but_context_poll_operator_ex(bContext *C,
                                      const wmOperatorCallParams *optype_params)
 {
   bool result;
+  int old_but_flag = 0;
 
-  if (but && but->context) {
-    CTX_store_set(C, but->context);
+  if (but) {
+    old_but_flag = but->flag;
+
+    /* Temporarily make this button override the active one, in case the poll acts on the active
+     * button. */
+    const_cast<uiBut *>(but)->flag |= UI_BUT_ACTIVE_OVERRIDE;
+
+    if (but->context) {
+      CTX_store_set(C, but->context);
+    }
   }
 
   result = WM_operator_poll_context(C, optype_params->optype, optype_params->opcontext);
 
-  if (but && but->context) {
-    CTX_store_set(C, nullptr);
+  if (but) {
+    BLI_assert_msg((but->flag & ~UI_BUT_ACTIVE_OVERRIDE) ==
+                       (old_but_flag & ~UI_BUT_ACTIVE_OVERRIDE),
+                   "Operator polls shouldn't change button flags");
+
+    const_cast<uiBut *>(but)->flag = old_but_flag;
+
+    if (but->context) {
+      CTX_store_set(C, nullptr);
+    }
   }
 
   return result;
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 26b9b82d67f..9d30ad992c9 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -8714,13 +8714,23 @@ static uiBut *ui_context_button_active(const ARegion *region, bool (*but_check_c
     /* find active button */
     LISTBASE_FOREACH (uiBlock *, block, &region->uiblocks) {
       LISTBASE_FOREACH (uiBut *, but, &block->buttons) {
+        if (but->flag & UI_BUT_ACTIVE_OVERRIDE) {
+          activebut = but;
+          break;
+        }
         if (but->active) {
           activebut = but;
+          break;
         }
-        else if (!activebut && (but->flag & UI_BUT_LAST_ACTIVE)) {
+        if (but->flag & UI_BUT_LAST_ACTIVE) {
           activebut = but;
+          break;
         }
       }
+
+      if (activebut) {
+        break;
+      }
     }
 
     if (activebut && (but_check_cb == NULL || but_check_cb(activebut))) {
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index b1ca0fa4e92..1c79d3218fb 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -74,6 +74,12 @@ enum {
   UI_SELECT_DRAW = (1 << 5),
   /** Property search filter is active and the button does not match. */
   UI_SEARCH_FILTER_NO_MATCH = (1 << 6),
+
+  /** Temporarily override the active button for lookups in context, regions, etc. (everything
+   * using #ui_context_button_active()). For example, so that operators normally acting on the
+   * active button can be polled on non-active buttons to (e.g. for disabling). */
+  UI_BUT_ACTIVE_OVERRIDE = (1 << 7),
+
   /* WARNING: rest of #uiBut.flag in UI_interface.h */
 };



More information about the Bf-blender-cvs mailing list