[Bf-blender-cvs] [b8c4d147afc] temp-checkbox-layout-tweaks: Draw node socket icons in properties using real node socket shape/color

Julian Eisel noreply at git.blender.org
Mon Apr 13 17:50:52 CEST 2020


Commit: b8c4d147afc5eb7ca7219e50a0c9e82feaffd0d8
Author: Julian Eisel
Date:   Mon Apr 13 15:03:56 2020 +0200
Branches: temp-checkbox-layout-tweaks
https://developer.blender.org/rBb8c4d147afc5eb7ca7219e50a0c9e82feaffd0d8

Draw node socket icons in properties using real node socket shape/color

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

M	source/blender/editors/include/ED_node.h
M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface.c
M	source/blender/editors/interface/interface_widgets.c
M	source/blender/editors/space_node/node_buttons.c
M	source/blender/editors/space_node/node_draw.c
M	source/blender/editors/space_node/node_intern.h
M	source/blender/editors/space_node/node_templates.c
M	source/blender/makesrna/intern/rna_ui_api.c

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

diff --git a/source/blender/editors/include/ED_node.h b/source/blender/editors/include/ED_node.h
index 7a1f64b61d4..b5fcddf9c16 100644
--- a/source/blender/editors/include/ED_node.h
+++ b/source/blender/editors/include/ED_node.h
@@ -37,6 +37,7 @@ struct Tex;
 struct View2D;
 struct bContext;
 struct bNode;
+struct bNodeSocket;
 struct bNodeSocketType;
 struct bNodeTree;
 struct bNodeTree;
@@ -79,6 +80,7 @@ void ED_node_draw_snap(
     struct View2D *v2d, const float cent[2], float size, NodeBorder border, unsigned int pos);
 
 /* node_draw.c */
+void ED_node_socket_draw(struct bNodeSocket *sock, const struct rcti *rect, const float color[4]);
 void ED_node_tree_update(const struct bContext *C);
 void ED_node_tag_update_id(struct ID *id);
 void ED_node_tag_update_nodetree(struct Main *bmain, struct bNodeTree *ntree, struct bNode *node);
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index eb134646649..aa74834454e 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -1583,6 +1583,8 @@ int UI_searchbox_size_x(void);
 /* check if a string is in an existing search box */
 int UI_search_items_find_index(uiSearchItems *items, const char *name);
 
+void UI_but_node_link_set(uiBut *but, struct bNodeSocket *socket, const float draw_color[4]);
+
 void UI_block_func_handle_set(uiBlock *block, uiBlockHandleFunc func, void *arg);
 void UI_block_func_butmenu_set(uiBlock *block, uiMenuHandleFunc func, void *arg);
 void UI_block_func_set(uiBlock *block, uiButHandleFunc func, void *arg1, void *arg2);
@@ -2086,6 +2088,7 @@ void uiTemplateList(uiLayout *layout,
                     bool sort_reverse,
                     bool sort_lock);
 void uiTemplateNodeLink(uiLayout *layout,
+                        struct bContext *C,
                         struct bNodeTree *ntree,
                         struct bNode *node,
                         struct bNodeSocket *input);
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 18666daa8b8..d97f853fb59 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -6482,6 +6482,13 @@ uiBut *uiDefSearchButO_ptr(uiBlock *block,
   return but;
 }
 
