[Bf-blender-cvs] [0dc1873477e] modifier-panels-ui: UI: Draw real node sockets for node-input buttons and left-align them

Julian Eisel noreply at git.blender.org
Thu Apr 16 21:30:23 CEST 2020


Commit: 0dc1873477e6b686c08104127cf97d225b5b6555
Author: Julian Eisel
Date:   Mon Apr 13 16:35:42 2020 +0200
Branches: modifier-panels-ui
https://developer.blender.org/rB0dc1873477e6b686c08104127cf97d225b5b6555

UI: Draw real node sockets for node-input buttons and left-align them

Couple of reasons for this:
* Makes it easier to understand that and how these buttons map to nodes.
* These buttons represent node inputs, so it makes more sense to have the icons
  on the left.
* We'd like to show the usual decorators on the right, but having two circles
  for different purposes next to each other would be confusing.

Also respects the socket shape. So if a diamond shape is used for example, the
properties show that too.

I'm not sure if the previous icon textures were cached, either way this method
doesn't use the caching. So this adds a draw call for every socket icon which
is a bit annoying, but probably neglectable. Would be better if we'd use proper
icon textures or batches, but that's a separate change.

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

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

M	source/blender/editors/include/ED_node.h
M	source/blender/editors/interface/interface_widgets.c
M	source/blender/editors/space_node/node_draw.c
M	source/blender/editors/space_node/node_templates.c

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

diff --git a/source/blender/editors/include/ED_node.h b/source/blender/editors/include/ED_node.h
index b5fcddf9c16..dfdd809dbd1 100644
--- a/source/blender/editors/include/ED_node.h
+++ b/source/blender/editors/include/ED_node.h
@@ -80,7 +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]);
+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/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 1480535ee36..ba7bea8b428 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -2402,6 +2402,8 @@ static void widget_draw_node_link_socket(const uiWidgetColors *wcol,
                                          float alpha)
 {
   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;
@@ -2411,7 +2413,7 @@ static void widget_draw_node_link_socket(const uiWidgetColors *wcol,
     GPU_blend(false);
 
     /* See UI_but_node_link_set() */
-    ED_node_socket_draw(but->custom_data, rect, col);
+    ED_node_socket_draw(but->custom_data, rect, col, scale);
   }
   else {
     widget_draw_icon(but, ICON_LAYER_USED, alpha, rect, wcol->text);
@@ -2427,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;
+    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);
-    rect->xmax = temp.xmin;
   }
 
   /* If there's an icon too (made with uiDefIconTextBut) then draw the icon
@@ -2520,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_draw.c b/source/blender/editors/space_node/node_draw.c
index 2d8fc840e7f..66f3cdc0178 100644
--- a/source/blender/editors/space_node/node_draw.c
+++ b/source/blender/editors/space_node/node_draw.c
@@ -832,15 +832,14 @@ static void node_socket_draw_nested(const bContext *C,
  * \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])
+void ED_node_socket_draw(bNodeSocket *sock, const rcti *rect, const float color[4], float scale)
 {
-  const float size = 2.25f * NODE_SOCKSIZE;
+  const float size = 2.25f * NODE_SOCKSIZE * scale;
   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();
diff --git a/source/blender/editors/space_node/node_templates.c b/source/blender/editors/space_node/node_templates.c
index da0058585cb..91fe6a97432 100644
--- a/source/blender/editors/space_node/node_templates.c
+++ b/source/blender/editors/space_node/node_templates.c
@@ -695,6 +695,7 @@ void uiTemplateNodeLink(
 
   UI_but_type_set_menu_from_pulldown(but);
   UI_but_node_link_set(but, sock, socket_col);
+  UI_but_drawflag_enable(but, UI_BUT_ICON_LEFT);
 
   but->poin = (char *)but;
   but->func_argN = arg;
@@ -816,6 +817,10 @@ static void ui_node_draw_input(
     }
   }
   else {
+    row = uiLayoutRow(split, true);
+
+    uiTemplateNodeLink(row, C, ntree, node, input);
+
     /* input not linked, show value */
     if (!(input->flag & SOCK_HIDE_VALUE)) {
       switch (input->type) {
@@ -824,25 +829,15 @@ static void ui_node_draw_input(
         case SOCK_BOOLEAN:
         case SOCK_RGBA:
         case SOCK_STRING:
-          row = uiLayoutRow(split, true);
           uiItemR(row, &inputptr, "default_value", 0, "", ICON_NONE);
           break;
         case SOCK_VECTOR:
-          row = uiLayoutRow(split, false);
+          uiItemS(row);
           col = uiLayoutColumn(row, false);
           uiItemR(col, &inputptr, "default_value", 0, "", ICON_NONE);
           break;
-
-        default:
-          row = uiLayoutRow(split, false);
-          break;
       }
     }
-    else {
-      row = uiLayoutRow(split, false);
-    }
-
-    uiTemplateNodeLink(row, C, ntree, node, input);
   }
 
   /* clear */



More information about the Bf-blender-cvs mailing list