[Bf-blender-cvs] [43a1fdd7b94] temp-geometry-nodes-attribute-search: More progress towards a prototype

Hans Goudey noreply at git.blender.org
Mon Feb 22 21:39:44 CET 2021


Commit: 43a1fdd7b948994754592bb346393971da83cf9f
Author: Hans Goudey
Date:   Thu Feb 18 15:50:39 2021 -0600
Branches: temp-geometry-nodes-attribute-search
https://developer.blender.org/rB43a1fdd7b948994754592bb346393971da83cf9f

More progress towards a prototype

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

M	source/blender/blenkernel/BKE_node_ui_storage.hh
M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface_region_search.c
M	source/blender/editors/space_node/node_geometry_attribute_search.cc
D	source/blender/editors/space_node/node_geometry_attribute_search.hh
M	source/blender/makesrna/intern/rna_nodetree.c

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

diff --git a/source/blender/blenkernel/BKE_node_ui_storage.hh b/source/blender/blenkernel/BKE_node_ui_storage.hh
index ac12999731a..22866fe09fc 100644
--- a/source/blender/blenkernel/BKE_node_ui_storage.hh
+++ b/source/blender/blenkernel/BKE_node_ui_storage.hh
@@ -29,8 +29,6 @@ struct Object;
 struct bNode;
 struct bNodeTree;
 
-using blender::Map;
-
 /**
  * Contains the context necessary to determine when to display settings for a certain node tree
  * that may be used for multiple modifiers and objects. The object name and modifier session UUID
@@ -77,10 +75,11 @@ struct NodeWarning {
 
 struct NodeUIStorage {
   blender::Vector<NodeWarning> warnings;
+  blender::Set<std::string> attribute_name_hints = {"HELLO!", "DOES", "THIS", "WORK???"};
 };
 
 struct NodeTreeUIStorage {
-  Map<NodeTreeEvaluationContext, Map<std::string, NodeUIStorage>> context_map;
+  blender::Map<NodeTreeEvaluationContext, blender::Map<std::string, NodeUIStorage>> context_map;
 };
 
 void BKE_nodetree_ui_storage_free_for_context(bNodeTree &ntree,
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index bc013953b1e..c8d4de22626 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -494,6 +494,7 @@ typedef void (*uiButHandleHoldFunc)(struct bContext *C, struct ARegion *butregio
 typedef int (*uiButCompleteFunc)(struct bContext *C, char *str, void *arg);
 
 /* Search types. */
+
 typedef struct ARegion *(*uiButSearchCreateFn)(struct bContext *C,
                                                struct ARegion *butregion,
                                                struct uiButSearch *search_but);
diff --git a/source/blender/editors/interface/interface_region_search.c b/source/blender/editors/interface/interface_region_search.c
index d1d4290bd11..464793968d3 100644
--- a/source/blender/editors/interface/interface_region_search.c
+++ b/source/blender/editors/interface/interface_region_search.c
@@ -719,24 +719,18 @@ static void ui_searchbox_region_free_cb(ARegion *region)
   region->regiondata = NULL;
 }
 
