Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_node/node_view.c
| Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | |||||
| /* **************** View All Operator ************** */ | /* **************** View All Operator ************** */ | ||||
| int space_node_view_flag( | int space_node_view_flag( | ||||
| bContext *C, SpaceNode *snode, ARegion *ar, const int node_flag, const int smooth_viewtx) | bContext *C, SpaceNode *snode, ARegion *ar, const int node_flag, const int smooth_viewtx) | ||||
| { | { | ||||
| bNode *node; | bNode *node; | ||||
| rctf cur_new; | rctf cur_new; | ||||
| float oldwidth, oldheight, width, height; | float oldwidth, oldheight, width, height, max_width, max_height; | ||||
| float oldasp, asp; | float oldasp, asp; | ||||
| int tot = 0; | int tot = 0; | ||||
| bool has_frame = false; | bool has_frame = false; | ||||
| oldwidth = BLI_rctf_size_x(&ar->v2d.cur); | oldwidth = BLI_rctf_size_x(&ar->v2d.cur); | ||||
| oldheight = BLI_rctf_size_y(&ar->v2d.cur); | oldheight = BLI_rctf_size_y(&ar->v2d.cur); | ||||
| oldasp = oldwidth / oldheight; | oldasp = oldwidth / oldheight; | ||||
| BLI_rctf_init_minmax(&cur_new); | BLI_rctf_init_minmax(&cur_new); | ||||
| max_width = 0.0f; | |||||
| max_height = 0.0f; | |||||
| if (snode->edittree) { | if (snode->edittree) { | ||||
| for (node = snode->edittree->nodes.first; node; node = node->next) { | for (node = snode->edittree->nodes.first; node; node = node->next) { | ||||
| if ((node->flag & node_flag) == node_flag) { | if ((node->flag & node_flag) == node_flag) { | ||||
| BLI_rctf_union(&cur_new, &node->totr); | BLI_rctf_union(&cur_new, &node->totr); | ||||
| tot++; | tot++; | ||||
| if (node->type == NODE_FRAME) { | if (node->type == NODE_FRAME) { | ||||
| has_frame = true; | has_frame = true; | ||||
| } | } | ||||
| } | } | ||||
| /* Find biggest node for single node view selected. */ | |||||
| float node_width = BLI_rctf_size_x(&node->totr); | |||||
| float node_height = BLI_rctf_size_y(&node->totr); | |||||
| if (node_width > max_width) { | |||||
| max_width = node_width; | |||||
| } | |||||
| if (node_height > max_height) { | |||||
| max_height = node_height; | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| if (tot) { | if (tot) { | ||||
| width = BLI_rctf_size_x(&cur_new); | width = BLI_rctf_size_x(&cur_new); | ||||
| height = BLI_rctf_size_y(&cur_new); | height = BLI_rctf_size_y(&cur_new); | ||||
| asp = width / height; | asp = width / height; | ||||
| /* for single non-frame nodes, don't zoom in, just pan view, | /* For single non-frame nodes, zoom in (taking biggest node in the tree into account). | ||||
| * but do allow zooming out, this allows for big nodes to be zoomed out */ | * This will look like panning once close enough, but still gets you close when zoomed far out. */ | ||||
| if ((tot == 1) && (has_frame == false) && ((oldwidth * oldheight) > (width * height))) { | if ((tot == 1) && (has_frame == false) && ((oldwidth * oldheight) > (width * height))) { | ||||
| /* center, don't zoom */ | BLI_rctf_resize(&cur_new, max_width, max_height); | ||||
| BLI_rctf_resize(&cur_new, oldwidth, oldheight); | |||||
| } | } | ||||
| else { | else { | ||||
| if (oldasp < asp) { | if (oldasp < asp) { | ||||
| const float height_new = width / oldasp; | const float height_new = width / oldasp; | ||||
| cur_new.ymin = cur_new.ymin - height_new / 2.0f; | cur_new.ymin = cur_new.ymin - height_new / 2.0f; | ||||
| cur_new.ymax = cur_new.ymax + height_new / 2.0f; | cur_new.ymax = cur_new.ymax + height_new / 2.0f; | ||||
| } | } | ||||
| else { | else { | ||||
| const float width_new = height * oldasp; | const float width_new = height * oldasp; | ||||
| cur_new.xmin = cur_new.xmin - width_new / 2.0f; | cur_new.xmin = cur_new.xmin - width_new / 2.0f; | ||||
| cur_new.xmax = cur_new.xmax + width_new / 2.0f; | cur_new.xmax = cur_new.xmax + width_new / 2.0f; | ||||
| } | } | ||||
| } | |||||
| /* add some padding */ | /* add some padding */ | ||||
| BLI_rctf_scale(&cur_new, 1.1f); | BLI_rctf_scale(&cur_new, 1.1f); | ||||
| } | |||||
| UI_view2d_smooth_view(C, ar, &cur_new, smooth_viewtx); | UI_view2d_smooth_view(C, ar, &cur_new, smooth_viewtx); | ||||
| } | } | ||||
| return (tot != 0); | return (tot != 0); | ||||
| } | } | ||||
| static int node_view_all_exec(bContext *C, wmOperator *op) | static int node_view_all_exec(bContext *C, wmOperator *op) | ||||
| ▲ Show 20 Lines • Show All 521 Lines • Show Last 20 Lines | |||||