add padding for node view-all, view-home operators.
authorCampbell Barton <ideasman42@gmail.com>
Fri, 11 Jan 2013 04:34:15 +0000 (04:34 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 11 Jan 2013 04:34:15 +0000 (04:34 +0000)
source/blender/blenlib/BLI_rect.h
source/blender/blenlib/intern/rct.c
source/blender/editors/space_graph/graph_edit.c
source/blender/editors/space_node/node_view.c

index f2e260937114f742a7bc6f2d858ed1b5d97619f9..3c9363039b23ab299dbd2311c1a735c7e0b550ae 100644 (file)
@@ -56,6 +56,8 @@ void BLI_rctf_translate(struct rctf *rect, float x, float y);
 void BLI_rcti_translate(struct rcti *rect, int x, int y);
 void BLI_rcti_resize(struct rcti *rect, int x, int y);
 void BLI_rctf_resize(struct rctf *rect, float x, float y);
+void BLI_rcti_scale(rcti *rect, const float scale);
+void BLI_rctf_scale(rctf *rect, const float scale);
 void BLI_rctf_interp(struct rctf *rect, const struct rctf *rect_a, const struct rctf *rect_b, const float fac);
 //void BLI_rcti_interp(struct rctf *rect, struct rctf *rect_a, struct rctf *rect_b, float fac);
 int  BLI_rctf_clamp_pt_v(const struct rctf *rect, float xy[2]);
index fb767f54e5517931c459683b3407ba575c80b9f3..4bd7715ea7aa6ea1e0ce87ef0ccf4dbee75eb24b 100644 (file)
@@ -317,6 +317,30 @@ void BLI_rctf_resize(rctf *rect, float x, float y)
        rect->ymax = rect->ymin + y;
 }
 
+void BLI_rcti_scale(rcti *rect, const float scale)
+{
+       const int cent_x      = BLI_rcti_cent_x(rect);
+       const int cent_y      = BLI_rcti_cent_y(rect);
+       const int size_x_half = BLI_rcti_size_x(rect) * (scale * 0.5f);
+       const int size_y_half = BLI_rcti_size_y(rect) * (scale * 0.5f);
+       rect->xmin = cent_x - size_x_half;
+       rect->ymin = cent_y - size_y_half;
+       rect->xmax = cent_x + size_x_half;
+       rect->ymax = cent_y + size_y_half;
+}
+
+void BLI_rctf_scale(rctf *rect, const float scale)
+{
+       const float cent_x      = BLI_rctf_cent_x(rect);
+       const float cent_y      = BLI_rctf_cent_y(rect);
+       const float size_x_half = BLI_rctf_size_x(rect) * (scale * 0.5f);
+       const float size_y_half = BLI_rctf_size_y(rect) * (scale * 0.5f);
+       rect->xmin = cent_x - size_x_half;
+       rect->ymin = cent_y - size_y_half;
+       rect->xmax = cent_x + size_x_half;
+       rect->ymax = cent_y + size_y_half;
+}
+
 void BLI_rctf_interp(rctf *rect, const rctf *rect_a, const rctf *rect_b, const float fac)
 {
        const float ifac = 1.0f - fac;
index 21b0ed99f0bf32cc4b625309bd0b994f4da655fc..b92430ce0e93e94a51d8623dc11331f55f13f361 100644 (file)
@@ -217,7 +217,6 @@ void GRAPH_OT_previewrange_set(wmOperatorType *ot)
 static int graphkeys_viewall(bContext *C, const short do_sel_only, const short include_handles)
 {
        bAnimContext ac;
-       float extra;
        rctf cur_new;
 
        /* get editor data */
@@ -230,13 +229,7 @@ static int graphkeys_viewall(bContext *C, const short do_sel_only, const short i
                                   &cur_new.ymin, &cur_new.ymax,
                                   do_sel_only, include_handles);
 
-       extra = 0.1f * BLI_rctf_size_x(&cur_new);
-       cur_new.xmin -= extra;
-       cur_new.xmax += extra;
-
-       extra = 0.1f * BLI_rctf_size_y(&cur_new);
-       cur_new.ymin -= extra;
-       cur_new.ymax += extra;
+       BLI_rctf_scale(&cur_new, 1.1f);
 
        UI_view2d_smooth_view(C, ac.ar, &cur_new);
 
index 492ff0dcbd4a17111497b219ad592d37efdecfd0..a69e73c1489b4fd8bfed7ddb440d35bfdcca8540 100644 (file)
@@ -118,6 +118,9 @@ static int space_node_view_flag(bContext *C, SpaceNode *snode, ARegion *ar, cons
                                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);
                }
 
                UI_view2d_smooth_view(C, ar, &cur_new);