Patch #37274: Circle select for node editor, by Henrik Aarnio (hjaarnio).

Circle select was missing from node editor, and C key was assigned to now defunct "show cyclic dependencies". This patch remaps the key and adds circle select operator.
Functions to check intersection between rctf/rcti and a circle were also added to rct.c for code cleanliness and consistency.
This commit is contained in:
Lukas Toenne 2013-11-06 19:21:42 +00:00
parent 549ed3d378
commit 61c411068b
7 changed files with 91 additions and 0 deletions

@ -169,6 +169,7 @@ class NODE_MT_select(Menu):
layout = self.layout
layout.operator("node.select_border")
layout.operator("node.select_circle")
layout.separator()
layout.operator("node.select_all").action = 'TOGGLE'

@ -74,6 +74,8 @@ bool BLI_rctf_isect_pt(const struct rctf *rect, const float x, const float y);
bool BLI_rctf_isect_pt_v(const struct rctf *rect, const float xy[2]);
bool BLI_rcti_isect_segment(const struct rcti *rect, const int s1[2], const int s2[2]);
bool BLI_rctf_isect_segment(const struct rctf *rect, const float s1[2], const float s2[2]);
bool BLI_rcti_isect_circle(const struct rcti *rect, const float xy[2], const float radius);
bool BLI_rctf_isect_circle(const struct rctf *rect, const float xy[2], const float radius);
bool BLI_rcti_inside_rcti(rcti *rct_a, const rcti *rct_b);
bool BLI_rctf_inside_rctf(rctf *rct_a, const rctf *rct_b);
void BLI_rcti_union(struct rcti *rcti1, const struct rcti *rcti2);

