Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2021-12-06 01:12:25 +0300
committerHans Goudey <h.goudey@me.com>2021-12-06 01:12:25 +0300
commit9a312ba19284f6d4b81378d145b24b6b76a2c082 (patch)
treeb3c14b620a23a20f0651a334cb2b463577b9eb6d /source
parent338c1060d5d7b6a8bd3ec5632f543738de4c103c (diff)
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.
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/BKE_node.h8
-rw-r--r--source/blender/editors/space_node/drawnode.cc203
-rw-r--r--source/blender/editors/space_node/node_draw.cc248
-rw-r--r--source/blender/editors/space_node/node_intern.hh20
4 files changed, 214 insertions, 265 deletions
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_roundbox_corner_set(UI_CNR_ALL);
ui_draw_dropshadow(&rct, radius, snode.runtime->aspect, alpha, node.flag & SELECT);
}
-void node_draw_sockets(const View2D &v2d,
- const bContext &C,
- bNodeTree &ntree,
- bNode &node,
- const bool draw_outputs,
- const bool select_all)
+static void node_draw_sockets(const View2D &v2d,
+ const bContext &C,
+ bNodeTree &ntree,
+ bNode &node,
+ const bool draw_outputs,
+ const bool select_all)
{
const uint total_input_len = BLI_listbase_count(&node.inputs);
const uint total_output_len = BLI_listbase_count(&node.outputs);
@@ -1746,7 +1747,7 @@ static void node_draw_extra_info_row(const bNode &node,
}
}
-void node_draw_extra_info_panel(const SpaceNode &snode, const bNode &node)
+static void node_draw_extra_info_panel(const SpaceNode &snode, const bNode &node)
{
Vector<NodeExtraInfoRow> extra_info_rows = node_get_extra_info(snode, node);
@@ -2310,22 +2311,6 @@ void node_set_cursor(wmWindow &win, SpaceNode &snode, const float2 &cursor)
WM_cursor_set(&win, wmcursor);
}
-void node_draw_default(const bContext *C,
- ARegion *region,
- SpaceNode *snode,
- bNodeTree *ntree,
- bNode *node,
- bNodeInstanceKey key)
-{
- const View2D *v2d = &region->v2d;
- if (node->flag & NODE_HIDDEN) {
- node_draw_hidden(*C, *v2d, *snode, *ntree, *node);
- }
- else {
- node_draw_basis(*C, *v2d, *snode, *ntree, *node, key);
- }
-}
-
static void count_multi_input_socket_links(bNodeTree &ntree, SpaceNode &snode)
{
Map<bNodeSocket *, int> counts;
@@ -2457,25 +2442,218 @@ void node_update_nodetree(const bContext &C, bNodeTree &ntree)
}
}
+static void frame_node_draw_label(bNodeTree &ntree, bNode &node, const 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 frame_node_draw(const bContext &C,
+ const ARegion &region,
+ const SpaceNode &snode,
+ bNodeTree &ntree,
+ bNode &node)
+{
+ /* 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 */
+ frame_node_draw_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 reroute_node_draw(const bContext &C, ARegion &region, bNodeTree &ntree, bNode &node)
+{
+ 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_draw(const bContext &C,
ARegion &region,
- SpaceNode &snode,
+ const SpaceNode &snode,
bNodeTree &ntree,
bNode &node,
bNodeInstanceKey key)
{
- if (node.typeinfo->draw_nodetype) {
- node.typeinfo->draw_nodetype(&C, &region, &snode, &ntree, &node, key);
+ if (node.type == NODE_FRAME) {
+ frame_node_draw(C, region, snode, ntree, node);
+ }
+ else if (node.type == NODE_REROUTE) {
+ reroute_node_draw(C, region, ntree, node);
+ }
+ else {
+ const View2D &v2d = region.v2d;
+ if (node.flag & NODE_HIDDEN) {
+ node_draw_hidden(C, v2d, snode, ntree, node);
+ }
+ else {
+ node_draw_basis(C, v2d, snode, ntree, node, key);
+ }
}
}
#define USE_DRAW_TOT_UPDATE
-void node_draw_nodetree(const bContext &C,
- ARegion &region,
- SpaceNode &snode,
- bNodeTree &ntree,
- bNodeInstanceKey parent_key)
+static void node_draw_nodetree(const bContext &C,
+ ARegion &region,
+ SpaceNode &snode,
+ bNodeTree &ntree,
+ bNodeInstanceKey parent_key)
{
#ifdef USE_DRAW_TOT_UPDATE
if (ntree.nodes.first) {
diff --git a/source/blender/editors/space_node/node_intern.hh b/source/blender/editors/space_node/node_intern.hh
index 980611cc909..71cdd9145b9 100644
--- a/source/blender/editors/space_node/node_intern.hh
+++ b/source/blender/editors/space_node/node_intern.hh
@@ -100,34 +100,14 @@ void node_link_calculate_multi_input_position(const float socket_x,
float r[2]);
int node_get_colorid(bNode &node);
-void node_draw_extra_info_panel(const SpaceNode &snode, const bNode &node);
int node_get_resize_cursor(NodeResizeDirection directions);
-void node_draw_shadow(const SpaceNode &snode, const bNode &node, float radius, float alpha);
-void node_draw_default(const bContext *C,
- ARegion *region,
- SpaceNode *snode,
- bNodeTree *ntree,
- bNode *node,
- bNodeInstanceKey key);
-void node_draw_sockets(const View2D &v2d,
- const bContext &C,
- bNodeTree &ntree,
- bNode &node,
- const bool draw_outputs,
- const bool select_all);
NodeResizeDirection node_get_resize_direction(const bNode *node, const int x, const int y);
-int node_tweak_area_default(bNode *node, int x, int y);
void node_socket_color_get(const bContext &C,
const bNodeTree &ntree,
PointerRNA &node_ptr,
const bNodeSocket &sock,
float r_color[4]);
void node_update_nodetree(const bContext &C, bNodeTree &ntree);
-void node_draw_nodetree(const bContext &C,
- ARegion &region,
- SpaceNode &snode,
- bNodeTree &ntree,
- bNodeInstanceKey parent_key);
void node_draw_space(const bContext &C, ARegion &region);
void node_set_cursor(wmWindow &win, SpaceNode &snode, const blender::float2 &cursor);