[Bf-blender-cvs] [68648733729] soc-2019-outliner: Eyedropper: Support datablock picking in outliner

Nathan Craddock noreply at git.blender.org
Wed Jun 19 00:35:00 CEST 2019


Commit: 6864873372928ce03f7e9072bf9c6fcd5e376ceb
Author: Nathan Craddock
Date:   Tue Jun 18 16:29:10 2019 -0600
Branches: soc-2019-outliner
https://developer.blender.org/rB6864873372928ce03f7e9072bf9c6fcd5e376ceb

Eyedropper: Support datablock picking in outliner

This adds support for picking datablocks from the outliner with the
eyedropper tool.

This requires changing the region the UI tooltip is drawn in by
tracking when the mouse moves to a different area on the screen.
By doing this the draw callback can be reset for each new area the
eyedropper enters.

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

M	source/blender/editors/include/ED_outliner.h
M	source/blender/editors/interface/interface_eyedropper_datablock.c
M	source/blender/editors/space_outliner/outliner_select.c
M	source/blender/editors/space_outliner/outliner_utils.c

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

diff --git a/source/blender/editors/include/ED_outliner.h b/source/blender/editors/include/ED_outliner.h
index e94aedc2b2b..55bc5e2d92b 100644
--- a/source/blender/editors/include/ED_outliner.h
+++ b/source/blender/editors/include/ED_outliner.h
@@ -30,4 +30,6 @@ bool ED_outliner_collections_editor_poll(struct bContext *C);
 
 void ED_outliner_selected_objects_get(const struct bContext *C, struct ListBase *objects);
 
+Base *ED_outliner_give_base_under_cursor(struct bContext *C, const int mval[2]);
+
 #endif /*  __ED_OUTLINER_H__ */
diff --git a/source/blender/editors/interface/interface_eyedropper_datablock.c b/source/blender/editors/interface/interface_eyedropper_datablock.c
index 658aa4f67f9..723ca43bfc5 100644
--- a/source/blender/editors/interface/interface_eyedropper_datablock.c
+++ b/source/blender/editors/interface/interface_eyedropper_datablock.c
@@ -51,6 +51,7 @@
 #include "ED_space_api.h"
 #include "ED_screen.h"
 #include "ED_view3d.h"
+#include "ED_outliner.h"
 
 #include "interface_intern.h"
 #include "interface_eyedropper_intern.h"
