Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/space_node/node_view.cc')
-rw-r--r--source/blender/editors/space_node/node_view.cc85
1 files changed, 39 insertions, 46 deletions
diff --git a/source/blender/editors/space_node/node_view.cc b/source/blender/editors/space_node/node_view.cc
index 36b84bec7eb..df629a983e3 100644
--- a/source/blender/editors/space_node/node_view.cc
+++ b/source/blender/editors/space_node/node_view.cc
@@ -24,7 +24,6 @@
#include "DNA_node_types.h"
#include "BLI_listbase.h"
-#include "BLI_math.h"
#include "BLI_rect.h"
#include "BLI_string_ref.hh"
#include "BLI_utildefines.h"
@@ -62,25 +61,21 @@ using blender::StringRef;
/** \name View All Operator
* \{ */
-int space_node_view_flag(
- bContext *C, SpaceNode *snode, ARegion *region, const int node_flag, const int smooth_viewtx)
+bool space_node_view_flag(
+ bContext &C, SpaceNode &snode, ARegion &region, const int node_flag, const int smooth_viewtx)
{
- bNode *node;
- rctf cur_new;
- float oldwidth, oldheight, width, height;
- float oldasp, asp;
- int tot = 0;
- bool has_frame = false;
+ const float oldwidth = BLI_rctf_size_x(&region.v2d.cur);
+ const float oldheight = BLI_rctf_size_y(&region.v2d.cur);
- oldwidth = BLI_rctf_size_x(&region->v2d.cur);
- oldheight = BLI_rctf_size_y(&region->v2d.cur);
-
- oldasp = oldwidth / oldheight;
+ const float old_aspect = oldwidth / oldheight;
+ rctf cur_new;
BLI_rctf_init_minmax(&cur_new);
- if (snode->edittree) {
- for (node = (bNode *)snode->edittree->nodes.first; node; node = node->next) {
+ int tot = 0;
+ bool has_frame = false;
+ if (snode.edittree) {
+ LISTBASE_FOREACH (const bNode *, node, &snode.edittree->nodes) {
if ((node->flag & node_flag) == node_flag) {
BLI_rctf_union(&cur_new, &node->totr);
tot++;
@@ -92,37 +87,39 @@ int space_node_view_flag(
}
}
- if (tot) {
- width = BLI_rctf_size_x(&cur_new);
- height = BLI_rctf_size_y(&cur_new);
- asp = width / height;
+ if (tot == 0) {
+ return false;
+ }
+
+ const float width = BLI_rctf_size_x(&cur_new);
+ const float height = BLI_rctf_size_y(&cur_new);
+ const float new_aspect = width / height;
- /* for single non-frame nodes, don't zoom in, just pan view,
- * but do allow zooming out, this allows for big nodes to be zoomed out */
- if ((tot == 1) && (has_frame == false) && ((oldwidth * oldheight) > (width * height))) {
- /* center, don't zoom */
- BLI_rctf_resize(&cur_new, oldwidth, oldheight);
+ /* for single non-frame nodes, don't zoom in, just pan view,
+ * but do allow zooming out, this allows for big nodes to be zoomed out */
+ if ((tot == 1) && (has_frame == false) && ((oldwidth * oldheight) > (width * height))) {
+ /* center, don't zoom */
+ BLI_rctf_resize(&cur_new, oldwidth, oldheight);
+ }
+ else {
+ if (old_aspect < new_aspect) {
+ const float height_new = width / old_aspect;
+ cur_new.ymin = cur_new.ymin - height_new / 2.0f;
+ cur_new.ymax = cur_new.ymax + height_new / 2.0f;
}
else {
- if (oldasp < asp) {
- const float height_new = width / oldasp;
- cur_new.ymin = cur_new.ymin - height_new / 2.0f;
- cur_new.ymax = cur_new.ymax + height_new / 2.0f;
- }
- else {
- const float width_new = height * oldasp;
- cur_new.xmin = cur_new.xmin - width_new / 2.0f;
- cur_new.xmax = cur_new.xmax + width_new / 2.0f;
- }
-
- /* add some padding */
- BLI_rctf_scale(&cur_new, 1.1f);
+ const float width_new = height * old_aspect;
+ cur_new.xmin = cur_new.xmin - width_new / 2.0f;
+ cur_new.xmax = cur_new.xmax + width_new / 2.0f;
}
- UI_view2d_smooth_view(C, region, &cur_new, smooth_viewtx);
+ /* add some padding */
+ BLI_rctf_scale(&cur_new, 1.1f);
}
- return (tot != 0);
+ UI_view2d_smooth_view(&C, &region, &cur_new, smooth_viewtx);
+
+ return true;
}
static int node_view_all_exec(bContext *C, wmOperator *op)
@@ -135,7 +132,7 @@ static int node_view_all_exec(bContext *C, wmOperator *op)
snode->xof = 0;
snode->yof = 0;
- if (space_node_view_flag(C, snode, region, 0, smooth_viewtx)) {
+ if (space_node_view_flag(*C, *snode, *region, 0, smooth_viewtx)) {
return OPERATOR_FINISHED;
}
return OPERATOR_CANCELLED;
@@ -168,7 +165,7 @@ static int node_view_selected_exec(bContext *C, wmOperator *op)
SpaceNode *snode = CTX_wm_space_node(C);
const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
- if (space_node_view_flag(C, snode, region, NODE_SELECT, smooth_viewtx)) {
+ if (space_node_view_flag(*C, *snode, *region, NODE_SELECT, smooth_viewtx)) {
return OPERATOR_FINISHED;
}
return OPERATOR_CANCELLED;
@@ -447,7 +444,6 @@ static void sample_draw(const bContext *C, ARegion *region, void *arg_info)
}
}
-/* Returns mouse position in image space. */
bool ED_space_node_get_position(
Main *bmain, SpaceNode *snode, struct ARegion *region, const int mval[2], float fpos[2])
{
@@ -475,9 +471,6 @@ bool ED_space_node_get_position(
return true;
}
-/* Returns color in linear space, matching ED_space_image_color_sample().
- * And here we've got recursion in the comments tips...
- */
bool ED_space_node_color_sample(
Main *bmain, SpaceNode *snode, ARegion *region, const int mval[2], float r_col[3])
{
@@ -738,7 +731,7 @@ static int space_node_view_geometry_nodes_legacy(bContext *C, SpaceNode *snode,
}
const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
- if (space_node_view_flag(C, snode, region, NODE_SELECT, smooth_viewtx)) {
+ if (space_node_view_flag(*C, *snode, *region, NODE_SELECT, smooth_viewtx)) {
return OPERATOR_FINISHED;
}
return OPERATOR_CANCELLED;