@ -216,6 +216,32 @@ bool BLI_rctf_isect_segment(const rctf *rect, const float s1[2], const float s2[
}
}
bool BLI_rcti_isect_circle(const rcti *rect, const float xy[2], const float radius)
{
float dx, dy;
if (xy[0] >= rect->xmin && xy[0] <= rect->xmax) dx = 0;
else dx = (xy[0] < rect->xmin) ? (rect->xmin - xy[0]) : (xy[0] - rect->xmax);
if (xy[1] >= rect->ymin && xy[1] <= rect->ymax) dy = 0;
else dy = (xy[1] < rect->ymin) ? (rect->ymin - xy[1]) : (xy[1] - rect->ymax);
return dx * dx + dy * dy <= radius * radius;
}
bool BLI_rctf_isect_circle(const rctf *rect, const float xy[2], const float radius)
{
float dx, dy;
if (xy[0] >= rect->xmin && xy[0] <= rect->xmax) dx = 0;
else dx = (xy[0] < rect->xmin) ? (rect->xmin - xy[0]) : (xy[0] - rect->xmax);
if (xy[1] >= rect->ymin && xy[1] <= rect->ymax) dy = 0;
else dy = (xy[1] < rect->ymin) ? (rect->ymin - xy[1]) : (xy[1] - rect->ymax);
return dx * dx + dy * dy <= radius * radius;
}
void BLI_rctf_union(rctf *rct1, const rctf *rct2)
{
if (rct1->xmin > rct2->xmin) rct1->xmin = rct2->xmin;

@ -116,6 +116,7 @@ void NODE_OT_select_all(struct wmOperatorType *ot);
void NODE_OT_select_linked_to(struct wmOperatorType *ot);
void NODE_OT_select_linked_from(struct wmOperatorType *ot);
void NODE_OT_select_border(struct wmOperatorType *ot);
void NODE_OT_select_circle(struct wmOperatorType *ot);
void NODE_OT_select_lasso(struct wmOperatorType *ot);
void NODE_OT_select_same_type(struct wmOperatorType *ot);
void NODE_OT_select_same_type_step(struct wmOperatorType *ot);

@ -56,6 +56,7 @@ void node_operatortypes(void)
WM_operatortype_append(NODE_OT_select_linked_to);
WM_operatortype_append(NODE_OT_select_linked_from);
WM_operatortype_append(NODE_OT_select_border);
WM_operatortype_append(NODE_OT_select_circle);
WM_operatortype_append(NODE_OT_select_lasso);
WM_operatortype_append(NODE_OT_select_same_type);
WM_operatortype_append(NODE_OT_select_same_type_step);
@ -232,6 +233,8 @@ void node_keymap(struct wmKeyConfig *keyconf)
kmi = WM_keymap_add_item(keymap, "NODE_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL | KM_SHIFT | KM_ALT, 0);
RNA_boolean_set(kmi->ptr, "deselect", TRUE);
WM_keymap_add_item(keymap, "NODE_OT_select_circle", CKEY, KM_PRESS, 0, 0);
/* each of these falls through if not handled... */
kmi = WM_keymap_add_item(keymap, "NODE_OT_link", LEFTMOUSE, KM_PRESS, 0, 0);
RNA_boolean_set(kmi->ptr, "detach", FALSE);

@ -514,6 +514,63 @@ void NODE_OT_select_border(wmOperatorType *ot)
RNA_def_boolean(ot->srna, "tweak", 0, "Tweak", "Only activate when mouse is not over a node - useful for tweak gesture");
}
/* ****** Circle Select ****** */
static int node_circleselect_exec(bContext *C, wmOperator *op)
{
SpaceNode *snode = CTX_wm_space_node(C);
ARegion *ar = CTX_wm_region(C);
bNode *node;
int x, y, radius, gesture_mode;
float offset[2];
float zoom = (float)(BLI_rcti_size_x(&ar->winrct)) / (float)(BLI_rctf_size_x(&ar->v2d.cur));
gesture_mode = RNA_int_get(op->ptr, "gesture_mode");
/* get operator properties */
x = RNA_int_get(op->ptr, "x");
y = RNA_int_get(op->ptr, "y");
radius = RNA_int_get(op->ptr, "radius");
UI_view2d_region_to_view(&ar->v2d, x, y, &offset[0], &offset[1]);
for (node = snode->edittree->nodes.first; node; node = node->next) {
if (BLI_rctf_isect_circle(&node->totr, offset, radius / zoom)) {
nodeSetSelected(node, (gesture_mode == GESTURE_MODAL_SELECT));
}
}
WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL);
return OPERATOR_FINISHED;
}
void NODE_OT_select_circle(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Circle Select";
ot->idname = "NODE_OT_select_circle";
ot->description = "Use circle selection to select nodes";
/* api callbacks */
ot->invoke = WM_gesture_circle_invoke;
ot->exec = node_circleselect_exec;
ot->modal = WM_gesture_circle_modal;
ot->poll = ED_operator_node_active;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* rna */
RNA_def_int(ot->srna, "x", 0, INT_MIN, INT_MAX, "X", "", INT_MIN, INT_MAX);
RNA_def_int(ot->srna, "y", 0, INT_MIN, INT_MAX, "Y", "", INT_MIN, INT_MAX);
RNA_def_int(ot->srna, "radius", 0, INT_MIN, INT_MAX, "Radius", "", INT_MIN, INT_MAX);
RNA_def_int(ot->srna, "gesture_mode", 0, INT_MIN, INT_MAX, "Gesture Mode", "", INT_MIN, INT_MAX);
}
/* ****** Lasso Select ****** */
static int do_lasso_select_node(bContext *C, const int mcords[][2], short moves, short select)

@ -4271,6 +4271,7 @@ static void gesture_circle_modal_keymap(wmKeyConfig *keyconf)
WM_modalkeymap_assign(keymap, "UV_OT_circle_select");
WM_modalkeymap_assign(keymap, "CLIP_OT_select_circle");
WM_modalkeymap_assign(keymap, "MASK_OT_select_circle");
WM_modalkeymap_assign(keymap, "NODE_OT_select_circle");
}