@@ -67,6 +68,7 @@ typedef struct DataDropper {
 
   ID *init_id; /* for resetting on cancel */
 
+  ScrArea *area_current;
   ARegionType *art;
   void *draw_handle_pixel;
   char name[200];
@@ -103,6 +105,7 @@ static int datadropper_init(bContext *C, wmOperator *op)
 
   ddr->is_undo = UI_but_flag_is_set(but, UI_BUT_UNDO);
 
+  ddr->area_current = CTX_wm_area(C);
   ddr->art = art;
   ddr->draw_handle_pixel = ED_region_draw_cb_activate(
       art, datadropper_draw_cb, ddr, REGION_DRAW_POST_PIXEL);
@@ -141,7 +144,7 @@ static void datadropper_exit(bContext *C, wmOperator *op)
 
 /* *** datadropper id helper functions *** */
 /**
- * \brief get the ID from the screen.
+ * \brief get the ID from the 3D view or outliner.
  */
 static void datadropper_id_sample_pt(bContext *C, DataDropper *ddr, int mx, int my, ID **r_id)
 {
@@ -155,7 +158,7 @@ static void datadropper_id_sample_pt(bContext *C, DataDropper *ddr, int mx, int
   ddr->name[0] = '\0';
 
   if (sa) {
-    if (sa->spacetype == SPACE_VIEW3D) {
+    if (sa->spacetype == SPACE_VIEW3D || sa->spacetype == SPACE_OUTLINER) {
       ARegion *ar = BKE_area_find_region_xy(sa, RGN_TYPE_WINDOW, mx, my);
       if (ar) {
         const int mval[2] = {mx - ar->winrct.xmin, my - ar->winrct.ymin};
@@ -167,7 +170,13 @@ static void datadropper_id_sample_pt(bContext *C, DataDropper *ddr, int mx, int
         /* grr, always draw else we leave stale text */
         ED_region_tag_redraw(ar);
 
-        base = ED_view3d_give_base_under_cursor(C, mval);
+        if (sa->spacetype == SPACE_VIEW3D) {
+          base = ED_view3d_give_base_under_cursor(C, mval);
+        }
+        else {
+          base = ED_outliner_give_base_under_cursor(C, mval);
+        }
+
         if (base) {
           Object *ob = base->object;
           ID *id = NULL;
@@ -232,6 +241,36 @@ static void datadropper_cancel(bContext *C, wmOperator *op)
   datadropper_exit(C, op);
 }
 
+/* To switch the draw callback when region under mouse event changes */
+static void datadropper_set_draw_callback_region(bContext *C,
+                                                 DataDropper *ddr,
+                                                 const int mx,
+                                                 const int my)
+{
+  bScreen *screen = CTX_wm_screen(C);
+  ScrArea *sa = BKE_screen_find_area_xy(screen, -1, mx, my);
+
+  if (sa) {
+    /* If spacetype changed */
+    if (sa->spacetype != ddr->area_current->spacetype) {
+      /* Remove old callback */
+      ED_region_draw_cb_exit(ddr->art, ddr->draw_handle_pixel);
+
+      /* Redraw old area */
+      ARegion *ar = BKE_area_find_region_type(ddr->area_current, RGN_TYPE_WINDOW);
+      ED_region_tag_redraw(ar);
+
+      /* Set draw callback in new region */
+      ARegionType *art = BKE_regiontype_from_id(sa->type, RGN_TYPE_WINDOW);
+
+      ddr->area_current = sa;
+      ddr->art = art;
+      ddr->draw_handle_pixel = ED_region_draw_cb_activate(
+          art, datadropper_draw_cb, ddr, REGION_DRAW_POST_PIXEL);
+    }
+  }
+}
+
 /* main modal status check */
 static int datadropper_modal(bContext *C, wmOperator *op, const wmEvent *event)
 {
@@ -260,6 +299,10 @@ static int datadropper_modal(bContext *C, wmOperator *op, const wmEvent *event)
   }
   else if (event->type == MOUSEMOVE) {
     ID *id = NULL;
+
+    /* Set the region for eyedropper cursor text drawing */
+    datadropper_set_draw_callback_region(C, ddr, event->x, event->y);
+
     datadropper_id_sample_pt(C, ddr, event->x, event->y, &id);
   }
 
diff --git a/source/blender/editors/space_outliner/outliner_select.c b/source/blender/editors/space_outliner/outliner_select.c
index fb015344a39..d9ecd596981 100644
--- a/source/blender/editors/space_outliner/outliner_select.c
+++ b/source/blender/editors/space_outliner/outliner_select.c
@@ -59,6 +59,7 @@
 #include "ED_sequencer.h"
 #include "ED_undo.h"
 #include "ED_gpencil.h"
+#include "ED_outliner.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -71,6 +72,30 @@
 
 #include "outliner_intern.h"
 
+/* Get base of object under cursor (for eyedropper) */
+Base *ED_outliner_give_base_under_cursor(struct bContext *C, const int mval[2])
+{
+  ARegion *ar = CTX_wm_region(C);
+  ViewLayer *view_layer = CTX_data_view_layer(C);
+  SpaceOutliner *soops = CTX_wm_space_outliner(C);
+  TreeElement *te;
+  Base *base = NULL;
+  float view_mval[2];
+
+  UI_view2d_region_to_view(&ar->v2d, mval[0], mval[1], &view_mval[0], &view_mval[1]);
+
+  te = outliner_find_item_at_y(soops, &soops->tree, view_mval[1]);
+  if (te) {
+    TreeStoreElem *tselem = TREESTORE(te);
+    if (tselem->type == 0) {
+      Object *ob = (Object *)tselem->id;
+      base = (te->directdata) ? (Base *)te->directdata : BKE_view_layer_base_find(view_layer, ob);
+    }
+  }
+
+  return base;
+}
+
 static bool do_outliner_activate_common(bContext *C,
                                         Main *bmain,
                                         Depsgraph *depsgraph,
diff --git a/source/blender/editors/space_outliner/outliner_utils.c b/source/blender/editors/space_outliner/outliner_utils.c
index f24435415f7..de18ea03d1f 100644
--- a/source/blender/editors/space_outliner/outliner_utils.c
+++ b/source/blender/editors/space_outliner/outliner_utils.c
@@ -333,4 +333,4 @@ bool outliner_is_element_visible(const ListBase *lb, const TreeElement *search_t
     }
   }
   return false;
-}
\ No newline at end of file
+}



More information about the Bf-blender-cvs mailing list