diff options
author | Hans Goudey <h.goudey@me.com> | 2022-09-02 22:09:32 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-09-02 22:09:41 +0300 |
commit | 86e7aaead29b22dee7949f49498152c59395258f (patch) | |
tree | 1ad1d2b4fa18420a170ac7243639be0172ec5143 /source/blender/editors/space_node/drawnode.cc | |
parent | 58c650a44c251a41c89375d697efdf07153016e0 (diff) |
Cleanup: Use C++ vector types in node editor
Diffstat (limited to 'source/blender/editors/space_node/drawnode.cc')
-rw-r--r-- | source/blender/editors/space_node/drawnode.cc | 118 |
1 files changed, 59 insertions, 59 deletions
diff --git a/source/blender/editors/space_node/drawnode.cc b/source/blender/editors/space_node/drawnode.cc index 262b33dc0a3..ca9f305379e 100644 --- a/source/blender/editors/space_node/drawnode.cc +++ b/source/blender/editors/space_node/drawnode.cc @@ -1588,75 +1588,70 @@ void draw_nodespace_back_pix(const bContext &C, bool node_link_bezier_handles(const View2D *v2d, const SpaceNode *snode, const bNodeLink &link, - float vec[4][2]) + std::array<float2, 4> &points) { - float cursor[2] = {0.0f, 0.0f}; + float2 cursor = {0.0f, 0.0f}; /* this function can be called with snode null (via cut_links_intersect) */ /* XXX map snode->runtime->cursor back to view space */ if (snode) { - cursor[0] = snode->runtime->cursor[0] * UI_DPI_FAC; - cursor[1] = snode->runtime->cursor[1] * UI_DPI_FAC; + cursor = snode->runtime->cursor * UI_DPI_FAC; } /* in v0 and v3 we put begin/end points */ if (link.fromsock) { - vec[0][0] = link.fromsock->locx; - vec[0][1] = link.fromsock->locy; + points[0].x = link.fromsock->locx; + points[0].y = link.fromsock->locy; if (link.fromsock->flag & SOCK_MULTI_INPUT) { - const float2 position = node_link_calculate_multi_input_position( + points[0] = node_link_calculate_multi_input_position( {link.fromsock->locx, link.fromsock->locy}, link.fromsock->total_inputs - 1, link.fromsock->total_inputs); - copy_v2_v2(vec[0], position); } } else { if (snode == nullptr) { return false; } - copy_v2_v2(vec[0], cursor); + points[0] = cursor; } if (link.tosock) { - vec[3][0] = link.tosock->locx; - vec[3][1] = link.tosock->locy; + points[3].x = link.tosock->locx; + points[3].y = link.tosock->locy; if (!(link.tonode->flag & NODE_HIDDEN) && link.tosock->flag & SOCK_MULTI_INPUT) { - const float2 position = node_link_calculate_multi_input_position( - {link.tosock->locx, link.tosock->locy}, - link.multi_input_socket_index, - link.tosock->total_inputs); - copy_v2_v2(vec[3], position); + points[3] = node_link_calculate_multi_input_position({link.tosock->locx, link.tosock->locy}, + link.multi_input_socket_index, + link.tosock->total_inputs); } } else { if (snode == nullptr) { return false; } - copy_v2_v2(vec[3], cursor); + points[3] = cursor; } - /* may be called outside of drawing (so pass spacetype) */ - int curving = UI_GetThemeValueType(TH_NODE_CURVING, SPACE_NODE); + const int curving = UI_GetThemeValueType(TH_NODE_CURVING, SPACE_NODE); if (curving == 0) { /* Straight line: align all points. */ - interp_v2_v2v2(vec[1], vec[0], vec[3], 1.0f / 3.0f); - interp_v2_v2v2(vec[2], vec[0], vec[3], 2.0f / 3.0f); + points[1] = math::interpolate(points[0], points[3], 1.0f / 3.0f); + points[2] = math::interpolate(points[0], points[3], 2.0f / 3.0f); return true; } - const float dist = curving * 0.10f * fabsf(vec[0][0] - vec[3][0]); + const float dist = curving * 0.10f * fabsf(points[0].x - points[3].x); - vec[1][0] = vec[0][0] + dist; - vec[1][1] = vec[0][1]; + points[1].x = points[0].x + dist; + points[1].y = points[0].y; - vec[2][0] = vec[3][0] - dist; - vec[2][1] = vec[3][1]; + points[2].x = points[3].x - dist; + points[2].y = points[3].y; - if (v2d && min_ffff(vec[0][0], vec[1][0], vec[2][0], vec[3][0]) > v2d->cur.xmax) { + if (v2d && min_ffff(points[0].x, points[1].x, points[2].x, points[3].x) > v2d->cur.xmax) { return false; /* clipped */ } - if (v2d && max_ffff(vec[0][0], vec[1][0], vec[2][0], vec[3][0]) < v2d->cur.xmin) { + if (v2d && max_ffff(points[0].x, points[1].x, points[2].x, points[3].x) < v2d->cur.xmin) { return false; /* clipped */ } @@ -1669,14 +1664,24 @@ bool node_link_bezier_points(const View2D *v2d, float coord_array[][2], const int resol) { - float vec[4][2]; + std::array<float2, 4> points; - if (node_link_bezier_handles(v2d, snode, link, vec)) { + if (node_link_bezier_handles(v2d, snode, link, points)) { /* always do all three, to prevent data hanging around */ - BKE_curve_forward_diff_bezier( - vec[0][0], vec[1][0], vec[2][0], vec[3][0], coord_array[0] + 0, resol, sizeof(float[2])); - BKE_curve_forward_diff_bezier( - vec[0][1], vec[1][1], vec[2][1], vec[3][1], coord_array[0] + 1, resol, sizeof(float[2])); + BKE_curve_forward_diff_bezier(points[0].x, + points[1].x, + points[2].x, + points[3].x, + coord_array[0] + 0, + resol, + sizeof(float[2])); + BKE_curve_forward_diff_bezier(points[0].y, + points[1].y, + points[2].y, + points[3].y, + coord_array[0] + 1, + resol, + sizeof(float[2])); return true; } @@ -1959,10 +1964,7 @@ struct NodeLinkDrawConfig { }; static void nodelink_batch_add_link(const SpaceNode &snode, - const float2 &p0, - const float2 &p1, - const float2 &p2, - const float2 &p3, + const std::array<float2, 4> &points, const NodeLinkDrawConfig &draw_config) { /* Only allow these colors. If more is needed, you need to modify the shader accordingly. */ @@ -1973,10 +1975,10 @@ static void nodelink_batch_add_link(const SpaceNode &snode, BLI_assert(ELEM(draw_config.th_col3, TH_WIRE, TH_REDALERT, -1)); g_batch_link.count++; - copy_v2_v2((float *)GPU_vertbuf_raw_step(&g_batch_link.p0_step), p0); - copy_v2_v2((float *)GPU_vertbuf_raw_step(&g_batch_link.p1_step), p1); - copy_v2_v2((float *)GPU_vertbuf_raw_step(&g_batch_link.p2_step), p2); - copy_v2_v2((float *)GPU_vertbuf_raw_step(&g_batch_link.p3_step), p3); + copy_v2_v2((float *)GPU_vertbuf_raw_step(&g_batch_link.p0_step), points[0]); + copy_v2_v2((float *)GPU_vertbuf_raw_step(&g_batch_link.p1_step), points[1]); + copy_v2_v2((float *)GPU_vertbuf_raw_step(&g_batch_link.p2_step), points[2]); + copy_v2_v2((float *)GPU_vertbuf_raw_step(&g_batch_link.p3_step), points[3]); char *colid = (char *)GPU_vertbuf_raw_step(&g_batch_link.colid_step); colid[0] = nodelink_get_color_id(draw_config.th_col1); colid[1] = nodelink_get_color_id(draw_config.th_col2); @@ -2012,19 +2014,17 @@ static void node_draw_link_end_marker(const float2 center, static void node_draw_link_end_markers(const bNodeLink &link, const NodeLinkDrawConfig &draw_config, - const float handles[4][2], + const std::array<float2, 4> &points, const bool outline) { const float radius = (outline ? 0.65f : 0.45f) * NODE_SOCKSIZE; if (link.fromsock) { - const float2 link_start(handles[0]); node_draw_link_end_marker( - link_start, radius, outline ? draw_config.outline_color : draw_config.start_color); + points[0], radius, outline ? draw_config.outline_color : draw_config.start_color); } if (link.tosock) { - const float2 link_end(handles[3]); node_draw_link_end_marker( - link_end, radius, outline ? draw_config.outline_color : draw_config.end_color); + points[3], radius, outline ? draw_config.outline_color : draw_config.end_color); } } @@ -2130,7 +2130,7 @@ static NodeLinkDrawConfig nodelink_get_draw_config(const bContext &C, static void node_draw_link_bezier_ex(const SpaceNode &snode, const NodeLinkDrawConfig &draw_config, - const float handles[4][2]) + const std::array<float2, 4> &points) { if (g_batch_link.batch == nullptr) { nodelink_batch_init(); @@ -2138,12 +2138,12 @@ static void node_draw_link_bezier_ex(const SpaceNode &snode, if (g_batch_link.enabled && !draw_config.highlighted) { /* Add link to batch. */ - nodelink_batch_add_link(snode, handles[0], handles[1], handles[2], handles[3], draw_config); + nodelink_batch_add_link(snode, points, draw_config); } else { NodeLinkData node_link_data; - for (int i = 0; i < 4; i++) { - copy_v2_v2(node_link_data.bezierPts[i], handles[i]); + for (const int i : IndexRange(points.size())) { + copy_v2_v2(node_link_data.bezierPts[i], points[i]); } copy_v4_v4(node_link_data.colors[0], draw_config.outline_color); @@ -2180,14 +2180,14 @@ void node_draw_link_bezier(const bContext &C, const int th_col3, const bool selected) { - float handles[4][2]; - if (!node_link_bezier_handles(&v2d, &snode, link, handles)) { + std::array<float2, 4> points; + if (!node_link_bezier_handles(&v2d, &snode, link, points)) { return; } const NodeLinkDrawConfig draw_config = nodelink_get_draw_config( C, v2d, snode, link, th_col1, th_col2, th_col3, selected); - node_draw_link_bezier_ex(snode, draw_config, handles); + node_draw_link_bezier_ex(snode, draw_config, points); } void node_draw_link(const bContext &C, @@ -2245,19 +2245,19 @@ void node_draw_link_dragged(const bContext &C, return; } - float handles[4][2]; - if (!node_link_bezier_handles(&v2d, &snode, link, handles)) { + std::array<float2, 4> points; + if (!node_link_bezier_handles(&v2d, &snode, link, points)) { return; } const NodeLinkDrawConfig draw_config = nodelink_get_draw_config( C, v2d, snode, link, TH_ACTIVE, TH_ACTIVE, TH_WIRE, true); /* End marker outline. */ - node_draw_link_end_markers(link, draw_config, handles, true); + node_draw_link_end_markers(link, draw_config, points, true); /* Link. */ - node_draw_link_bezier_ex(snode, draw_config, handles); + node_draw_link_bezier_ex(snode, draw_config, points); /* End marker fill. */ - node_draw_link_end_markers(link, draw_config, handles, false); + node_draw_link_end_markers(link, draw_config, points, false); } } // namespace blender::ed::space_node |