Cleanup: Use separate variables for node socket locations
This will help if the locations are moved out of DNA and require slightly more complicated access.
This commit is contained in:
parent
df40440d22
commit
4a4044ad9b
|
@ -720,8 +720,7 @@ static void node_socket_draw_multi_input(const float color[4],
|
|||
const float color_outline[4],
|
||||
const float width,
|
||||
const float height,
|
||||
const int locx,
|
||||
const int locy)
|
||||
const float2 location)
|
||||
{
|
||||
/* The other sockets are drawn with the keyframe shader. There, the outline has a base thickness
|
||||
* that can be varied but always scales with the size the socket is drawn at. Using `U.dpi_fac`
|
||||
|
@ -731,10 +730,10 @@ static void node_socket_draw_multi_input(const float color[4],
|
|||
|
||||
/* UI_draw_roundbox draws the outline on the outer side, so compensate for the outline width. */
|
||||
const rctf rect = {
|
||||
locx - width + outline_width * 0.5f,
|
||||
locx + width - outline_width * 0.5f,
|
||||
locy - height + outline_width * 0.5f,
|
||||
locy + height - outline_width * 0.5f,
|
||||
location.x - width + outline_width * 0.5f,
|
||||
location.x + width - outline_width * 0.5f,
|
||||
location.y - height + outline_width * 0.5f,
|
||||
location.y + height - outline_width * 0.5f,
|
||||
};
|
||||
|
||||
UI_draw_roundbox_corner_set(UI_CNR_ALL);
|
||||
|
@ -1126,9 +1125,10 @@ static void node_socket_draw_nested(const bContext &C,
|
|||
const float size,
|
||||
const bool selected)
|
||||
{
|
||||
const float2 location(sock.locx, sock.locy);
|
||||
|
||||
float color[4];
|
||||
float outline_color[4];
|
||||
|
||||
node_socket_color_get(C, ntree, node_ptr, sock, color);
|
||||
node_socket_outline_color_get(selected, sock.type, outline_color);
|
||||
|
||||
|
@ -1136,8 +1136,8 @@ static void node_socket_draw_nested(const bContext &C,
|
|||
color,
|
||||
outline_color,
|
||||
size,
|
||||
sock.locx,
|
||||
sock.locy,
|
||||
location.x,
|
||||
location.y,
|
||||
pos_id,
|
||||
col_id,
|
||||
shape_id,
|
||||
|
@ -1156,8 +1156,8 @@ static void node_socket_draw_nested(const bContext &C,
|
|||
UI_BTYPE_BUT,
|
||||
0,
|
||||
ICON_NONE,
|
||||
sock.locx - size / 2,
|
||||
sock.locy - size / 2,
|
||||
location.x - size / 2.0f,
|
||||
location.y - size / 2.0f,
|
||||
size,
|
||||
size,
|
||||
nullptr,
|
||||
|
@ -1530,7 +1530,8 @@ static void node_draw_sockets(const View2D &v2d,
|
|||
node_socket_color_get(C, ntree, node_ptr, *socket, color);
|
||||
node_socket_outline_color_get(socket->flag & SELECT, socket->type, outline_color);
|
||||
|
||||
node_socket_draw_multi_input(color, outline_color, width, height, socket->locx, socket->locy);
|
||||
const float2 location(socket->locx, socket->locy);
|
||||
node_socket_draw_multi_input(color, outline_color, width, height, location);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -921,7 +921,7 @@ static void edit_node_properties_get(
|
|||
/** \name Node Generic
|
||||
* \{ */
|
||||
|
||||
static bool socket_is_occluded(const bNodeSocket &sock,
|
||||
static bool socket_is_occluded(const float2 &location,
|
||||
const bNode &node_the_socket_belongs_to,
|
||||
const SpaceNode &snode)
|
||||
{
|
||||
|
@ -933,7 +933,7 @@ static bool socket_is_occluded(const bNodeSocket &sock,
|
|||
|
||||
rctf socket_hitbox;
|
||||
const float socket_hitbox_radius = NODE_SOCKSIZE - 0.1f * U.widget_unit;
|
||||
BLI_rctf_init_pt_radius(&socket_hitbox, float2(sock.locx, sock.locy), socket_hitbox_radius);
|
||||
BLI_rctf_init_pt_radius(&socket_hitbox, location, socket_hitbox_radius);
|
||||
if (BLI_rctf_inside_rctf(&node->totr, &socket_hitbox)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -1202,17 +1202,18 @@ void node_set_hidden_sockets(SpaceNode *snode, bNode *node, int set)
|
|||
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;
|
||||
const float2 location(socket.locx, socket.locy);
|
||||
/* `.xmax = socket->locx + NODE_SOCKSIZE * 5.5f`
|
||||
* would be the same behavior as for regular sockets.
|
||||
* But keep it smaller because for multi-input socket you
|
||||
* sometimes want to drag the link to the other side, if you may
|
||||
* accidentally pick the wrong link otherwise. */
|
||||
rctf multi_socket_rect;
|
||||
BLI_rctf_init(&multi_socket_rect,
|
||||
socket.locx - NODE_SOCKSIZE * 4.0f,
|
||||
socket.locx + NODE_SOCKSIZE * 2.0f,
|
||||
socket.locy - node_socket_height,
|
||||
socket.locy + node_socket_height);
|
||||
location.x - NODE_SOCKSIZE * 4.0f,
|
||||
location.x + NODE_SOCKSIZE * 2.0f,
|
||||
location.y - node_socket_height,
|
||||
location.y + node_socket_height);
|
||||
if (BLI_rctf_isect_pt(&multi_socket_rect, cursor.x, cursor.y)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -1251,17 +1252,18 @@ bool node_find_indicated_socket(SpaceNode &snode,
|
|||
if (in_out & SOCK_IN) {
|
||||
LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) {
|
||||
if (!nodeSocketIsHidden(sock)) {
|
||||
const float2 location(sock->locx, sock->locy);
|
||||
if (sock->flag & SOCK_MULTI_INPUT && !(node->flag & NODE_HIDDEN)) {
|
||||
if (cursor_isect_multi_input_socket(cursor, *sock)) {
|
||||
if (!socket_is_occluded(*sock, *node, snode)) {
|
||||
if (!socket_is_occluded(location, *node, snode)) {
|
||||
*nodep = node;
|
||||
*sockp = sock;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (BLI_rctf_isect_pt(&rect, sock->locx, sock->locy)) {
|
||||
if (!socket_is_occluded(*sock, *node, snode)) {
|
||||
else if (BLI_rctf_isect_pt(&rect, location.x, location.y)) {
|
||||
if (!socket_is_occluded(location, *node, snode)) {
|
||||
*nodep = node;
|
||||
*sockp = sock;
|
||||
return true;
|
||||
|
@ -1273,8 +1275,9 @@ bool node_find_indicated_socket(SpaceNode &snode,
|
|||
if (in_out & SOCK_OUT) {
|
||||
LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) {
|
||||
if (!nodeSocketIsHidden(sock)) {
|
||||
if (BLI_rctf_isect_pt(&rect, sock->locx, sock->locy)) {
|
||||
if (!socket_is_occluded(*sock, *node, snode)) {
|
||||
const float2 location(sock->locx, sock->locy);
|
||||
if (BLI_rctf_isect_pt(&rect, location.x, location.y)) {
|
||||
if (!socket_is_occluded(location, *node, snode)) {
|
||||
*nodep = node;
|
||||
*sockp = sock;
|
||||
return true;
|
||||
|
@ -1300,11 +1303,12 @@ float node_link_dim_factor(const View2D &v2d, const bNodeLink &link)
|
|||
return 1.0f;
|
||||
}
|
||||
|
||||
const float2 from(link.fromsock->locx, link.fromsock->locy);
|
||||
const float2 to(link.tosock->locx, link.tosock->locy);
|
||||
|
||||
const float min_endpoint_distance = std::min(
|
||||
std::max(BLI_rctf_length_x(&v2d.cur, link.fromsock->locx),
|
||||
BLI_rctf_length_y(&v2d.cur, link.fromsock->locy)),
|
||||
std::max(BLI_rctf_length_x(&v2d.cur, link.tosock->locx),
|
||||
BLI_rctf_length_y(&v2d.cur, link.tosock->locy)));
|
||||
std::max(BLI_rctf_length_x(&v2d.cur, from.x), BLI_rctf_length_y(&v2d.cur, from.y)),
|
||||
std::max(BLI_rctf_length_x(&v2d.cur, to.x), BLI_rctf_length_y(&v2d.cur, to.y)));
|
||||
|
||||
if (min_endpoint_distance == 0.0f) {
|
||||
return 1.0f;
|
||||
|
|
Loading…
Reference in New Issue