[Bf-blender-cvs] [9a312ba1928] master: Cleanup: Remove unnecesary node type draw callback

Hans Goudey noreply at git.blender.org
Sun Dec 5 23:13:09 CET 2021


Commit: 9a312ba19284f6d4b81378d145b24b6b76a2c082
Author: Hans Goudey
Date:   Sun Dec 5 17:12:25 2021 -0500
Branches: master
https://developer.blender.org/rB9a312ba19284f6d4b81378d145b24b6b76a2c082

Cleanup: Remove unnecesary node type draw callback

As a followup to 338c1060d5d7, apply the same change to the node
drawing callback. This helps to simplify code when the complexity
of a callback isn't necessary right now.

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

M	source/blender/blenkernel/BKE_node.h
M	source/blender/editors/space_node/drawnode.cc
M	source/blender/editors/space_node/node_draw.cc
M	source/blender/editors/space_node/node_intern.hh

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

diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 0584a8c811f..fd43a5418f6 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -247,14 +247,6 @@ typedef struct bNodeType {
 
   char storagename[64]; /* struct name for DNA */
 
-  /* Main draw function for the node */
-  void (*draw_nodetype)(const struct bContext *C,
-                        struct ARegion *region,
-                        struct SpaceNode *snode,
-                        struct bNodeTree *ntree,
-                        struct bNode *node,
-                        bNodeInstanceKey key);
-
   /* Draw the option buttons on the node */
   void (*draw_buttons)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr);
   /* Additional parameters in the side panel */
diff --git a/source/blender/editors/space_node/drawnode.cc b/source/blender/editors/space_node/drawnode.cc
index b031067ab14..8bce1248e8e 100644
--- a/source/blender/editors/space_node/drawnode.cc
+++ b/source/blender/editors/space_node/drawnode.cc
@@ -29,7 +29,6 @@
 #include "DNA_object_types.h"
 #include "DNA_screen_types.h"
 #include "DNA_space_types.h"
-#include "DNA_text_types.h"
 #include "DNA_userdef_types.h"
 
 #include "BKE_context.h"
@@ -312,147 +311,6 @@ static void node_draw_buttons_group(uiLayout *layout, bContext *C, PointerRNA *p
       layout, C, ptr, "node_tree", nullptr, nullptr, nullptr, UI_TEMPLATE_ID_FILTER_ALL, nullptr);
 }
 
