Cleanup: Use C++ vector types in node editor

This commit is contained in:
Hans Goudey 2022-09-02 14:09:32 -05:00
parent 58c650a44c
commit 86e7aaead2
11 changed files with 155 additions and 153 deletions

View File

@ -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

View File

@ -293,7 +293,7 @@ static uiBlock *create_search_popup_block(bContext *C, ARegion *region, void *ar
0,
nullptr);
const int offset[2] = {0, -UI_UNIT_Y};
const int2 offset = {0, -UI_UNIT_Y};
UI_block_bounds_set_popup(block, 0.3f * U.widget_unit, offset);
return block;
}

View File

@ -104,7 +104,7 @@ bNode *add_static_node(const bContext &C, int type, const float2 &location)
static bool add_reroute_intersect_check(const bNodeLink &link,
float mcoords[][2],
int tot,
float result[2])
float2 &result)
{
float coord_array[NODE_LINK_RESOL + 1][2];
@ -126,13 +126,13 @@ struct bNodeSocketLink {
struct bNodeSocket *sock;
struct bNodeLink *link;
float point[2];
float2 point;
};
static bNodeSocketLink *add_reroute_insert_socket_link(ListBase *lb,
bNodeSocket *sock,
bNodeLink *link,
const float point[2])
const float2 &point)
{
bNodeSocketLink *socklink, *prev;
@ -158,10 +158,9 @@ static bNodeSocketLink *add_reroute_do_socket_section(bContext *C,
bNodeTree *ntree = snode->edittree;
bNode *reroute_node = nullptr;
bNodeSocket *cursock = socklink->sock;
float insert_point[2];
float2 insert_point{0.0f, 0.0f};
int num_links;
zero_v2(insert_point);
num_links = 0;
while (socklink && socklink->sock == cursock) {
@ -199,7 +198,7 @@ static bNodeSocketLink *add_reroute_do_socket_section(bContext *C,
socklink->link->tosock = (bNodeSocket *)reroute_node->inputs.first;
}
add_v2_v2(insert_point, socklink->point);
insert_point += socklink->point;
num_links++;
}
socklink = socklink->next;
@ -233,11 +232,9 @@ static int add_reroute_exec(bContext *C, wmOperator *op)
/* Get the cut path */
RNA_BEGIN (op->ptr, itemptr, "path") {
float loc[2];
float2 loc;
RNA_float_get_array(&itemptr, "loc", loc);
UI_view2d_region_to_view(
&region.v2d, (short)loc[0], (short)loc[1], &mcoords[i][0], &mcoords[i][1]);
UI_view2d_region_to_view(&region.v2d, loc.x, loc.y, &mcoords[i][0], &mcoords[i][1]);
i++;
if (i >= 256) {
break;
@ -248,7 +245,6 @@ static int add_reroute_exec(bContext *C, wmOperator *op)
if (i > 1) {
ListBase output_links, input_links;
bNodeSocketLink *socklink;
float insert_point[2];
/* always first */
ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
@ -263,6 +259,7 @@ static int add_reroute_exec(bContext *C, wmOperator *op)
if (node_link_is_hidden_or_dimmed(region.v2d, *link)) {
continue;
}
float2 insert_point;
if (add_reroute_intersect_check(*link, mcoords, i, insert_point)) {
add_reroute_insert_socket_link(&output_links, link->fromsock, link, insert_point);
add_reroute_insert_socket_link(&input_links, link->tosock, link, insert_point);

View File

@ -3104,8 +3104,8 @@ void node_draw_space(const bContext &C, ARegion &region)
}
/* Current View2D center, will be set temporarily for parent node trees. */
float center[2];
UI_view2d_center_get(&v2d, &center[0], &center[1]);
float2 center;
UI_view2d_center_get(&v2d, &center.x, &center.y);
/* Store new view center in path and current edit tree. */
copy_v2_v2(path->view_center, center);

View File

@ -956,14 +956,14 @@ struct NodeSizeWidget {
};
static void node_resize_init(
bContext *C, wmOperator *op, const float cursor[2], const bNode *node, NodeResizeDirection dir)
bContext *C, wmOperator *op, const float2 &cursor, const bNode *node, NodeResizeDirection dir)
{
NodeSizeWidget *nsw = MEM_cnew<NodeSizeWidget>(__func__);
op->customdata = nsw;
nsw->mxstart = cursor[0];
nsw->mystart = cursor[1];
nsw->mxstart = cursor.x;
nsw->mystart = cursor.y;
/* store old */
nsw->oldlocx = node->locx;
@ -1010,12 +1010,12 @@ static int node_resize_modal(bContext *C, wmOperator *op, const wmEvent *event)
switch (event->type) {
case MOUSEMOVE: {
int mval[2];
int2 mval;
WM_event_drag_start_mval(event, region, mval);
float mx, my;
UI_view2d_region_to_view(&region->v2d, mval[0], mval[1], &mx, &my);
float dx = (mx - nsw->mxstart) / UI_DPI_FAC;
float dy = (my - nsw->mystart) / UI_DPI_FAC;
UI_view2d_region_to_view(&region->v2d, mval.x, mval.y, &mx, &my);
const float dx = (mx - nsw->mxstart) / UI_DPI_FAC;
const float dy = (my - nsw->mystart) / UI_DPI_FAC;
if (node) {
float *pwidth = &node->width;
@ -1117,11 +1117,11 @@ static int node_resize_invoke(bContext *C, wmOperator *op, const wmEvent *event)
}
/* convert mouse coordinates to v2d space */
float cursor[2];
int mval[2];
float2 cursor;
int2 mval;
WM_event_drag_start_mval(event, region, mval);
UI_view2d_region_to_view(&region->v2d, mval[0], mval[1], &cursor[0], &cursor[1]);
const NodeResizeDirection dir = node_get_resize_direction(node, cursor[0], cursor[1]);
UI_view2d_region_to_view(&region->v2d, mval.x, mval.y, &cursor.x, &cursor.y);
const NodeResizeDirection dir = node_get_resize_direction(node, cursor.x, cursor.y);
if (dir == NODE_RESIZE_NONE) {
return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH;
}
@ -1199,7 +1199,7 @@ void node_set_hidden_sockets(SpaceNode *snode, bNode *node, int set)
}
/* checks snode->mouse position, and returns found node/socket */
static bool cursor_isect_multi_input_socket(const float cursor[2], const bNodeSocket &socket)
static bool cursor_isect_multi_input_socket(const float2 &cursor, const bNodeSocket &socket)
{
const float node_socket_height = node_socket_calculate_height(socket);
rctf multi_socket_rect;
@ -1213,7 +1213,7 @@ static bool cursor_isect_multi_input_socket(const float cursor[2], const bNodeSo
socket.locx + NODE_SOCKSIZE * 2.0f,
socket.locy - node_socket_height,
socket.locy + node_socket_height);
if (BLI_rctf_isect_pt(&multi_socket_rect, cursor[0], cursor[1])) {
if (BLI_rctf_isect_pt(&multi_socket_rect, cursor.x, cursor.y)) {
return true;
}
return false;
@ -2355,11 +2355,11 @@ static int node_clipboard_paste_exec(bContext *C, wmOperator *op)
node_deselect_all(*snode);
/* calculate "barycenter" for placing on mouse cursor */
float center[2] = {0.0f, 0.0f};
float2 center = {0.0f, 0.0f};
int num_nodes = 0;
LISTBASE_FOREACH_INDEX (bNode *, node, clipboard_nodes_lb, num_nodes) {
center[0] += BLI_rctf_cent_x(&node->totr);
center[1] += BLI_rctf_cent_y(&node->totr);
center.x += BLI_rctf_cent_x(&node->totr);
center.y += BLI_rctf_cent_y(&node->totr);
}
mul_v2_fl(center, 1.0 / num_nodes);

View File

@ -49,14 +49,14 @@ static void node_gizmo_calc_matrix_space(const SpaceNode *snode,
static void node_gizmo_calc_matrix_space_with_image_dims(const SpaceNode *snode,
const ARegion *region,
const float image_dims[2],
const float2 &image_dims,
float matrix_space[4][4])
{
unit_m4(matrix_space);
mul_v3_fl(matrix_space[0], snode->zoom * image_dims[0]);
mul_v3_fl(matrix_space[1], snode->zoom * image_dims[1]);
matrix_space[3][0] = ((region->winx / 2) + snode->xof) - ((image_dims[0] / 2.0f) * snode->zoom);
matrix_space[3][1] = ((region->winy / 2) + snode->yof) - ((image_dims[1] / 2.0f) * snode->zoom);
mul_v3_fl(matrix_space[0], snode->zoom * image_dims.x);
mul_v3_fl(matrix_space[1], snode->zoom * image_dims.y);
matrix_space[3][0] = ((region->winx / 2) + snode->xof) - ((image_dims.x / 2.0f) * snode->zoom);
matrix_space[3][1] = ((region->winy / 2) + snode->yof) - ((image_dims.y / 2.0f) * snode->zoom);
}
/** \} */
@ -135,7 +135,7 @@ static void WIDGETGROUP_node_transform_refresh(const bContext *C, wmGizmoGroup *
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, nullptr, &lock);
if (ibuf) {
const float dims[2] = {
const float2 dims = {
(ibuf->x > 0) ? ibuf->x : 64.0f,
(ibuf->y > 0) ? ibuf->y : 64.0f,
};
@ -190,7 +190,7 @@ struct NodeCropWidgetGroup {
wmGizmo *border;
struct {
float dims[2];
float2 dims;
} state;
struct {
@ -206,10 +206,7 @@ static void gizmo_node_crop_update(struct NodeCropWidgetGroup *crop_group)
crop_group->update_data.context, &crop_group->update_data.ptr, crop_group->update_data.prop);
}
static void two_xy_to_rect(const NodeTwoXYs *nxy,
rctf *rect,
const float dims[2],
bool is_relative)
static void two_xy_to_rect(const NodeTwoXYs *nxy, rctf *rect, const float2 &dims, bool is_relative)
{
if (is_relative) {
rect->xmin = nxy->fac_x1;
@ -218,16 +215,16 @@ static void two_xy_to_rect(const NodeTwoXYs *nxy,
rect->ymax = nxy->fac_y2;
}
else {
rect->xmin = nxy->x1 / dims[0];
rect->xmax = nxy->x2 / dims[0];
rect->ymin = nxy->y1 / dims[1];
rect->ymax = nxy->y2 / dims[1];
rect->xmin = nxy->x1 / dims.x;
rect->xmax = nxy->x2 / dims.x;
rect->ymin = nxy->y1 / dims.y;
rect->ymax = nxy->y2 / dims.y;
}
}
static void two_xy_from_rect(NodeTwoXYs *nxy,
const rctf *rect,
const float dims[2],
const float2 &dims,
bool is_relative)
{
if (is_relative) {
@ -237,10 +234,10 @@ static void two_xy_from_rect(NodeTwoXYs *nxy,
nxy->fac_y2 = rect->ymax;
}
else {
nxy->x1 = rect->xmin * dims[0];
nxy->x2 = rect->xmax * dims[0];
nxy->y1 = rect->ymin * dims[1];
nxy->y2 = rect->ymax * dims[1];
nxy->x1 = rect->xmin * dims.x;
nxy->x2 = rect->xmax * dims.x;
nxy->y1 = rect->ymin * dims.y;
nxy->y2 = rect->ymax * dims.y;
}
}
@ -407,7 +404,7 @@ struct NodeSunBeamsWidgetGroup {
wmGizmo *gizmo;
struct {
float dims[2];
float2 dims;
} state;
};
@ -512,7 +509,7 @@ struct NodeCornerPinWidgetGroup {
wmGizmo *gizmos[4];
struct {
float dims[2];
float2 dims;
} state;
};

View File

@ -717,13 +717,13 @@ static int node_get_selected_minmax(
INIT_MINMAX2(min, max);
LISTBASE_FOREACH (bNode *, node, &ntree.nodes) {
if (node_group_make_use_node(*node, gnode)) {
float loc[2];
nodeToView(node, node->offsetx, node->offsety, &loc[0], &loc[1]);
minmax_v2v2_v2(min, max, loc);
float2 loc;
nodeToView(node, node->offsetx, node->offsety, &loc.x, &loc.y);
math::min_max(loc, min, max);
if (use_size) {
loc[0] += node->width;
loc[1] -= node->height;
minmax_v2v2_v2(min, max, loc);
loc.x += node->width;
loc.y -= node->height;
math::min_max(loc, min, max);
}
totselect++;
}

View File

@ -241,7 +241,7 @@ bool node_link_bezier_points(const View2D *v2d,
bool node_link_bezier_handles(const View2D *v2d,
const SpaceNode *snode,
const bNodeLink &ink,
float vec[4][2]);
std::array<float2, 4> &points);
void draw_nodespace_back_pix(const bContext &C,
ARegion &region,
SpaceNode &snode,

View File

@ -128,7 +128,7 @@ static void pick_input_link_by_link_intersect(const bContext &C,
const ARegion *region = CTX_wm_region(&C);
const View2D *v2d = &region->v2d;
float drag_start[2];
float2 drag_start;
RNA_float_get_array(op.ptr, "drag_start", drag_start);
bNode *node;
bNodeSocket *socket;
@ -144,19 +144,27 @@ static void pick_input_link_by_link_intersect(const bContext &C,
LISTBASE_FOREACH (bNodeLink *, link, &snode->edittree->links) {
if (link->tosock == socket) {
/* Test if the cursor is near a link. */
float vec[4][2];
node_link_bezier_handles(v2d, snode, *link, vec);
std::array<float2, 4> points;
node_link_bezier_handles(v2d, snode, *link, points);
float data[NODE_LINK_RESOL * 2 + 2];
BKE_curve_forward_diff_bezier(
vec[0][0], vec[1][0], vec[2][0], vec[3][0], data, resolution, sizeof(float[2]));
BKE_curve_forward_diff_bezier(
vec[0][1], vec[1][1], vec[2][1], vec[3][1], data + 1, resolution, sizeof(float[2]));
std::array<float2, NODE_LINK_RESOL + 1> data;
BKE_curve_forward_diff_bezier(points[0].x,
points[1].x,
points[2].x,
points[3].x,
&data[0].x,
resolution,
sizeof(float2));
BKE_curve_forward_diff_bezier(points[0].y,
points[1].y,
points[2].y,
points[3].y,
&data[0].y,
resolution,
sizeof(float2));
for (int i = 0; i < resolution * 2; i += 2) {
float *l1 = &data[i];
float *l2 = &data[i + 2];
float distance = dist_squared_to_line_segment_v2(cursor, l1, l2);
for (const int i : IndexRange(data.size() - 1)) {
const float distance = dist_squared_to_line_segment_v2(cursor, data[i], data[i + 1]);
if (distance < cursor_link_touch_distance) {
link_to_pick = link;
nldrag.last_picked_multi_input_socket_link = link_to_pick;
@ -1177,7 +1185,7 @@ static int node_link_invoke(bContext *C, wmOperator *op, const wmEvent *event)
bool detach = RNA_boolean_get(op->ptr, "detach");
int mval[2];
int2 mval;
WM_event_drag_start_mval(event, &region, mval);
float2 cursor;
@ -1707,11 +1715,11 @@ void NODE_OT_join(wmOperatorType *ot)
static bNode *node_find_frame_to_attach(ARegion &region,
const bNodeTree &ntree,
const int mouse_xy[2])
const int2 mouse_xy)
{
/* convert mouse coordinates to v2d space */
float cursor[2];
UI_view2d_region_to_view(&region.v2d, UNPACK2(mouse_xy), &cursor[0], &cursor[1]);
float2 cursor;
UI_view2d_region_to_view(&region.v2d, mouse_xy.x, mouse_xy.y, &cursor.x, &cursor.y);
LISTBASE_FOREACH_BACKWARD (bNode *, frame, &ntree.nodes) {
/* skip selected, those are the nodes we want to attach */

View File

@ -193,7 +193,7 @@ static bool is_event_over_node_or_socket(bContext *C, const wmEvent *event)
ARegion *region = CTX_wm_region(C);
float2 mouse;
int mval[2];
int2 mval;
WM_event_drag_start_mval(event, region, mval);
UI_view2d_region_to_view(&region->v2d, mval[0], mval[1], &mouse.x, &mouse.y);
@ -514,7 +514,7 @@ void node_select_single(bContext &C, bNode &node)
static bool node_mouse_select(bContext *C,
wmOperator *op,
const int mval[2],
const int2 mval,
struct SelectPick_Params *params)
{
Main &bmain = *CTX_data_main(C);
@ -526,7 +526,7 @@ static bool node_mouse_select(bContext *C,
bNode *node, *tnode;
bNodeSocket *sock = nullptr;
bNodeSocket *tsock;
float cursor[2];
float2 cursor;
/* always do socket_select when extending selection. */
const bool socket_select = (params->sel_op == SEL_OP_XOR) ||
@ -536,7 +536,7 @@ static bool node_mouse_select(bContext *C,
bool node_was_selected = false;
/* get mouse coordinates in view2d space */
UI_view2d_region_to_view(&region.v2d, mval[0], mval[1], &cursor[0], &cursor[1]);
UI_view2d_region_to_view(&region.v2d, mval.x, mval.y, &cursor.x, &cursor.y);
/* first do socket selection, these generally overlap with nodes. */
if (socket_select) {
@ -667,7 +667,7 @@ static bool node_mouse_select(bContext *C,
static int node_select_exec(bContext *C, wmOperator *op)
{
/* get settings from RNA properties for operator */
int mval[2];
int2 mval;
RNA_int_get_array(op->ptr, "location", mval);
struct SelectPick_Params params = {};
@ -836,7 +836,7 @@ static int node_circleselect_exec(bContext *C, wmOperator *op)
bNode *node;
int x, y, radius;
float offset[2];
float2 offset;
float zoom = (float)(BLI_rcti_size_x(&region->winrct)) /
(float)(BLI_rctf_size_x(&region->v2d.cur));
@ -854,7 +854,7 @@ static int node_circleselect_exec(bContext *C, wmOperator *op)
y = RNA_int_get(op->ptr, "y");
radius = RNA_int_get(op->ptr, "radius");
UI_view2d_region_to_view(&region->v2d, x, y, &offset[0], &offset[1]);
UI_view2d_region_to_view(&region->v2d, x, y, &offset.x, &offset.y);
for (node = (bNode *)snode->edittree->nodes.first; node; node = node->next) {
switch (node->type) {
@ -968,14 +968,14 @@ static bool do_lasso_select_node(bContext *C,
break;
}
default: {
int screen_co[2];
const float cent[2] = {BLI_rctf_cent_x(&node->totr), BLI_rctf_cent_y(&node->totr)};
int2 screen_co;
const float2 center = {BLI_rctf_cent_x(&node->totr), BLI_rctf_cent_y(&node->totr)};
/* marker in screen coords */
if (UI_view2d_view_to_region_clip(
&region->v2d, cent[0], cent[1], &screen_co[0], &screen_co[1]) &&
BLI_rcti_isect_pt(&rect, screen_co[0], screen_co[1]) &&
BLI_lasso_is_point_inside(mcoords, mcoords_len, screen_co[0], screen_co[1], INT_MAX)) {
&region->v2d, center.x, center.y, &screen_co.x, &screen_co.y) &&
BLI_rcti_isect_pt(&rect, screen_co.x, screen_co.y) &&
BLI_lasso_is_point_inside(mcoords, mcoords_len, screen_co.x, screen_co.y, INT_MAX)) {
nodeSetSelected(node, select);
changed = true;
}

View File

@ -177,7 +177,7 @@ void NODE_OT_view_selected(wmOperatorType *ot)
* \{ */
struct NodeViewMove {
int mvalo[2];
int2 mvalo;
int xmin, ymin, xmax, ymax;
/** Original Offset for cancel. */
float xof_orig, yof_orig;
@ -192,10 +192,10 @@ static int snode_bg_viewmove_modal(bContext *C, wmOperator *op, const wmEvent *e
switch (event->type) {
case MOUSEMOVE:
snode->xof -= (nvm->mvalo[0] - event->mval[0]);
snode->yof -= (nvm->mvalo[1] - event->mval[1]);
nvm->mvalo[0] = event->mval[0];
nvm->mvalo[1] = event->mval[1];
snode->xof -= (nvm->mvalo.x - event->mval[0]);
snode->yof -= (nvm->mvalo.y - event->mval[1]);
nvm->mvalo.x = event->mval[0];
nvm->mvalo.y = event->mval[1];
/* prevent dragging image outside of the window and losing it! */
CLAMP(snode->xof, nvm->xmin, nvm->xmax);
@ -254,8 +254,8 @@ static int snode_bg_viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *
nvm = MEM_cnew<NodeViewMove>("NodeViewMove struct");
op->customdata = nvm;
nvm->mvalo[0] = event->mval[0];
nvm->mvalo[1] = event->mval[1];
nvm->mvalo.x = event->mval[0];
nvm->mvalo.y = event->mval[1];
nvm->xmin = -(region->winx / 2) - (ibuf->x * (0.5f * snode->zoom)) + pad;
nvm->xmax = (region->winx / 2) + (ibuf->x * (0.5f * snode->zoom)) - pad;