From 6b1582c012a93aa8497b4d8a087500bcb5fbaecc Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 25 Aug 2012 14:18:54 +0000 Subject: better handle sizes by default for mask mode, now ignore image width/height --- source/blender/editors/mask/mask_add.c | 43 +++++++++++----------------------- 1 file changed, 14 insertions(+), 29 deletions(-) (limited to 'source/blender/editors/mask/mask_add.c') diff --git a/source/blender/editors/mask/mask_add.c b/source/blender/editors/mask/mask_add.c index d2a5e80fc24..b37f758596b 100644 --- a/source/blender/editors/mask/mask_add.c +++ b/source/blender/editors/mask/mask_add.c @@ -180,25 +180,20 @@ static int find_nearest_diff_point(const bContext *C, Mask *mask, const float no /******************** add vertex *********************/ -static void setup_vertex_point(const bContext *C, Mask *mask, MaskSpline *spline, MaskSplinePoint *new_point, +static void setup_vertex_point(Mask *mask, MaskSpline *spline, MaskSplinePoint *new_point, const float point_co[2], const float tangent[2], const float u, MaskSplinePoint *reference_point, const short reference_adjacent, const float view_zoom) { - ScrArea *sa = CTX_wm_area(C); - MaskSplinePoint *prev_point = NULL; MaskSplinePoint *next_point = NULL; BezTriple *bezt; - int width, height; float co[3]; - const float len = 20.0; /* default length of handle in pixel space */ + const float len = 10.0; /* default length of handle in pixel space */ copy_v2_v2(co, point_co); co[2] = 0.0f; - ED_mask_get_size(sa, &width, &height); - /* point coordinate */ bezt = &new_point->bezt; @@ -226,21 +221,15 @@ static void setup_vertex_point(const bContext *C, Mask *mask, MaskSpline *spline /* initial offset for handles */ if (spline->tot_point == 1) { /* first point of splien is aligned horizontally */ - bezt->vec[0][0] -= len / maxi(width, height) * view_zoom; - bezt->vec[2][0] += len / maxi(width, height) * view_zoom; + bezt->vec[0][0] -= len * view_zoom; + bezt->vec[2][0] += len * view_zoom; } else if (tangent) { float vec[2]; copy_v2_v2(vec, tangent); - vec[0] *= width; - vec[1] *= height; - - mul_v2_fl(vec, len / len_v2(vec)); - - vec[0] /= width; - vec[1] /= height; + mul_v2_fl(vec, len); sub_v2_v2(bezt->vec[0], vec); add_v2_v2(bezt->vec[2], vec); @@ -392,7 +381,7 @@ static int add_vertex_subdivide(const bContext *C, Mask *mask, const float co[2] new_point = &spline->points[point_index + 1]; - setup_vertex_point(C, mask, spline, new_point, co, tangent, u, NULL, TRUE, 1.0f); + setup_vertex_point(mask, spline, new_point, co, tangent, u, NULL, TRUE, 1.0f); /* TODO - we could pass the spline! */ BKE_mask_layer_shape_changed_add(masklay, BKE_mask_layer_shape_spline_to_index(masklay, spline) + point_index + 1, TRUE, TRUE); @@ -491,7 +480,7 @@ static int add_vertex_extrude(const bContext *C, Mask *mask, MaskLayer *masklay, masklay->act_point = new_point; - setup_vertex_point(C, mask, spline, new_point, co, NULL, 0.5f, ref_point, FALSE, 1.0f); + setup_vertex_point(mask, spline, new_point, co, NULL, 0.5f, ref_point, FALSE, 1.0f); if (masklay->splines_shapes.first) { point_index = (((int)(new_point - spline->points) + 0) % spline->tot_point); @@ -542,22 +531,18 @@ static int add_vertex_new(const bContext *C, Mask *mask, MaskLayer *masklay, con ScrArea *sa = CTX_wm_area(C); ARegion *ar = CTX_wm_region(C); + float zoom_x, zoom_y; /* calc view zoom in a simplistic way */ - float co_a[2]; - float co_b[2]; - int mval_a[2] = {0, 0}; - int mval_b[2] = {1, 1}; - - ED_mask_mouse_pos(sa, ar, mval_a, co_a); - ED_mask_mouse_pos(sa, ar, mval_b, co_b); + ED_mask_zoom(sa, ar, &zoom_x, &zoom_y); - view_zoom = ((co_b[0] - co_a[0]) + (co_b[1] - co_a[1])) / 2.0f; + view_zoom = zoom_x + zoom_y / 2.0f; + view_zoom = 1.0f / view_zoom; - /* scale up - arbitrarty but works well in the view */ - view_zoom *= 200.0f; + /* arbitrary but gives good results */ + view_zoom /= 500.0f; } - setup_vertex_point(C, mask, spline, new_point, co, NULL, 0.5f, ref_point, FALSE, view_zoom); + setup_vertex_point(mask, spline, new_point, co, NULL, 0.5f, ref_point, FALSE, view_zoom); { int point_index = (((int)(new_point - spline->points) + 0) % spline->tot_point); -- cgit v1.2.3