better handle sizes by default for mask mode, now ignore image width/height
This commit is contained in:
@@ -34,6 +34,8 @@ __all__ = (
|
|||||||
"register_class",
|
"register_class",
|
||||||
"register_module",
|
"register_module",
|
||||||
"register_manual_map",
|
"register_manual_map",
|
||||||
|
"unregister_manual_map",
|
||||||
|
"manual_map",
|
||||||
"resource_path",
|
"resource_path",
|
||||||
"script_path_user",
|
"script_path_user",
|
||||||
"script_path_pref",
|
"script_path_pref",
|
||||||
|
|||||||
@@ -180,25 +180,20 @@ static int find_nearest_diff_point(const bContext *C, Mask *mask, const float no
|
|||||||
|
|
||||||
/******************** add vertex *********************/
|
/******************** 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,
|
const float point_co[2], const float tangent[2], const float u,
|
||||||
MaskSplinePoint *reference_point, const short reference_adjacent,
|
MaskSplinePoint *reference_point, const short reference_adjacent,
|
||||||
const float view_zoom)
|
const float view_zoom)
|
||||||
{
|
{
|
||||||
ScrArea *sa = CTX_wm_area(C);
|
|
||||||
|
|
||||||
MaskSplinePoint *prev_point = NULL;
|
MaskSplinePoint *prev_point = NULL;
|
||||||
MaskSplinePoint *next_point = NULL;
|
MaskSplinePoint *next_point = NULL;
|
||||||
BezTriple *bezt;
|
BezTriple *bezt;
|
||||||
int width, height;
|
|
||||||
float co[3];
|
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);
|
copy_v2_v2(co, point_co);
|
||||||
co[2] = 0.0f;
|
co[2] = 0.0f;
|
||||||
|
|
||||||
ED_mask_get_size(sa, &width, &height);
|
|
||||||
|
|
||||||
/* point coordinate */
|
/* point coordinate */
|
||||||
bezt = &new_point->bezt;
|
bezt = &new_point->bezt;
|
||||||
|
|
||||||
@@ -226,21 +221,15 @@ static void setup_vertex_point(const bContext *C, Mask *mask, MaskSpline *spline
|
|||||||
/* initial offset for handles */
|
/* initial offset for handles */
|
||||||
if (spline->tot_point == 1) {
|
if (spline->tot_point == 1) {
|
||||||
/* first point of splien is aligned horizontally */
|
/* first point of splien is aligned horizontally */
|
||||||
bezt->vec[0][0] -= len / maxi(width, height) * view_zoom;
|
bezt->vec[0][0] -= len * view_zoom;
|
||||||
bezt->vec[2][0] += len / maxi(width, height) * view_zoom;
|
bezt->vec[2][0] += len * view_zoom;
|
||||||
}
|
}
|
||||||
else if (tangent) {
|
else if (tangent) {
|
||||||
float vec[2];
|
float vec[2];
|
||||||
|
|
||||||
copy_v2_v2(vec, tangent);
|
copy_v2_v2(vec, tangent);
|
||||||
|
|
||||||
vec[0] *= width;
|
mul_v2_fl(vec, len);
|
||||||
vec[1] *= height;
|
|
||||||
|
|
||||||
mul_v2_fl(vec, len / len_v2(vec));
|
|
||||||
|
|
||||||
vec[0] /= width;
|
|
||||||
vec[1] /= height;
|
|
||||||
|
|
||||||
sub_v2_v2(bezt->vec[0], vec);
|
sub_v2_v2(bezt->vec[0], vec);
|
||||||
add_v2_v2(bezt->vec[2], 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];
|
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! */
|
/* 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);
|
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;
|
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) {
|
if (masklay->splines_shapes.first) {
|
||||||
point_index = (((int)(new_point - spline->points) + 0) % spline->tot_point);
|
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);
|
ScrArea *sa = CTX_wm_area(C);
|
||||||
ARegion *ar = CTX_wm_region(C);
|
ARegion *ar = CTX_wm_region(C);
|
||||||
|
|
||||||
|
float zoom_x, zoom_y;
|
||||||
/* calc view zoom in a simplistic way */
|
/* calc view zoom in a simplistic way */
|
||||||
float co_a[2];
|
ED_mask_zoom(sa, ar, &zoom_x, &zoom_y);
|
||||||
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);
|
view_zoom = zoom_x + zoom_y / 2.0f;
|
||||||
ED_mask_mouse_pos(sa, ar, mval_b, co_b);
|
view_zoom = 1.0f / view_zoom;
|
||||||
|
|
||||||
view_zoom = ((co_b[0] - co_a[0]) + (co_b[1] - co_a[1])) / 2.0f;
|
/* arbitrary but gives good results */
|
||||||
|
view_zoom /= 500.0f;
|
||||||
/* scale up - arbitrarty but works well in the view */
|
|
||||||
view_zoom *= 200.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);
|
int point_index = (((int)(new_point - spline->points) + 0) % spline->tot_point);
|
||||||
|
|||||||
Reference in New Issue
Block a user