Пример #1
0
static int previewrange_define_exec(bContext *C, wmOperator *op)
{
	Scene *scene = CTX_data_scene(C);
	ARegion *ar = CTX_wm_region(C);
	float sfra, efra;
	rcti rect;
	
	/* get min/max values from border select rect (already in region coordinates, not screen) */
	WM_operator_properties_border_to_rcti(op, &rect);
	
	/* convert min/max values to frames (i.e. region to 'tot' rect) */
	sfra = UI_view2d_region_to_view_x(&ar->v2d, rect.xmin);
	efra = UI_view2d_region_to_view_x(&ar->v2d, rect.xmax);
	
	/* set start/end frames for preview-range 
	 *	- must clamp within allowable limits
	 *	- end must not be before start (though this won't occur most of the time)
	 */
	FRAMENUMBER_MIN_CLAMP(sfra);
	FRAMENUMBER_MIN_CLAMP(efra);
	if (efra < sfra) efra = sfra;
	
	scene->r.flag |= SCER_PRV_RANGE;
	scene->r.psfra = iroundf(sfra);
	scene->r.pefra = iroundf(efra);
	
	/* send notifiers */
	WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene);
	
	return OPERATOR_FINISHED;
} 
Пример #2
0
bool ED_region_overlap_isect_x_with_margin(const ARegion *ar, const int event_x, const int margin)
{
  BLI_assert(ar->overlap);
  /* No contents, skip it. */
  if (ar->v2d.mask.xmin == ar->v2d.mask.xmax) {
    return false;
  }
  int region_x = event_x - ar->winrct.xmin;
  return ((ar->v2d.tot.xmin <= UI_view2d_region_to_view_x(&ar->v2d, region_x + margin)) &&
          (ar->v2d.tot.xmax >= UI_view2d_region_to_view_x(&ar->v2d, region_x - margin)));
}
Пример #3
0
static int graphkeys_select_leftright_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
	bAnimContext ac;
	short leftright = RNA_enum_get(op->ptr, "mode");
	
	/* get editor data */
	if (ANIM_animdata_get_context(C, &ac) == 0)
		return OPERATOR_CANCELLED;
		
	/* handle mode-based testing */
	if (leftright == GRAPHKEYS_LRSEL_TEST) {
		Scene *scene = ac.scene;
		ARegion *ar = ac.ar;
		View2D *v2d = &ar->v2d;
		float x;

		/* determine which side of the current frame mouse is on */
		x = UI_view2d_region_to_view_x(v2d, event->mval[0]);
		if (x < CFRA)
			RNA_enum_set(op->ptr, "mode", GRAPHKEYS_LRSEL_LEFT);
		else
			RNA_enum_set(op->ptr, "mode", GRAPHKEYS_LRSEL_RIGHT);
	}
	
	/* perform selection */
	return graphkeys_select_leftright_exec(C, op);
}
Пример #4
0
bool ED_region_overlap_isect_x(const ARegion *ar, const int event_x)
{
  BLI_assert(ar->overlap);
  /* No contents, skip it. */
  if (ar->v2d.mask.xmin == ar->v2d.mask.xmax) {
    return false;
  }
  return BLI_rctf_isect_x(&ar->v2d.tot,
                          UI_view2d_region_to_view_x(&ar->v2d, event_x - ar->winrct.xmin));
}
Пример #5
0
/* Get frame from mouse coordinates */
static float frame_from_event(bContext *C, const wmEvent *event)
{
  ARegion *region = CTX_wm_region(C);
  Scene *scene = CTX_data_scene(C);
  float frame;

  /* convert from region coordinates to View2D 'tot' space */
  frame = UI_view2d_region_to_view_x(&region->v2d, event->mval[0]);

  /* respect preview range restrictions (if only allowed to move around within that range) */
  if (scene->r.flag & SCER_LOCK_FRAME_SELECTION) {
    CLAMP(frame, PSFRA, PEFRA);
  }

  return frame;
}
Пример #6
0
/* Get frame from mouse coordinates */
static int frame_from_event(bContext *C, const wmEvent *event)
{
	ARegion *region = CTX_wm_region(C);
	Scene *scene = CTX_data_scene(C);
	float viewx;
	int frame;

	/* convert from region coordinates to View2D 'tot' space */
	viewx = UI_view2d_region_to_view_x(&region->v2d, event->mval[0]);
	
	/* round result to nearest int (frames are ints!) */
	frame = iroundf(viewx);
	
	if (scene->r.flag & SCER_LOCK_FRAME_SELECTION) {
		CLAMP(frame, PSFRA, PEFRA);
	}
	
	return frame;
}
Пример #7
0
static int ed_marker_select(bContext *C, const wmEvent *event, bool extend, bool camera)
{
	ListBase *markers = ED_context_get_markers(C);
	ARegion *ar = CTX_wm_region(C);
	View2D *v2d = UI_view2d_fromcontext(C);
	float viewx;
	int x, cfra;
	
	if (markers == NULL)
		return OPERATOR_PASS_THROUGH;

	x = event->x - ar->winrct.xmin;
	
	viewx = UI_view2d_region_to_view_x(v2d, x);
	
	cfra = ED_markers_find_nearest_marker_time(markers, viewx);
	
	select_timeline_marker_frame(markers, cfra, extend);
	
#ifdef DURIAN_CAMERA_SWITCH

	if (camera) {
		Scene *scene = CTX_data_scene(C);
		Base *base;
		TimeMarker *marker;
		int sel = 0;
		
		if (!extend)
			BKE_scene_base_deselect_all(scene);
		
		for (marker = markers->first; marker; marker = marker->next) {
			if (marker->frame == cfra) {
				sel = (marker->flag & SELECT);
				break;
			}
		}
		
		for (marker = markers->first; marker; marker = marker->next) {
			if (marker->camera) {
				if (marker->frame == cfra) {
					base = BKE_scene_base_find(scene, marker->camera);
					if (base) {
						ED_base_object_select(base, sel);
						if (sel)
							ED_base_object_activate(C, base);
					}
				}
			}
		}
		
		WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
	}
#else
	(void)camera;
#endif

	WM_event_add_notifier(C, NC_SCENE | ND_MARKERS, NULL);
	WM_event_add_notifier(C, NC_ANIMATION | ND_MARKERS, NULL);

	/* allowing tweaks, but needs OPERATOR_FINISHED, otherwise renaming fails... [#25987] */
	return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH;
}
Пример #8
0
static int sequencer_select_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
	View2D *v2d = UI_view2d_fromcontext(C);
	Scene *scene = CTX_data_scene(C);
	Editing *ed = BKE_sequencer_editing_get(scene, false);
	const bool extend = RNA_boolean_get(op->ptr, "extend");
	const bool linked_handle = RNA_boolean_get(op->ptr, "linked_handle");
	const bool linked_time = RNA_boolean_get(op->ptr, "linked_time");
	int left_right = RNA_enum_get(op->ptr, "left_right");
	
	Sequence *seq, *neighbor, *act_orig;
	int hand, sel_side;
	TimeMarker *marker;

	if (ed == NULL)
		return OPERATOR_CANCELLED;
	
	marker = find_nearest_marker(SCE_MARKERS, 1); //XXX - dummy function for now
	
	seq = find_nearest_seq(scene, v2d, &hand, event->mval);

	// XXX - not nice, Ctrl+RMB needs to do left_right only when not over a strip
	if (seq && linked_time && (left_right == SEQ_SELECT_LR_MOUSE))
		left_right = SEQ_SELECT_LR_NONE;


	if (marker) {
		int oldflag;
		/* select timeline marker */
		if (extend) {
			oldflag = marker->flag;
			if (oldflag & SELECT)
				marker->flag &= ~SELECT;
			else
				marker->flag |= SELECT;
		}
		else {
			/* deselect_markers(0, 0); */ /* XXX, in 2.4x, seq selection used to deselect all, need to re-thnik this for 2.5 */
			marker->flag |= SELECT;
		}
		
	}
	else if (left_right != SEQ_SELECT_LR_NONE) {
		/* use different logic for this */
		float x;
		ED_sequencer_deselect_all(scene);
		
		switch (left_right) {
			case SEQ_SELECT_LR_MOUSE:
				x = UI_view2d_region_to_view_x(v2d, event->mval[0]);
				break;
				
			case SEQ_SELECT_LR_LEFT:
				x = CFRA - 1;
				break;
			case SEQ_SELECT_LR_RIGHT:
				x = CFRA + 1;
				break;
		}
		
		SEQP_BEGIN (ed, seq)
		{
			if (x < CFRA) {
				if (seq->enddisp < CFRA) {
					seq->flag |= SELECT;
					recurs_sel_seq(seq);
				}
			}
			else {
				if (seq->startdisp > CFRA) {
					seq->flag |= SELECT;
					recurs_sel_seq(seq);
				}
			}
		}
		SEQ_END
		
		{
			SpaceSeq *sseq = CTX_wm_space_seq(C);
			if (sseq && sseq->flag & SEQ_MARKER_TRANS) {
				TimeMarker *tmarker;

				for (tmarker = scene->markers.first; tmarker; tmarker = tmarker->next) {
					if (((x <  CFRA) && tmarker->frame <  CFRA) ||
					    ((x >= CFRA) && tmarker->frame >= CFRA))
					{
						tmarker->flag |= SELECT;
					}
					else {
						tmarker->flag &= ~SELECT;
					}
				}
			}
		}
	}