+void UI_but_node_link_set(uiBut *but, bNodeSocket *socket, const float draw_color[4])
+{
+  but->flag |= UI_BUT_NODE_LINK;
+  but->custom_data = socket;
+  rgba_float_to_uchar(but->col, draw_color);
+}
+
 /**
  * push a new event onto event queue to activate the given button
  * (usually a text-field) upon entering a popup
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index fa4a0a1e07d..6ec2b81319c 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -42,6 +42,8 @@
 
 #include "BLF_api.h"
 
+#include "ED_node.h"
+
 #include "UI_interface.h"
 #include "UI_interface_icons.h"
 
@@ -2407,6 +2409,28 @@ static void widget_draw_extra_icons(const uiWidgetColors *wcol,
   }
 }
 
+static void widget_draw_node_link_socket(const uiWidgetColors *wcol,
+                                         const rcti *rect,
+                                         uiBut *but,
+                                         float alpha)
+{
+  if (but->custom_data) {
+    float col[4];
+    rgba_uchar_to_float(col, but->col);
+    col[3] *= alpha;
+
+    GPU_blend(true);
+    UI_widgetbase_draw_cache_flush();
+    GPU_blend(false);
+
+    /* See UI_but_node_link_set() */
+    ED_node_socket_draw(but->custom_data, rect, col);
+  }
+  else {
+    widget_draw_icon(but, ICON_LAYER_USED, alpha, rect, wcol->text);
+  }
+}
+
 /* draws text and icons for buttons */
 static void widget_draw_text_icon(const uiFontStyle *fstyle,
                                   const uiWidgetColors *wcol,
@@ -2423,7 +2447,7 @@ static void widget_draw_text_icon(const uiFontStyle *fstyle,
   if (ELEM(but->type, UI_BTYPE_MENU, UI_BTYPE_POPOVER) && (but->flag & UI_BUT_NODE_LINK)) {
     rcti temp = *rect;
     temp.xmin = rect->xmax - BLI_rcti_size_y(rect) - 1;
-    widget_draw_icon(but, ICON_LAYER_USED, alpha, &temp, wcol->text);
+    widget_draw_node_link_socket(wcol, &temp, but, alpha);
     rect->xmax = temp.xmin;
   }
 
diff --git a/source/blender/editors/space_node/node_buttons.c b/source/blender/editors/space_node/node_buttons.c
index 4cf67dddb57..8fc343a9ed4 100644
--- a/source/blender/editors/space_node/node_buttons.c
+++ b/source/blender/editors/space_node/node_buttons.c
@@ -84,7 +84,7 @@ static void node_sockets_panel(const bContext *C, Panel *panel)
 
     split = uiLayoutSplit(layout, 0.35f, false);
     uiItemL(split, name, ICON_NONE);
-    uiTemplateNodeLink(split, ntree, node, sock);
+    uiTemplateNodeLink(split, (bContext *)C, ntree, node, sock);
   }
 }
 
diff --git a/source/blender/editors/space_node/node_draw.c b/source/blender/editors/space_node/node_draw.c
index 0552660b9bf..2d8fc840e7f 100644
--- a/source/blender/editors/space_node/node_draw.c
+++ b/source/blender/editors/space_node/node_draw.c
@@ -719,39 +719,19 @@ static void node_draw_mute_line(View2D *v2d, SpaceNode *snode, bNode *node)
 #define MARKER_SHAPE_CIRCLE 0x2
 #define MARKER_SHAPE_INNER_DOT 0x10
 
