[Bf-blender-cvs] [675d42dfc33] master: UI: Draw real node sockets for node input buttons

Julian Eisel noreply at git.blender.org
Thu Apr 16 15:31:42 CEST 2020


Commit: 675d42dfc33d6c791d9e5da31dcc00930519a127
Author: Julian Eisel
Date:   Thu Apr 16 15:09:49 2020 +0200
Branches: master
https://developer.blender.org/rB675d42dfc33d6c791d9e5da31dcc00930519a127

UI: Draw real node sockets for node input buttons

For buttons representing node inputs (e.g. in the material properties)
rather than drawing some generic socket icon, the actual sockets are
drawn now. That includes color, shape and the selection outline.

This should make it easier to understand what these buttons relate to.

Screenshots: {F8469252}, {F8469248} (The left alignment will be done in
a follow-up commit.)

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

Reviewed by: Brecht Van Lommel, Clément Foucault, William Reynish

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

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..dfdd809dbd1 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,10 @@ 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],
+                         float scale);
 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 774cf8c509f..4716e7f0972 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -1585,6 +1585,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);
@@ -2088,6 +2090,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 9ec660a9714..c97f5ee8239 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -6486,6 +6486,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 ae40b01c77d..53c488bf765 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"
 
@@ -2394,6 +2396,30 @@ 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)
+{
+  /* Node socket pointer can be passed as custom_data, see UI_but_node_link_set(). */
+  if (but->custom_data) {
+    const float scale = 0.9f / but->block->aspect;
+
+    float col[4];
+    rgba_uchar_to_float(col, but->col);
+    col[3] *= alpha;
+
+    GPU_blend(true);
+    UI_widgetbase_draw_cache_flush();
+    GPU_blend(false);
+
+    ED_node_socket_draw(but->custom_data, rect, col, scale);
+  }
+  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,
@@ -2403,15 +2429,27 @@ static void widget_draw_text_icon(const uiFontStyle *fstyle,
   const bool show_menu_icon = ui_but_draw_menu_icon(but);
   float alpha = (float)wcol->text[3] / 255.0f;
   char password_str[UI_MAX_DRAW_STR];
+  bool no_text_padding = false;
 
   ui_but_text_password_hide(password_str, but, false);
 
   /* check for button text label */
   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);
-    rect->xmax = temp.xmin;
+    const int size = BLI_rcti_size_y(rect) + 1; /* Not the icon size! */
+
+    if (but->drawflag & UI_BUT_ICON_LEFT) {
+      temp.xmax = rect->xmin + size;
+      rect->xmin = temp.xmax;
+      /* Further padding looks off. */
+      no_text_padding = true;
+    }
+    else {
+      temp.xmin = rect->xmax - size;
+      rect->xmax = temp.xmin;
+    }
+
+    widget_draw_node_link_socket(wcol, &temp, but, alpha);
   }
 
   /* If there's an icon too (made with uiDefIconTextBut) then draw the icon
@@ -2496,28 +2534,30 @@ static void widget_draw_text_icon(const uiFontStyle *fstyle,
     rect->xmin += icon_size + icon_padding;
   }
 
-  int text_padding = (UI_TEXT_MARGIN_X * U.widget_unit) / but->block->aspect;
-  if (but->editstr) {
-    rect->xmin += text_padding;
-  }
-  else if (but->flag & UI_BUT_DRAG_MULTI) {
-    bool text_is_edited = ui_but_drag_multi_edit_get(but) != NULL;
-    if (text_is_edited) {
+  if (!no_text_padding) {
+    int text_padding = (UI_TEXT_MARGIN_X * U.widget_unit) / but->block->aspect;
+    if (but->editstr) {
       rect->xmin += text_padding;
     }
-  }
-  else if (but->drawflag & UI_BUT_TEXT_LEFT) {
-
-    /* Reduce the left padding for labels without an icon. */
-    if ((but->type == UI_BTYPE_LABEL) && !(but->flag & UI_HAS_ICON) &&
-        !ui_block_is_menu(but->block)) {
-      text_padding /= 2;
+    else if (but->flag & UI_BUT_DRAG_MULTI) {
+      bool text_is_edited = ui_but_drag_multi_edit_get(but) != NULL;
+      if (text_is_edited) {
+        rect->xmin += text_padding;
+      }
     }
+    else if (but->drawflag & UI_BUT_TEXT_LEFT) {
 
-    rect->xmin += text_padding;
-  }
-  else if (but->drawflag & UI_BUT_TEXT_RIGHT) {
-    rect->xmax -= text_padding;
+      /* Reduce the left padding for labels without an icon. */
+      if ((but->type == UI_BTYPE_LABEL) && !(but->flag & UI_HAS_ICON) &&
+          !ui_block_is_menu(but->block)) {
+        text_padding /= 2;
+      }
+
+      rect->xmin += text_padding;
+    }
+    else if (but->drawflag & UI_BUT_TEXT_RIGHT) {
+      rect->xmax -= text_padding;
+    }
   }
 
   /* Menu contains sub-menu items with triangle icon on their right. Shortcut
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 bdb7f787be6..bd8950c5085 100644
--- a/source/blender/editors/space_node/node_draw.c
+++ b/source/blender/editors/space_node/node_draw.c
@@ -707,39 +707,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 void 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) {
@@ -768,8 +748,120 @@ 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);
+}
+
+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 *so

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list