Пример #9
0
/* select strip directly under mouse */
static void mouse_nla_strips(bContext *C, bAnimContext *ac, const int mval[2], short select_mode)
{
	ListBase anim_data = {NULL, NULL};
	bAnimListElem *ale = NULL;
	int filter;
	
	SpaceNla *snla = (SpaceNla *)ac->sl;
	View2D *v2d = &ac->ar->v2d;
	Scene *scene = ac->scene;
	NlaStrip *strip = NULL;
	int channel_index;
	float xmin, xmax;
	float x, y;
	
	
	/* use View2D to determine the index of the channel (i.e a row in the list) where keyframe was */
	UI_view2d_region_to_view(v2d, mval[0], mval[1], &x, &y);
	UI_view2d_listview_view_to_cell(v2d, 0, NLACHANNEL_STEP(snla), 0, (float)NLACHANNEL_HEIGHT_HALF(snla), x, y, NULL, &channel_index);
	
	/* x-range to check is +/- 7 (in screen/region-space) on either side of mouse click 
	 * (that is the size of keyframe icons, so user should be expecting similar tolerances) 
	 */
	xmin = UI_view2d_region_to_view_x(v2d, mval[0] - 7);
	xmax = UI_view2d_region_to_view_x(v2d, mval[0] + 7);
	
	/* filter data */
	filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS);
	ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
	
	/* try to get channel */
	ale = BLI_findlink(&anim_data, channel_index);
	if (ale == NULL) {
		/* channel not found */
		printf("Error: animation channel (index = %d) not found in mouse_nla_strips()\n", channel_index);
		ANIM_animdata_freelist(&anim_data);
		return;
	}
	else {
		/* found some channel - we only really should do somethign when its an Nla-Track */
		if (ale->type == ANIMTYPE_NLATRACK) {
			NlaTrack *nlt = (NlaTrack *)ale->data;
			
			/* loop over NLA-strips in this track, trying to find one which occurs in the necessary bounds */
			for (strip = nlt->strips.first; strip; strip = strip->next) {
				if (BKE_nlastrip_within_bounds(strip, xmin, xmax))
					break;
			}
		}
		
		/* remove active channel from list of channels for separate treatment (since it's needed later on) */
		BLI_remlink(&anim_data, ale);
		
		/* free list of channels, since it's not used anymore */
		ANIM_animdata_freelist(&anim_data);
	}
	
	/* if currently in tweakmode, exit tweakmode before changing selection states
	 * now that we've found our target...
	 */
	if (scene->flag & SCE_NLA_EDIT_ON)
		WM_operator_name_call(C, "NLA_OT_tweakmode_exit", WM_OP_EXEC_DEFAULT, NULL);
	
	/* for replacing selection, firstly need to clear existing selection */
	if (select_mode == SELECT_REPLACE) {
		/* reset selection mode for next steps */
		select_mode = SELECT_ADD;
		
		/* deselect all strips */
		deselect_nla_strips(ac, 0, SELECT_SUBTRACT);
		
		/* deselect all other channels first */
		ANIM_deselect_anim_channels(ac, ac->data, ac->datatype, 0, ACHANNEL_SETFLAG_CLEAR);
	}
	
	/* only select strip if we clicked on a valid channel and hit something */
	if (ale) {
		/* select the strip accordingly (if a matching one was found) */
		if (strip) {
			select_mode = selmodes_to_flagmodes(select_mode);
			ACHANNEL_SET_FLAG(strip, select_mode, NLASTRIP_FLAG_SELECT);
			
			/* if we selected it, we can make it active too
			 *	- we always need to clear the active strip flag though... 
			 *  - as well as selecting its track...
			 */
			deselect_nla_strips(ac, DESELECT_STRIPS_CLEARACTIVE, 0);
			
			if (strip->flag & NLASTRIP_FLAG_SELECT) {
				strip->flag |= NLASTRIP_FLAG_ACTIVE;
				
				/* Highlight NLA-Track */
				if (ale->type == ANIMTYPE_NLATRACK) {
					NlaTrack *nlt = (NlaTrack *)ale->data;
					
					nlt->flag |= NLATRACK_SELECTED;
					ANIM_set_active_channel(ac, ac->data, ac->datatype, filter, nlt, ANIMTYPE_NLATRACK);
				}
			}
		}
		
		/* free this channel */
		MEM_freeN(ale);
	}
}