-ARegion *ui_searchbox_create_generic(bContext *C, ARegion *butregion, uiButSearch *search_but)
+ARegion *UI_searchbox_create_generic(bContext *C, ARegion *butregion, uiButSearch *search_but)
 {
   wmWindow *win = CTX_wm_window(C);
   const uiStyle *style = UI_style_get();
   uiBut *but = &search_but->but;
-  static ARegionType type;
-  ARegion *region;
-  uiSearchboxData *data;
   const float aspect = but->block->aspect;
-  rctf rect_fl;
-  rcti rect_i;
   const int margin = UI_POPUP_MARGIN;
-  int winx /*, winy */, ofsx, ofsy;
-  int i;
 
   /* create area region */
-  region = ui_region_temp_add(CTX_wm_screen(C));
+  ARegion *region = ui_region_temp_add(CTX_wm_screen(C));
 
+  static ARegionType type;
   memset(&type, 0, sizeof(ARegionType));
   type.draw = ui_searchbox_region_draw_cb;
   type.free = ui_searchbox_region_free_cb;
@@ -744,7 +738,7 @@ ARegion *ui_searchbox_create_generic(bContext *C, ARegion *butregion, uiButSearc
   region->type = &type;
 
   /* create searchbox data */
-  data = MEM_callocN(sizeof(uiSearchboxData), "uiSearchboxData");
+  uiSearchboxData *data = MEM_callocN(sizeof(uiSearchboxData), "uiSearchboxData");
 
   /* set font, get bb */
   data->fstyle = style->widget; /* copy struct */
@@ -799,13 +793,14 @@ ARegion *ui_searchbox_create_generic(bContext *C, ARegion *butregion, uiButSearc
   else {
     const int searchbox_width = UI_searchbox_size_x();
 
+    rctf rect_fl;
     rect_fl.xmin = but->rect.xmin - 5; /* align text with button */
     rect_fl.xmax = but->rect.xmax + 5; /* symmetrical */
     rect_fl.ymax = but->rect.ymin;
     rect_fl.ymin = rect_fl.ymax - UI_searchbox_size_y();
 
-    ofsx = (but->block->panel) ? but->block->panel->ofsx : 0;
-    ofsy = (but->block->panel) ? but->block->panel->ofsy : 0;
+    const int ofsx = (but->block->panel) ? but->block->panel->ofsx : 0;
+    const int ofsy = (but->block->panel) ? but->block->panel->ofsy : 0;
 
     BLI_rctf_translate(&rect_fl, ofsx, ofsy);
 
@@ -815,6 +810,7 @@ ARegion *ui_searchbox_create_generic(bContext *C, ARegion *butregion, uiButSearc
     }
 
     /* copy to int, gets projected if possible too */
+    rcti rect_i;
     BLI_rcti_rctf_copy(&rect_i, &rect_fl);
 
     if (butregion->v2d.cur.xmin != butregion->v2d.cur.xmax) {
@@ -823,7 +819,7 @@ ARegion *ui_searchbox_create_generic(bContext *C, ARegion *butregion, uiButSearc
 
     BLI_rcti_translate(&rect_i, butregion->winrct.xmin, butregion->winrct.ymin);
 
-    winx = WM_window_pixels_x(win);
+    int winx = WM_window_pixels_x(win);
     // winy = WM_window_pixels_y(win);  /* UNUSED */
     // wm_window_get_size(win, &winx, &winy);
 
@@ -885,7 +881,7 @@ ARegion *ui_searchbox_create_generic(bContext *C, ARegion *butregion, uiButSearc
   data->items.icons = MEM_callocN(data->items.maxitem * sizeof(int), "search icons");
   data->items.states = MEM_callocN(data->items.maxitem * sizeof(int), "search flags");
   data->items.name_prefix_offsets = NULL; /* Lazy initialized as needed. */
-  for (i = 0; i < data->items.maxitem; i++) {
+  for (int i = 0; i < data->items.maxitem; i++) {
     data->items.names[i] = MEM_callocN(but->hardmax + 1, "search pointers");
   }
 
@@ -1000,10 +996,8 @@ static void ui_searchbox_region_draw_cb__operator(const bContext *UNUSED(C), ARe
 
 ARegion *ui_searchbox_create_operator(bContext *C, ARegion *butregion, uiButSearch *search_but)
 {
-  ARegion *region;
-
   UI_but_drawflag_enable(&search_but->but, UI_BUT_HAS_SHORTCUT);
-  region = ui_searchbox_create_generic(C, butregion, search_but);
+  ARegion *region = ui_searchbox_create_generic(C, butregion, search_but);
 
   region->type->draw = ui_searchbox_region_draw_cb__operator;
 
@@ -1022,10 +1016,8 @@ static void ui_searchbox_region_draw_cb__menu(const bContext *UNUSED(C), ARegion
 
 ARegion *ui_searchbox_create_menu(bContext *C, ARegion *butregion, uiButSearch *search_but)
 {
-  ARegion *region;
-
   UI_but_drawflag_enable(&search_but->but, UI_BUT_HAS_SHORTCUT);
-  region = ui_searchbox_create_generic(C, butregion, search_but);
+  ARegion *region = ui_searchbox_create_generic(C, butregion, search_but);
 
   if (false) {
     region->type->draw = ui_searchbox_region_draw_cb__menu;
diff --git a/source/blender/editors/space_node/node_geometry_attribute_search.cc b/source/blender/editors/space_node/node_geometry_attribute_search.cc
index b941a5c28a7..7fa86d13ef1 100644
--- a/source/blender/editors/space_node/node_geometry_attribute_search.cc
+++ b/source/blender/editors/space_node/node_geometry_attribute_search.cc
@@ -14,11 +14,12 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
+#include "BLI_index_range.hh"
 #include "BLI_listbase.h"
 #include "BLI_map.hh"
+#include "BLI_set.hh"
 #include "BLI_string_ref.hh"
 #include "BLI_string_search.h"
-#include "BLI_vector.hh"
 
 #include "DNA_modifier_types.h"
 #include "DNA_node_types.h"
@@ -29,9 +30,12 @@
 #include "BKE_object.h"
 
 #include "UI_interface.h"
+#include "UI_resources.h"
 
+using blender::IndexRange;
+using blender::Map;
+using blender::Set;
 using blender::StringRef;
-using blender::Vector;
 
 static const NodeUIStorage *node_ui_storage_get_from_context(const bContext *C,
                                                              const bNodeTree &ntree,
@@ -58,28 +62,30 @@ static const NodeUIStorage *node_ui_storage_get_from_context(const bContext *C,
 }
 
 struct AttributeSearchData {
-  Vector<std::string> attributes;
+  Set<std::string> attributes;
+  bNodeSocket &socket;
 };
 
-static void menu_search_update_fn(const bContext *UNUSED(C),
-                                  void *arg,
-                                  const char *str,
-                                  uiSearchItems *items)
+static void attribute_search_update_fn(const bContext *UNUSED(C),
+                                       void *arg,
+                                       const char *str,
+                                       uiSearchItems *items)
 {
-  struct MenuSearch_Data *data = arg;
+  const NodeUIStorage &storage = *static_cast<const NodeUIStorage *>(arg);
+  Set<std::string> attribute_name_hints = {"HELLO!", "DOES", "THIS", "WORK???"};
 
   StringSearch *search = BLI_string_search_new();
 
-  LISTBASE_FOREACH (struct MenuSearch_Item *, item, &data->items) {
-    BLI_string_search_add(search, item->drawwstr_full, item);
+  for (const std::string attribute_name : attribute_name_hints) {
+    BLI_string_search_add(search, attribute_name.c_str(), (void *)&attribute_name);
   }
 
-  struct MenuSearch_Item **filtered_items;
+  std::string **filtered_items;
   const int filtered_amount = BLI_string_search_query(search, str, (void ***)&filtered_items);
 
-  for (int i = 0; i < filtered_amount; i++) {
-    struct MenuSearch_Item *item = filtered_items[i];
-    if (!UI_search_item_add(items, item->drawwstr_full, item, item->icon, item->state, 0)) {
+  for (const int i : IndexRange(filtered_amount)) {
+    std::string *item = filtered_items[i];
+    if (!UI_search_item_add(items, item->c_str(), item, ICON_NONE, 0, 0)) {
       break;
     }
   }
@@ -88,9 +94,25 @@ static void menu_search_update_fn(const bContext *UNUSED(C),
   BLI_string_search_free(search);
 }
 
-void button_add_attribute_search(const bContext *C,
-                                 uiBut *but,
-                                 const bNodeTree &ntree,
-                                 const bNode &node)
+static void attribute_search_exec_fn(struct bContext *C, void *arg1, void *arg2)
 {
+  AttributeSearchData *data = static_cast<AttributeSearchData *>(arg1);
+  const std::string *attribute_name = static_cast<std::string *>(arg2);
+
+  bNodeSocketValueString *string_value = static_cast<bNodeSocketValueString *>(
+      data->socket.default_value);
+
+  BLI_strncpy(string_value->value, attribute_name->c_str(), 1024);
+}
+
+void button_add_attribute_search(uiBut *but, const NodeUIStorage &ui_storage, bNodeSocket *socket)
+{
+  AttributeSearchData data = {ui_storage.attribute_name_hints, *socket};
+  UI_but_func_search_set(but,
+                         nullptr,
+                         attribute_search_updat

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list