Esempio n. 1
0
static bool do_lasso_select_mask(bContext *C, const int mcords[][2], short moves, short select)
{
	ScrArea *sa = CTX_wm_area(C);
	ARegion *ar = CTX_wm_region(C);

	Mask *mask = CTX_data_edit_mask(C);
	MaskLayer *masklay;
	int i;

	rcti rect;
	bool changed = false;

	/* get rectangle from operator */
	BLI_lasso_boundbox(&rect, mcords, moves);

	/* do actual selection */
	for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
		MaskSpline *spline;

		if (masklay->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) {
			continue;
		}

		for (spline = masklay->splines.first; spline; spline = spline->next) {
			MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline);

			for (i = 0; i < spline->tot_point; i++) {
				MaskSplinePoint *point = &spline->points[i];
				MaskSplinePoint *point_deform = &points_array[i];

				/* TODO: handles? */
				/* TODO: uw? */

				float screen_co[2];

				/* point in screen coords */
				ED_mask_point_pos__reverse(sa, ar,
				                           point_deform->bezt.vec[1][0], point_deform->bezt.vec[1][1],
				                           &screen_co[0], &screen_co[1]);

				if (BLI_rcti_isect_pt(&rect, screen_co[0], screen_co[1]) &&
				    BLI_lasso_is_point_inside(mcords, moves, screen_co[0], screen_co[1], INT_MAX))
				{
					BKE_mask_point_select_set(point, select);
					BKE_mask_point_select_set_handle(point, MASK_WHICH_HANDLE_BOTH, select);
				}

				changed = true;
			}
		}
	}

	if (changed) {
		ED_mask_select_flush_all(mask);

		WM_event_add_notifier(C, NC_MASK | ND_SELECT, mask);
	}

	return changed;
}
Esempio n. 2
0
static bool do_lasso_select_node(bContext *C, const int mcords[][2], short moves, short select)
{
	SpaceNode *snode = CTX_wm_space_node(C);
	bNode *node;

	ARegion *ar = CTX_wm_region(C);

	rcti rect;
	bool changed = false;

	/* get rectangle from operator */
	BLI_lasso_boundbox(&rect, mcords, moves);

	/* do actual selection */
	for (node = snode->edittree->nodes.first; node; node = node->next) {
		int screen_co[2];
		const float cent[2] = {BLI_rctf_cent_x(&node->totr),
		                       BLI_rctf_cent_y(&node->totr)};

		/* marker in screen coords */
		if (UI_view2d_view_to_region_clip(&ar->v2d, cent[0], cent[1], &screen_co[0], &screen_co[1]) &&
		    BLI_rcti_isect_pt(&rect, screen_co[0], screen_co[1]) &&
		    BLI_lasso_is_point_inside(mcords, moves, screen_co[0], screen_co[1], INT_MAX))
		{
			nodeSetSelected(node, select);
			changed = true;
		}
	}

	if (changed) {
		WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL);
	}

	return changed;
}
Esempio n. 3
0
static int do_lasso_select_marker(bContext *C, int mcords[][2], short moves, short select)
{
	SpaceClip *sc = CTX_wm_space_clip(C);
	ARegion *ar = CTX_wm_region(C);

	MovieClip *clip = ED_space_clip_get_clip(sc);
	MovieTracking *tracking = &clip->tracking;
	MovieTrackingTrack *track;
	ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
	rcti rect;
	int change = FALSE;
	int framenr = ED_space_clip_get_clip_frame_number(sc);

	/* get rectangle from operator */
	BLI_lasso_boundbox(&rect, mcords, moves);

	/* do actual selection */
	track = tracksbase->first;
	while (track) {
		if ((track->flag & TRACK_HIDDEN) == 0) {
			MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);

			if (MARKER_VISIBLE(sc, track, marker)) {
				float screen_co[2];

				/* marker in screen coords */
				ED_clip_point_stable_pos__reverse(sc, ar, marker->pos, screen_co);

				if (BLI_in_rcti(&rect, screen_co[0], screen_co[1]) &&
				    BLI_lasso_is_point_inside(mcords, moves, screen_co[0], screen_co[1], V2D_IS_CLIPPED))
				{
					if (select)
						BKE_tracking_track_flag_set(track, TRACK_AREA_ALL, SELECT);
					else
						BKE_tracking_track_flag_clear(track, TRACK_AREA_ALL, SELECT);
				}

				change = TRUE;
			}
		}

		track = track->next;
	}

	if (change) {
		BKE_tracking_dopesheet_tag_update(tracking);

		WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL);
	}

	return change;
}
Esempio n. 4
0
static void draw_filled_lasso(wmWindow *win, wmGesture *gt)
{
	const short *lasso = (short *)gt->customdata;
	const int tot = gt->points;
	int (*moves)[2] = MEM_mallocN(sizeof(*moves) * (tot + 1), __func__);
	int i;
	rcti rect;
	rcti rect_win;

	for (i = 0; i < tot; i++, lasso += 2) {
		moves[i][0] = lasso[0];
		moves[i][1] = lasso[1];
	}

	BLI_lasso_boundbox(&rect, (const int (*)[2])moves, tot);

	wm_subwindow_rect_get(win, gt->swinid, &rect_win);
	BLI_rcti_translate(&rect, rect_win.xmin, rect_win.ymin);
	BLI_rcti_isect(&rect_win, &rect, &rect);
	BLI_rcti_translate(&rect, -rect_win.xmin, -rect_win.ymin);

	/* highly unlikely this will fail, but could crash if (tot == 0) */
	if (BLI_rcti_is_empty(&rect) == false) {
		const int w = BLI_rcti_size_x(&rect);
		const int h = BLI_rcti_size_y(&rect);
		unsigned int *pixel_buf = MEM_callocN(sizeof(*pixel_buf) * w * h, __func__);
		struct LassoFillData lasso_fill_data = {pixel_buf, w};

		fill_poly_v2i_n(
		       rect.xmin, rect.ymin, rect.xmax, rect.ymax,
		       (const int (*)[2])moves, tot,
		       draw_filled_lasso_px_cb, &lasso_fill_data);

		glEnable(GL_BLEND);
		// glColor4f(1.0, 1.0, 1.0, 0.05);

		glRasterPos2f(rect.xmin, rect.ymin);

		glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixel_buf);

		glDisable(GL_BLEND);
		MEM_freeN(pixel_buf);
	}

	MEM_freeN(moves);
}
Esempio n. 5
0
static int actkeys_lassoselect_exec(bContext *C, wmOperator *op)
{
	bAnimContext ac;
	
	KeyframeEdit_LassoData data_lasso;
	rcti rect;
	rctf rect_fl;
	
	short selectmode;
	bool extend;
	
	/* get editor data */
	if (ANIM_animdata_get_context(C, &ac) == 0)
		return OPERATOR_CANCELLED;
	
	data_lasso.rectf_view = &rect_fl;
	data_lasso.mcords = WM_gesture_lasso_path_to_array(C, op, &data_lasso.mcords_tot);
	if (data_lasso.mcords == NULL)
		return OPERATOR_CANCELLED;
	
	/* clear all selection if not extending selection */
	extend = RNA_boolean_get(op->ptr, "extend");
	if (!extend)
		deselect_action_keys(&ac, 1, SELECT_SUBTRACT);
	
	if (!RNA_boolean_get(op->ptr, "deselect"))
		selectmode = SELECT_ADD;
	else
		selectmode = SELECT_SUBTRACT;
	
	/* get settings from operator */
	BLI_lasso_boundbox(&rect, data_lasso.mcords, data_lasso.mcords_tot);
	BLI_rctf_rcti_copy(&rect_fl, &rect);
	
	/* apply borderselect action */
	region_select_action_keys(&ac, &rect_fl, BEZT_OK_CHANNEL_LASSO, selectmode, &data_lasso);
	
	MEM_freeN((void *)data_lasso.mcords);
	
	/* send notifier that keyframe selection has changed */
	WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL);
	
	return OPERATOR_FINISHED;
}
Esempio n. 6
0
static int graphkeys_lassoselect_exec(bContext *C, wmOperator *op)
{
	bAnimContext ac;
	rcti rect;
	rctf rect_fl;
	short selectmode;
	bool incl_handles;
	bool extend;

	struct KeyframeEdit_LassoData data_lasso;

	/* get editor data */
	if (ANIM_animdata_get_context(C, &ac) == 0)
		return OPERATOR_CANCELLED;

	data_lasso.rectf_view = &rect_fl;
	data_lasso.mcords = WM_gesture_lasso_path_to_array(C, op, &data_lasso.mcords_tot);
	if (data_lasso.mcords == NULL)
		return OPERATOR_CANCELLED;

	/* clear all selection if not extending selection */
	extend = RNA_boolean_get(op->ptr, "extend");
	if (!extend)
		deselect_graph_keys(&ac, 1, SELECT_SUBTRACT, true);

	if (!RNA_boolean_get(op->ptr, "deselect"))
		selectmode = SELECT_ADD;
	else
		selectmode = SELECT_SUBTRACT;

	if (ac.spacetype == SPACE_IPO) {
		SpaceIpo *sipo = (SpaceIpo *)ac.sl;
		if (selectmode == SELECT_ADD) {
			incl_handles = ((sipo->flag & SIPO_SELVHANDLESONLY) ||
			                (sipo->flag & SIPO_NOHANDLES)) == 0;
		}
		else {
			incl_handles = (sipo->flag & SIPO_NOHANDLES) == 0;
		}
	}
	else {
		incl_handles = false;
	}


	/* get settings from operator */
	BLI_lasso_boundbox(&rect, data_lasso.mcords, data_lasso.mcords_tot);

	BLI_rctf_rcti_copy(&rect_fl, &rect);

	/* apply borderselect action */
	borderselect_graphkeys(&ac, &rect_fl, BEZT_OK_REGION_LASSO, selectmode, incl_handles, &data_lasso);

	MEM_freeN((void *)data_lasso.mcords);


	/* send notifier that keyframe selection has changed */
	WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL);

	return OPERATOR_FINISHED;
}
static int do_lasso_select_marker(bContext *C, const int mcords[][2], const short moves, bool select)
{
	SpaceClip *sc = CTX_wm_space_clip(C);
	ARegion *ar = CTX_wm_region(C);

	MovieClip *clip = ED_space_clip_get_clip(sc);
	MovieTracking *tracking = &clip->tracking;
	MovieTrackingTrack *track;
	MovieTrackingPlaneTrack *plane_track;
	ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
	ListBase *plane_tracks_base = BKE_tracking_get_active_plane_tracks(tracking);
	rcti rect;
	bool changed = false;
	int framenr = ED_space_clip_get_clip_frame_number(sc);

	/* get rectangle from operator */
	BLI_lasso_boundbox(&rect, mcords, moves);

	/* do actual selection */
	track = tracksbase->first;
	while (track) {
		if ((track->flag & TRACK_HIDDEN) == 0) {
			MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);

			if (MARKER_VISIBLE(sc, track, marker)) {
				float screen_co[2];

				/* marker in screen coords */
				ED_clip_point_stable_pos__reverse(sc, ar, marker->pos, screen_co);

				if (BLI_rcti_isect_pt(&rect, screen_co[0], screen_co[1]) &&
				    BLI_lasso_is_point_inside(mcords, moves, screen_co[0], screen_co[1], V2D_IS_CLIPPED))
				{
					if (select)
						BKE_tracking_track_flag_set(track, TRACK_AREA_ALL, SELECT);
					else
						BKE_tracking_track_flag_clear(track, TRACK_AREA_ALL, SELECT);
				}

				changed = true;
			}
		}

		track = track->next;
	}

	for (plane_track = plane_tracks_base->first;
	     plane_track;
	     plane_track = plane_track->next)
	{
		if ((plane_track->flag & PLANE_TRACK_HIDDEN) == 0) {
			MovieTrackingPlaneMarker *plane_marker =
				BKE_tracking_plane_marker_get(plane_track, framenr);
			int i;

			for (i = 0; i < 4; i++) {
				float screen_co[2];

				/* marker in screen coords */
				ED_clip_point_stable_pos__reverse(sc, ar, plane_marker->corners[i], screen_co);

				if (BLI_rcti_isect_pt(&rect, screen_co[0], screen_co[1]) &&
				    BLI_lasso_is_point_inside(mcords, moves, screen_co[0], screen_co[1], V2D_IS_CLIPPED))
				{
					if (select) {
						plane_track->flag |= SELECT;
					}
					else {
						plane_track->flag &= ~SELECT;
					}
				}
			}

			changed = true;
		}
	}

	if (changed) {
		BKE_tracking_dopesheet_tag_update(tracking);

		WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL);
	}

	return changed;
}