forked from bartvdbraak/blender
add view selected for node view
This commit is contained in:
parent
95465e7a28
commit
258b4a8dad
@ -115,6 +115,7 @@ class NODE_MT_view(Menu):
|
||||
|
||||
layout.separator()
|
||||
|
||||
layout.operator("node.view_selected")
|
||||
layout.operator("node.view_all")
|
||||
|
||||
if context.space_data.show_backdrop:
|
||||
|
@ -113,6 +113,7 @@ void NODE_OT_select_same_type_prev(wmOperatorType *ot);
|
||||
|
||||
/* node_view.c */
|
||||
void NODE_OT_view_all(struct wmOperatorType *ot);
|
||||
void NODE_OT_view_selected(struct wmOperatorType *ot);
|
||||
|
||||
void NODE_OT_backimage_move(struct wmOperatorType *ot);
|
||||
void NODE_OT_backimage_zoom(struct wmOperatorType *ot);
|
||||
|
@ -60,6 +60,7 @@ void node_operatortypes(void)
|
||||
WM_operatortype_append(NODE_OT_select_same_type_prev);
|
||||
|
||||
WM_operatortype_append(NODE_OT_view_all);
|
||||
WM_operatortype_append(NODE_OT_view_selected);
|
||||
|
||||
WM_operatortype_append(NODE_OT_mute_toggle);
|
||||
WM_operatortype_append(NODE_OT_hide_toggle);
|
||||
@ -255,6 +256,7 @@ void node_keymap(struct wmKeyConfig *keyconf)
|
||||
WM_keymap_add_item(keymap, "NODE_OT_show_cyclic_dependencies", CKEY, KM_PRESS, 0, 0);
|
||||
|
||||
WM_keymap_add_item(keymap, "NODE_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
|
||||
WM_keymap_add_item(keymap, "NODE_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
|
||||
|
||||
kmi = WM_keymap_add_item(keymap, "NODE_OT_select_border", BKEY, KM_PRESS, 0, 0);
|
||||
RNA_boolean_set(kmi->ptr, "tweak", FALSE);
|
||||
|
@ -60,54 +60,52 @@
|
||||
|
||||
/* **************** View All Operator ************** */
|
||||
|
||||
static void snode_home(ScrArea *UNUSED(sa), ARegion *ar, SpaceNode *snode)
|
||||
static int snode_home(ScrArea *UNUSED(sa), ARegion *ar, SpaceNode *snode, const int node_flag)
|
||||
{
|
||||
bNode *node;
|
||||
rctf *cur;
|
||||
rctf cur_new;
|
||||
float oldwidth, oldheight, width, height;
|
||||
int first = 1;
|
||||
int change = FALSE;
|
||||
|
||||
cur = &ar->v2d.cur;
|
||||
|
||||
oldwidth = cur->xmax - cur->xmin;
|
||||
oldheight = cur->ymax - cur->ymin;
|
||||
|
||||
cur->xmin = cur->ymin = 0.0f;
|
||||
cur->xmax = ar->winx;
|
||||
cur->ymax = ar->winy;
|
||||
|
||||
oldwidth = ar->v2d.cur.xmax - ar->v2d.cur.xmin;
|
||||
oldheight = ar->v2d.cur.ymax - ar->v2d.cur.ymin;
|
||||
|
||||
BLI_rctf_init_minmax(&cur_new);
|
||||
|
||||
if (snode->edittree) {
|
||||
for (node = snode->edittree->nodes.first; node; node = node->next) {
|
||||
if (first) {
|
||||
first = 0;
|
||||
ar->v2d.cur = node->totr;
|
||||
}
|
||||
else {
|
||||
BLI_rctf_union(cur, &node->totr);
|
||||
if ((node->flag & node_flag) == node_flag) {
|
||||
BLI_rctf_union(&cur_new, &node->totr);
|
||||
change = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
snode->xof = 0;
|
||||
snode->yof = 0;
|
||||
width = cur->xmax - cur->xmin;
|
||||
height = cur->ymax - cur->ymin;
|
||||
|
||||
if (width > height) {
|
||||
float newheight;
|
||||
newheight = oldheight * width / oldwidth;
|
||||
cur->ymin = cur->ymin - newheight / 4;
|
||||
cur->ymax = cur->ymax + newheight / 4;
|
||||
}
|
||||
else {
|
||||
float newwidth;
|
||||
newwidth = oldwidth * height / oldheight;
|
||||
cur->xmin = cur->xmin - newwidth / 4;
|
||||
cur->xmax = cur->xmax + newwidth / 4;
|
||||
if (change) {
|
||||
snode->xof = 0;
|
||||
snode->yof = 0;
|
||||
width = cur_new.xmax - cur_new.xmin;
|
||||
height = cur_new.ymax - cur_new.ymin;
|
||||
|
||||
if (width > height) {
|
||||
float newheight;
|
||||
newheight = oldheight * width / oldwidth;
|
||||
cur_new.ymin = cur_new.ymin - newheight / 4;
|
||||
cur_new.ymax = cur_new.ymax + newheight / 4;
|
||||
}
|
||||
else {
|
||||
float newwidth;
|
||||
newwidth = oldwidth * height / oldheight;
|
||||
cur_new.xmin = cur_new.xmin - newwidth / 4;
|
||||
cur_new.xmax = cur_new.xmax + newwidth / 4;
|
||||
}
|
||||
|
||||
ar->v2d.tot = ar->v2d.cur = cur_new;
|
||||
UI_view2d_curRect_validate(&ar->v2d);
|
||||
}
|
||||
|
||||
ar->v2d.tot = ar->v2d.cur;
|
||||
UI_view2d_curRect_validate(&ar->v2d);
|
||||
return change;
|
||||
}
|
||||
|
||||
static int node_view_all_exec(bContext *C, wmOperator *UNUSED(op))
|
||||
@ -116,10 +114,14 @@ static int node_view_all_exec(bContext *C, wmOperator *UNUSED(op))
|
||||
ARegion *ar = CTX_wm_region(C);
|
||||
SpaceNode *snode = CTX_wm_space_node(C);
|
||||
|
||||
snode_home(sa, ar, snode);
|
||||
ED_region_tag_redraw(ar);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
if (snode_home(sa, ar, snode, 0)) {
|
||||
ED_region_tag_redraw(ar);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
else {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
}
|
||||
|
||||
void NODE_OT_view_all(wmOperatorType *ot)
|
||||
@ -137,6 +139,36 @@ void NODE_OT_view_all(wmOperatorType *ot)
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
}
|
||||
|
||||
static int node_view_selected_exec(bContext *C, wmOperator *UNUSED(op))
|
||||
{
|
||||
ScrArea *sa = CTX_wm_area(C);
|
||||
ARegion *ar = CTX_wm_region(C);
|
||||
SpaceNode *snode = CTX_wm_space_node(C);
|
||||
|
||||
if (snode_home(sa, ar, snode, NODE_SELECT)) {
|
||||
ED_region_tag_redraw(ar);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
else {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
}
|
||||
|
||||
void NODE_OT_view_selected(wmOperatorType *ot)
|
||||
{
|
||||
/* identifiers */
|
||||
ot->name = "View Selected";
|
||||
ot->idname = "NODE_OT_view_selected";
|
||||
ot->description = "Resize view so you can see selected nodes";
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec = node_view_selected_exec;
|
||||
ot->poll = ED_operator_node_active;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
}
|
||||
|
||||
/* **************** Backround Image Operators ************** */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user