-static void node_socket_draw(const bContext *C,
-                             bNodeTree *ntree,
-                             PointerRNA node_ptr,
-                             bNodeSocket *sock,
+static uint node_socket_draw(const bNodeSocket *sock,
+                             const float color[4],
+                             const float color_outline[4],
+                             float size,
+                             int locx,
+                             int locy,
                              uint pos_id,
                              uint col_id,
                              uint shape_id,
                              uint size_id,
-                             uint outline_col_id,
-                             float size,
-                             bool selected)
+                             uint outline_col_id)
 {
-  PointerRNA ptr;
-  float color[4];
-  float outline_color[4];
-  uint flags = 0;
-
-  RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr);
-  sock->typeinfo->draw_color((bContext *)C, &ptr, &node_ptr, color);
-
-  bNode *node = node_ptr.data;
-  if (node->flag & NODE_MUTED) {
-    color[3] *= 0.25f;
-  }
-
-  if (selected) {
-    UI_GetThemeColor4fv(TH_TEXT_HI, outline_color);
-    outline_color[3] = 0.9f;
-  }
-  else {
-    copy_v4_fl(outline_color, 0.0f);
-    outline_color[3] = 0.6f;
-  }
+  int flags;
 
   /* sets shape flags */
   switch (sock->display_shape) {
@@ -780,8 +760,123 @@ static void node_socket_draw(const bContext *C,
   immAttr4fv(col_id, color);
   immAttr1u(shape_id, flags);
   immAttr1f(size_id, size);
-  immAttr4fv(outline_col_id, outline_color);
-  immVertex2f(pos_id, sock->locx, sock->locy);
+  immAttr4fv(outline_col_id, color_outline);
+  immVertex2f(pos_id, locx, locy);
+
+  return flags;
+}
+
+static void node_socket_outline_color_get(bool selected, float r_outline_color[4])
+{
+  if (selected) {
+    UI_GetThemeColor4fv(TH_TEXT_HI, r_outline_color);
+    r_outline_color[3] = 0.9f;
+  }
+  else {
+    copy_v4_fl(r_outline_color, 0.0f);
+    r_outline_color[3] = 0.6f;
+  }
+}
+
+/* Usual convention here would be node_socket_get_color(), but that's already used (for setting a
+ * color property socket). */
+void node_socket_color_get(
+    bContext *C, bNodeTree *ntree, PointerRNA *node_ptr, bNodeSocket *sock, float r_color[4])
+{
+  PointerRNA ptr;
+
+  BLI_assert(RNA_struct_is_a(node_ptr->type, &RNA_Node));
+  RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr);
+
+  sock->typeinfo->draw_color(C, &ptr, node_ptr, r_color);
+
+  bNode *node = node_ptr->data;
+  if (node->flag & NODE_MUTED) {
+    r_color[3] *= 0.25f;
+  }
+}
+
+static void node_socket_draw_nested(const bContext *C,
+                                    bNodeTree *ntree,
+                                    PointerRNA *node_ptr,
+                                    bNodeSocket *sock,
+                                    uint pos_id,
+                                    uint col_id,
+                                    uint shape_id,
+                                    uint size_id,
+                                    uint outline_col_id,
+                                    float size,
+                                    bool selected)
+{
+  float color[4];
+  float outline_color[4];
+
+  node_socket_color_get((bContext *)C, ntree, node_ptr, sock, color);
+  node_socket_outline_color_get(selected, outline_color);
+
+  node_socket_draw(sock,
+                   color,
+                   outline_color,
+                   size,
+                   sock->locx,
+                   sock->locy,
+                   pos_id,
+                   col_id,
+                   shape_id,
+                   size_id,
+                   outline_col_id);
+}
+
+/**
+ * Draw a single node socket at default size.
+ * \note this is only called from external code, internally #node_socket_draw_nested() is used for
+ *       optimized drawing of multiple/all sockets of a node.
+ */
+void ED_node_socket_draw(bNodeSocket *sock, const rcti *rect, const float color[4])
+{
+  const float size = 2.25f * NODE_SOCKSIZE;
+  rcti draw_rect = *rect;
+  float outline_color[4] = {0};
+
+  node_socket_outline_color_get(sock->flag & SELECT, outline_color);
+
+  /* Always use default size, could be optional. */
+  BLI_rcti_resize(&draw_rect, size, size);
+
+  GPUVertFormat *format = immVertexFormat();
+  uint pos_id = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+  uint col_id = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT);
+  uint shape_id = GPU_vertformat_attr_add(format, "flags", GPU_COMP_U32, 1, GPU_FETCH_INT);
+  uint size_id = GPU_vertformat_attr_add(format, "size", GPU_COMP_F32, 1, GPU_FETCH_FLOAT);
+  uint outline_col_id = GPU_vertformat_attr_add(
+      format, "outlineColor", GPU_COMP_F32, 4, GPU_FETCH_FLOAT);


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list