-static void node_draw_frame_label(bNodeTree &ntree, bNode &node, SpaceNode &snode)
-{
-  const float aspect = snode.runtime->aspect;
-  /* XXX font id is crap design */
-  const int fontid = UI_style_get()->widgetlabel.uifont_id;
-  NodeFrame *data = (NodeFrame *)node.storage;
-  const float font_size = data->label_size / aspect;
-
-  char label[MAX_NAME];
-  nodeLabel(&ntree, &node, label, sizeof(label));
-
-  BLF_enable(fontid, BLF_ASPECT);
-  BLF_aspect(fontid, aspect, aspect, 1.0f);
-  /* clamp otherwise it can suck up a LOT of memory */
-  BLF_size(fontid, MIN2(24.0f, font_size), U.dpi);
-
-  /* title color */
-  int color_id = node_get_colorid(node);
-  uchar color[3];
-  UI_GetThemeColorBlendShade3ubv(TH_TEXT, color_id, 0.4f, 10, color);
-  BLF_color3ubv(fontid, color);
-
-  const float margin = (float)(NODE_DY / 4);
-  const float width = BLF_width(fontid, label, sizeof(label));
-  const float ascender = BLF_ascender(fontid);
-  const int label_height = ((margin / aspect) + (ascender * aspect));
-
-  /* 'x' doesn't need aspect correction */
-  const rctf &rct = node.totr;
-  /* XXX a bit hacky, should use separate align values for x and y */
-  float x = BLI_rctf_cent_x(&rct) - (0.5f * width);
-  float y = rct.ymax - label_height;
-
-  /* label */
-  const bool has_label = node.label[0] != '\0';
-  if (has_label) {
-    BLF_position(fontid, x, y, 0);
-    BLF_draw(fontid, label, BLF_DRAW_STR_DUMMY_MAX);
-  }
-
-  /* draw text body */
-  if (node.id) {
-    Text *text = (Text *)node.id;
-    const int line_height_max = BLF_height_max(fontid);
-    const float line_spacing = (line_height_max * aspect);
-    const float line_width = (BLI_rctf_size_x(&rct) - margin) / aspect;
-
-    /* 'x' doesn't need aspect correction */
-    x = rct.xmin + margin;
-    y = rct.ymax - label_height - (has_label ? line_spacing : 0);
-
-    /* early exit */
-    int y_min = y + ((margin * 2) - (y - rct.ymin));
-
-    BLF_enable(fontid, BLF_CLIPPING | BLF_WORD_WRAP);
-    BLF_clipping(fontid,
-                 rct.xmin,
-                 /* round to avoid clipping half-way through a line */
-                 y - (floorf(((y - rct.ymin) - (margin * 2)) / line_spacing) * line_spacing),
-                 rct.xmin + line_width,
-                 rct.ymax);
-
-    BLF_wordwrap(fontid, line_width);
-
-    LISTBASE_FOREACH (TextLine *, line, &text->lines) {
-      struct ResultBLF info;
-      if (line->line[0]) {
-        BLF_position(fontid, x, y, 0);
-        BLF_draw_ex(fontid, line->line, line->len, &info);
-        y -= line_spacing * info.lines;
-      }
-      else {
-        y -= line_spacing;
-      }
-      if (y < y_min) {
-        break;
-      }
-    }
-
-    BLF_disable(fontid, BLF_CLIPPING | BLF_WORD_WRAP);
-  }
-
-  BLF_disable(fontid, BLF_ASPECT);
-}
-
-static void node_draw_frame(const bContext *C,
-                            ARegion *region,
-                            SpaceNode *snode,
-                            bNodeTree *ntree,
-                            bNode *node,
-                            bNodeInstanceKey UNUSED(key))
-{
-
-  /* skip if out of view */
-  if (BLI_rctf_isect(&node->totr, &region->v2d.cur, nullptr) == false) {
-    UI_block_end(C, node->block);
-    node->block = nullptr;
-    return;
-  }
-
-  float color[4];
-  UI_GetThemeColor4fv(TH_NODE_FRAME, color);
-  const float alpha = color[3];
-
-  /* shadow */
-  node_draw_shadow(*snode, *node, BASIS_RAD, alpha);
-
-  /* body */
-  if (node->flag & NODE_CUSTOM_COLOR) {
-    rgba_float_args_set(color, node->color[0], node->color[1], node->color[2], alpha);
-  }
-  else {
-    UI_GetThemeColor4fv(TH_NODE_FRAME, color);
-  }
-
-  const rctf &rct = node->totr;
-  UI_draw_roundbox_corner_set(UI_CNR_ALL);
-  UI_draw_roundbox_4fv(&rct, true, BASIS_RAD, color);
-
-  /* outline active and selected emphasis */
-  if (node->flag & SELECT) {
-    if (node->flag & NODE_ACTIVE) {
-      UI_GetThemeColorShadeAlpha4fv(TH_ACTIVE, 0, -40, color);
-    }
-    else {
-      UI_GetThemeColorShadeAlpha4fv(TH_SELECT, 0, -40, color);
-    }
-
-    UI_draw_roundbox_aa(&rct, false, BASIS_RAD, color);
-  }
-
-  /* label and text */
-  node_draw_frame_label(*ntree, *node, *snode);
-
-  node_draw_extra_info_panel(*snode, *node);
-
-  UI_block_end(C, node->block);
-  UI_block_draw(C, node->block);
-  node->block = nullptr;
-}
-
 static void node_buts_frame_ex(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
 {
   uiItemR(layout, ptr, "label_size", DEFAULT_FLAGS, IFACE_("Label Size"), ICON_NONE);
@@ -460,53 +318,6 @@ static void node_buts_frame_ex(uiLayout *layout, bContext *UNUSED(C), PointerRNA
   uiItemR(layout, ptr, "text", DEFAULT_FLAGS, nullptr, ICON_NONE);
 }
 
-static void node_draw_reroute(const bContext *C,
-                              ARegion *region,
-                              SpaceNode *UNUSED(snode),
-                              bNodeTree *ntree,
-                              bNode *node,
-                              bNodeInstanceKey UNUSED(key))
-{
-  char showname[128]; /* 128 used below */
-  const rctf &rct = node->totr;
-
-  /* skip if out of view */
-  if (rct.xmax < region->v2d.cur.xmin || rct.xmin > region->v2d.cur.xmax ||
-      rct.ymax < region->v2d.cur.ymin || node->totr.ymin > region->v2d.cur.ymax) {
-    UI_block_end(C, node->block);
-    node->block = nullptr;
-    return;
-  }
-
-  if (node->label[0] != '\0') {
-    /* draw title (node label) */
-    BLI_strncpy(showname, node->label, sizeof(showname));
-    uiDefBut(node->block,
-             UI_BTYPE_LABEL,
-             0,
-             showname,
-             (int)(rct.xmin - NODE_DYS),
-             (int)(rct.ymax),
-             (short)512,
-             (short)NODE_DY,
-             nullptr,
-             0,
-             0,
-             0,
-             0,
-             nullptr);
-  }
-
-  /* only draw input socket. as they all are placed on the same position.
-   * highlight also if node itself is selected, since we don't display the node body separately!
-   */
-  node_draw_sockets(region->v2d, *C, *ntree, *node, false, node->flag & SELECT);
-
-  UI_block_end(C, node->block);
-  UI_block_draw(C, node->block);
-  node->block = nullptr;
-}
-
 static void node_common_set_butfunc(bNodeType *ntype)
 {
   switch (ntype->type) {
@@ -514,12 +325,8 @@ static void node_common_set_butfunc(bNodeType *ntype)
       ntype->draw_buttons = node_draw_buttons_group;
       break;
     case NODE_FRAME:
-      ntype->draw_nodetype = node_draw_frame;
       ntype->draw_buttons_ex = node_buts_frame_ex;
       break;
-    case NODE_REROUTE:
-      ntype->draw_nodetype = node_draw_reroute;
-      break;
   }
 }
 
@@ -3272,8 +3079,6 @@ void ED_node_init_butfuncs(void)
    * Defined in blenkernel, but not registered in type hashes.
    */
 
-  /* default ui functions */
-  NodeTypeUndefined.draw_nodetype = node_draw_default;
   NodeTypeUndefined.draw_buttons = nullptr;
   NodeTypeUndefined.draw_buttons_ex = nullptr;
 
@@ -3284,9 +3089,6 @@ void ED_node_init_butfuncs(void)
 
   /* node type ui functions */
   NODE_TYPES_BEGIN (ntype) {
-    /* default ui functions */
-    ntype->draw_nodetype = node_draw_default;
-
     node_common_set_butfunc(ntype);
 
     node_composit_set_butfunc(ntype);
@@ -3305,15 +3107,12 @@ void ED_node_init_butfuncs(void)
   ntreeType_Geometry->ui_icon = ICON_NODETREE;
 }
 
-void ED_init_custom_node_type(bNodeType *ntype)
+void ED_init_custom_node_type(bNodeType *UNUSED(ntype))
 {
-  /* default ui functions */
-  ntype->draw_nodetype = node_draw_default;
 }
 
 void ED_init_custom_node_socket_type(bNodeSocketType *stype)
 {
-  /* default ui functions */
   stype->draw = node_socket_button_label;
 }
 
diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc
index c2187d1d479..d9fa63de08f 100644
--- a/source/blender/editors/space_node/node_draw.cc
+++ b/source/blender/editors/space_node/node_draw.cc
@@ -31,6 +31,7 @@
 #include "DNA_node_types.h"
 #include "DNA_screen_types.h"
 #include "DNA_space_types.h"
+#include "DNA_text_types.h"
 #include "DNA_texture_types.h"
 #include "DNA_world_types.h"
 
@@ -1248,22 +1249,22 @@ static void node_toggle_button_cb(struct bContext *C, void *node_argv, void *op_
   WM_operator_name_call(C, opname, WM_OP_INVOKE_DEFAULT, nullptr);
 }
 
-void node_draw_shadow(const SpaceNode &snode,
-                      const bNode &node,
-                      const float radius,
-                      const float alpha)
+static void node_draw_shadow(const SpaceNode &snode,
+                             const bNode &node,
+                             const float radius,
+                             const float alpha)
 {
   const rctf &rct = node.totr;
   UI_draw_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list