Beispiel #1
0
static int add_vertex_new(const bContext *C, Mask *mask, MaskLayer *masklay, const float co[2])
{
	MaskSpline *spline;
	MaskSplinePoint *point;
	MaskSplinePoint *new_point = NULL, *ref_point = NULL;
	float view_zoom;

	if (!masklay) {
		/* if there's no masklay currently operationg on, create new one */
		masklay = BKE_mask_layer_new(mask, "");
		mask->masklay_act = mask->masklay_tot - 1;
		spline = NULL;
		point = NULL;
	}
	else {
		finSelectedSplinePoint(masklay, &spline, &point, TRUE);
	}

	ED_mask_select_toggle_all(mask, SEL_DESELECT);

	if (!spline) {
		/* no selected splines in active masklay, create new spline */
		spline = BKE_mask_spline_add(masklay);
	}

	masklay->act_spline = spline;
	new_point = spline->points;

	masklay->act_point = new_point;

	{
		ScrArea *sa = CTX_wm_area(C);
		ARegion *ar = CTX_wm_region(C);

		float zoom_x, zoom_y;
		/* calc view zoom in a simplistic way */
		ED_mask_zoom(sa, ar, &zoom_x, &zoom_y);

		view_zoom = zoom_x + zoom_y / 2.0f;
		view_zoom = 1.0f / view_zoom;

		/* arbitrary but gives good results */
		view_zoom /= 500.0f;
	}

	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);
		BKE_mask_layer_shape_changed_add(masklay, BKE_mask_layer_shape_spline_to_index(masklay, spline) + point_index, TRUE, TRUE);
	}

	WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask);

	return TRUE;
}
Beispiel #2
0
static bool add_vertex_new(const bContext *C, Mask *mask, MaskLayer *masklay, const float co[2])
{
	MaskSpline *spline;
	MaskSplinePoint *point;
	MaskSplinePoint *new_point = NULL, *ref_point = NULL;

	if (!masklay) {
		/* if there's no masklay currently operationg on, create new one */
		masklay = BKE_mask_layer_new(mask, "");
		mask->masklay_act = mask->masklay_tot - 1;
		spline = NULL;
		point = NULL;
	}
	else {
		finSelectedSplinePoint(masklay, &spline, &point, true);
	}

	ED_mask_select_toggle_all(mask, SEL_DESELECT);

	if (!spline) {
		/* no selected splines in active masklay, create new spline */
		spline = BKE_mask_spline_add(masklay);
	}

	masklay->act_spline = spline;
	new_point = spline->points;

	masklay->act_point = new_point;

	setup_vertex_point(mask, spline, new_point, co, 0.5f, ref_point, false);

	{
		int point_index = (((int)(new_point - spline->points) + 0) % spline->tot_point);
		BKE_mask_layer_shape_changed_add(masklay, BKE_mask_layer_shape_spline_to_index(masklay, spline) + point_index, true, true);
	}

	WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask);

	return true;
}
Beispiel #3
0
static bool add_vertex_extrude(const bContext *C, Mask *mask, MaskLayer *masklay, const float co[2])
{
	MaskSpline *spline;
	MaskSplinePoint *point;
	MaskSplinePoint *new_point = NULL, *ref_point = NULL;

	/* check on which side we want to add the point */
	int point_index;
	float tangent_point[2];
	float tangent_co[2];
	bool do_cyclic_correct = false;
	bool do_prev;                /* use prev point rather then next?? */

	if (!masklay) {
		return false;
	}
	else {
		finSelectedSplinePoint(masklay, &spline, &point, true);
	}

	ED_mask_select_toggle_all(mask, SEL_DESELECT);

	point_index = (point - spline->points);

	MASKPOINT_DESEL_ALL(point);

	if ((spline->flag & MASK_SPLINE_CYCLIC) ||
	    (point_index > 0 && point_index != spline->tot_point - 1))
	{
		BKE_mask_calc_tangent_polyline(spline, point, tangent_point);
		sub_v2_v2v2(tangent_co, co, point->bezt.vec[1]);

		if (dot_v2v2(tangent_point, tangent_co) < 0.0f) {
			do_prev = true;
		}
		else {
			do_prev = false;
		}
	}
	else if (((spline->flag & MASK_SPLINE_CYCLIC) == 0) && (point_index == 0)) {
		do_prev = true;
	}
	else if (((spline->flag & MASK_SPLINE_CYCLIC) == 0) && (point_index == spline->tot_point - 1)) {
		do_prev = false;
	}
	else {
		do_prev = false;  /* quiet warning */
		/* should never get here */
		BLI_assert(0);
	}

	/* use the point before the active one */
	if (do_prev) {
		point_index--;
		if (point_index < 0) {
			point_index += spline->tot_point; /* wrap index */
			if ((spline->flag & MASK_SPLINE_CYCLIC) == 0) {
				do_cyclic_correct = true;
				point_index = 0;
			}
		}
	}

//		print_v2("", tangent_point);
//		printf("%d\n", point_index);

	mask_spline_add_point_at_index(spline, point_index);

	if (do_cyclic_correct) {
		ref_point = &spline->points[point_index + 1];
		new_point = &spline->points[point_index];
		*ref_point = *new_point;
		memset(new_point, 0, sizeof(*new_point));
	}
	else {
		ref_point = &spline->points[point_index];
		new_point = &spline->points[point_index + 1];
	}

	masklay->act_point = new_point;

	setup_vertex_point(mask, spline, new_point, co, 0.5f, ref_point, false);

	if (masklay->splines_shapes.first) {
		point_index = (((int)(new_point - spline->points) + 0) % spline->tot_point);
		BKE_mask_layer_shape_changed_add(masklay, BKE_mask_layer_shape_spline_to_index(masklay, spline) + point_index, true, true);
	}

	WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask);

	return true;
}