[Bf-blender-cvs] [4588609fc3e] asset-browser-poselib: Asset View: Activate poses when "walk" navigating the active asset

Julian Eisel noreply at git.blender.org
Tue Apr 20 17:47:19 CEST 2021


Commit: 4588609fc3eebf77700475ae32af53b7fb60dc81
Author: Julian Eisel
Date:   Tue Apr 20 17:43:36 2021 +0200
Branches: asset-browser-poselib
https://developer.blender.org/rB4588609fc3eebf77700475ae32af53b7fb60dc81

Asset View: Activate poses when "walk" navigating the active asset

When using the arrow keys to "walk" the active item in the asset view, call the
activate operator which applies the pose asset. This is useful for animators to
easily go through poses on the search for an appropriate one.

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

M	source/blender/editors/interface/interface_handlers.c
M	source/blender/editors/interface/interface_intern.h
M	source/blender/editors/interface/interface_query.c

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

diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index b40bdb50864..a9be7c86744 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -1071,39 +1071,33 @@ static void ui_apply_but_ROW(bContext *C, uiBlock *block, uiBut *but, uiHandleBu
 /**
  * \note Ownership of \a properties is moved here. The after-func owns it now.
  *
+ * \param context_but: The button to use context from when calling or polling the operator.
+ *
  * \returns true if the operator was executed, otherwise false.
  */
 static bool ui_list_invoke_item_operator(bContext *C,
-                                         const ARegion *region,
-                                         const wmEvent *event,
+                                         const uiBut *context_but,
                                          wmOperatorType *ot,
                                          PointerRNA **properties)
 {
-  const uiBut *hovered_but = ui_but_find_mouse_over(region, event);
-
-  if (!ui_but_context_poll_operator(C, ot, hovered_but)) {
+  if (!ui_but_context_poll_operator(C, ot, context_but)) {
     return false;
   }
 
   /* Allow the context to be set from the hovered button, so the list item draw callback can set
    * context for the operators. */
-  ui_handle_afterfunc_add_operator_ex(ot, properties, WM_OP_INVOKE_DEFAULT, hovered_but);
+  ui_handle_afterfunc_add_operator_ex(ot, properties, WM_OP_INVOKE_DEFAULT, context_but);
   return true;
 }
 
 static void ui_apply_but_LISTROW(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data)
 {
-  wmWindow *window = CTX_wm_window(C);
-
-  uiBut *listbox = ui_list_find_mouse_over(data->region, window->eventstate);
+  uiBut *listbox = ui_list_find_from_row(data->region, but);
   if (listbox) {
     uiList *list = listbox->custom_data;
     if (list && list->dyn_data->custom_activate_optype) {
-      ui_list_invoke_item_operator(C,
-                                   data->region,
-                                   window->eventstate,
-                                   list->dyn_data->custom_activate_optype,
-                                   &list->dyn_data->custom_activate_opptr);
+      ui_list_invoke_item_operator(
+          C, but, list->dyn_data->custom_activate_optype, &list->dyn_data->custom_activate_opptr);
     }
   }
 
@@ -1578,7 +1572,7 @@ static void ui_drag_toggle_set(bContext *C, uiDragToggleHandle *drag_info, const
    */
   if (drag_info->is_xy_lock_init == false) {
     /* first store the buttons original coords */
-    uiBut *but = ui_but_find_mouse_over_ex(region, xy_input[0], xy_input[1], true, NULL);
+    uiBut *but = ui_but_find_mouse_over_ex(region, xy_input[0], xy_input[1], true, NULL, NULL);
 
     if (but) {
       if (but->flag & UI_BUT_DRAG_LOCK) {
@@ -1649,7 +1643,7 @@ static int ui_handler_region_drag_toggle(bContext *C, const wmEvent *event, void
     wmWindow *win = CTX_wm_window(C);
     const ARegion *region = CTX_wm_region(C);
     uiBut *but = ui_but_find_mouse_over_ex(
-        region, drag_info->xy_init[0], drag_info->xy_init[1], true, NULL);
+        region, drag_info->xy_init[0], drag_info->xy_init[1], true, NULL, NULL);
 
     if (but) {
       ui_apply_but_undo(but);
@@ -4225,7 +4219,7 @@ static uiBut *ui_but_list_row_text_activate(bContext *C,
                                             uiButtonActivateType activate_type)
 {
   ARegion *region = CTX_wm_region(C);
-  uiBut *labelbut = ui_but_find_mouse_over_ex(region, event->x, event->y, true, NULL);
+  uiBut *labelbut = ui_but_find_mouse_over_ex(region, event->x, event->y, true, NULL, NULL);
 
   if (labelbut && labelbut->type == UI_BTYPE_TEXT && !(labelbut->flag & UI_BUT_DISABLED)) {
     /* exit listrow */
@@ -9122,9 +9116,9 @@ static int ui_list_activate_hovered_row(bContext *C,
   const bool do_drag = activate_dragging && ui_list->dyn_data->custom_drag_optype;
 
   if (do_drag) {
+    const uiBut *hovered_but = ui_but_find_mouse_over(region, event);
     if (!ui_list_invoke_item_operator(C,
-                                      region,
-                                      event,
+                                      hovered_but,
                                       ui_list->dyn_data->custom_drag_optype,
                                       &ui_list->dyn_data->custom_drag_opptr)) {
       return WM_UI_HANDLER_CONTINUE;
@@ -9160,7 +9154,7 @@ static bool ui_list_is_hovering_draggable_but(bContext *C,
   /* On a tweak event, uses the coordinates from where tweaking was started. */
   const int *mouse_xy = ISTWEAK(event->type) ? &event->prevclickx : &event->x;
   const uiBut *hovered_but = ui_but_find_mouse_over_ex(
-      region, mouse_xy[0], mouse_xy[1], false, NULL);
+      region, mouse_xy[0], mouse_xy[1], false, NULL, NULL);
 
   if (list->dyn_data->custom_drag_optype) {
     if (ui_but_context_poll_operator(C, list->dyn_data->custom_drag_optype, hovered_but)) {
@@ -9207,6 +9201,28 @@ static int ui_list_handle_click_drag(bContext *C,
   return retval;
 }
 
+static void ui_list_activate_row_from_index(
+    bContext *C, ARegion *region, uiBut *listbox, uiList *ui_list, int index)
+{
+  uiBut *new_active_row = ui_list_row_find_from_index(region, index, listbox);
+  if (new_active_row) {
+    /* Preferred way to update the active item, also calls the custom activate operator
+     * (#uiList.custom_activate_opname). */
+    UI_but_execute(C, region, new_active_row);
+  }
+  else {
+    /* A bit ugly, set the active index in RNA directly. That's because a button that's
+     * scrolled away in the list box isn't created at all.
+     * The custom activate operator (#uiList.custom_activate_opname) is not called in this case
+     * (which may need the row button context).*/
+    RNA_property_int_set(&listbox->rnapoin, listbox->rnaprop, index);
+    RNA_property_update(C, &listbox->rnapoin, listbox->rnaprop);
+    ui_apply_but_undo(listbox);
+  }
+
+  ui_list->flag |= UILST_SCROLL_TO_ACTIVE_ITEM;
+}
+
 static int ui_handle_list_event(bContext *C, const wmEvent *event, ARegion *region, uiBut *listbox)
 {
   int retval = WM_UI_HANDLER_CONTINUE;
@@ -9305,12 +9321,7 @@ static int ui_handle_list_event(bContext *C, const wmEvent *event, ARegion *regi
       CLAMP(value, min, max);
 
       if (value != value_orig) {
-        RNA_property_int_set(&listbox->rnapoin, listbox->rnaprop, value);
-        RNA_property_update(C, &listbox->rnapoin, listbox->rnaprop);
-
-        ui_apply_but_undo(listbox);
-
-        ui_list->flag |= UILST_SCROLL_TO_ACTIVE_ITEM;
+        ui_list_activate_row_from_index(C, region, listbox, ui_list, value);
         redraw = true;
       }
       retval = WM_UI_HANDLER_BREAK;
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index 454fca7a146..1f571fd8c24 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -1129,16 +1129,22 @@ bool ui_but_contains_point_px(const uiBut *but, const struct ARegion *region, in
 
 uiBut *ui_list_find_mouse_over(const struct ARegion *region,
                                const struct wmEvent *event) ATTR_WARN_UNUSED_RESULT;
+uiBut *ui_list_find_from_row(const struct ARegion *region,
+                             const uiBut *row_but) ATTR_WARN_UNUSED_RESULT;
 uiBut *ui_list_row_find_mouse_over(const struct ARegion *region,
                                    int x,
                                    int y) ATTR_WARN_UNUSED_RESULT;
+uiBut *ui_list_row_find_from_index(const struct ARegion *region,
+                                   const int index,
+                                   uiBut *listbox) ATTR_WARN_UNUSED_RESULT;
 
-typedef bool (*uiButFindPoll)(const uiBut *but);
+typedef bool (*uiButFindPollFn)(const uiBut *but, const void *customdata);
 uiBut *ui_but_find_mouse_over_ex(const struct ARegion *region,
                                  const int x,
                                  const int y,
                                  const bool labeledit,
-                                 uiButFindPoll find_poll) ATTR_WARN_UNUSED_RESULT;
+                                 const uiButFindPollFn find_poll,
+                                 const void *find_custom_data) ATTR_WARN_UNUSED_RESULT;
 uiBut *ui_but_find_mouse_over(const struct ARegion *region,
                               const struct wmEvent *event) ATTR_WARN_UNUSED_RESULT;
 uiBut *ui_but_find_rect_over(const struct ARegion *region,
diff --git a/source/blender/editors/interface/interface_query.c b/source/blender/editors/interface/interface_query.c
index 1d3a177586a..804ca4674fa 100644
--- a/source/blender/editors/interface/interface_query.c
+++ b/source/blender/editors/interface/interface_query.c
@@ -264,9 +264,29 @@ bool ui_but_contains_point_px_icon(const uiBut *but, ARegion *region, const wmEv
   return BLI_rcti_isect_pt(&rect, x, y);
 }
 
+static uiBut *ui_but_find(const ARegion *region,
+                          const uiButFindPollFn find_poll,
+                          const void *find_custom_data)
+{
+  LISTBASE_FOREACH (uiBlock *, block, &region->uiblocks) {
+    LISTBASE_FOREACH_BACKWARD (uiBut *, but, &block->buttons) {
+      if (find_poll && find_poll(but, find_custom_data) == false) {
+        continue;
+      }
+      return but;
+    }
+  }
+
+  return NULL;
+}
+
 /* x and y are only used in case event is NULL... */
-uiBut *ui_but_find_mouse_over_ex(
-    const ARegion *region, const int x, const int y, const bool labeledit, uiButFindPoll find_poll)
+uiBut *ui_but_find_mouse_over_ex(const ARegion *region,
+                                 const int x,
+                                 const int y,
+                                 const bool labeledit,
+                                 const uiButFindPollFn find_poll,
+                                 const void *find_custom_data)
 {
   uiBut *butover = NULL;
 
@@ -278,7 +298,7 @@ uiBut *ui_but_find_mouse_over_ex(
     ui_window_to_block_fl(region, block, &mx, &my);
 
     LISTBASE_FOREACH_BACKWARD (uiBut *, but, &block->buttons) {
-      if (find_poll && find_poll(b

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list