Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.8 kB
1
Indexable
Never
void transitionRangeForUnifying(MTime & leftSegmentStart, MTime & leftSegmentEnd, MTime & rightSegmentStart, MTime & rightSegmentEnd, Timeline::ClipTiming const & leftClipTiming, Timeline::ClipTiming const & rightClipTiming)
{
	auto const minDuration = Timeline::MIN_CLIP_DURATION;
	auto const maxDuration = std::min(leftClipTiming.duration() - leftClipTiming.transitionIn(), rightClipTiming.duration() - rightClipTiming.transitionOut());
	leftSegmentStart = rightClipTiming.timestamp() - maxDuration;
	leftSegmentEnd = rightClipTiming.timestamp() - minDuration;
	rightSegmentStart = rightClipTiming.timestamp() + minDuration;
	rightSegmentEnd = rightClipTiming.timestamp() + maxDuration;
}

void transitionRangeForRight(MTime & leftSegmentStart, MTime & leftSegmentEnd, MTime const & rightSegmentStart, Timeline::ClipTiming const & leftClipTiming)
{
	auto const minDuration = Timeline::MIN_CLIP_DURATION;

	leftSegmentStart = leftClipTiming.timestamp() + leftClipTiming.transitionIn();
	leftSegmentEnd = rightSegmentStart - minDuration;
}

void transitionRangeForLeft(MTime & rightSegmentStart, MTime & rightSegmentEnd, Timeline::ClipTiming const & rightClipTiming)
{
	auto const minDuration = Timeline::MIN_CLIP_DURATION;

	rightSegmentStart = rightClipTiming.timestamp() + minDuration;
	rightSegmentEnd = rightClipTiming.end() - rightClipTiming.transitionOut();
}

bool TimelineScene::TransitionItem::isResizePossible(ResizeContext const & from, MTime ts)
{
	auto const [leftClip, rightClip] = clipPair();

	//дефолтные значения для рассчетов
	auto minLeft = from.timing.timestamp();
	auto maxLeft = from.timing.timestamp();
	auto minRight = from.timing.end();
	auto maxRight = from.timing.end();

	if (transitionType() == TransitionType::Unifying)
	{
		auto leftTiming = timeline()->clipTiming(leftClip);
		auto rightTiming = timeline()->clipTiming(rightClip);
		//считаем допустимые отрезки для ресайза
		transitionRangeForUnifying(minLeft, maxLeft, minRight, maxRight, leftTiming, rightTiming);

		return (((ts > minLeft) && (ts < maxLeft)) || ((ts > minRight) && (ts < maxRight))) ? true : false;
	}

	else if (transitionType() == TransitionType::Right)
	{
		auto const & leftTiming = timeline()->clipTiming(leftClip);
		//считаем допустимые отрезки для ресайза
		transitionRangeForRight(minLeft, maxLeft, minRight, leftTiming);

		return (ts > minLeft && ts < maxLeft) ? true : false;
	}
	else if (transitionType() == TransitionType::Left)
	{
		auto const & rightTiming = timeline()->clipTiming(rightClip);
		//считаем допустимые отрезки для ресайза
		transitionRangeForLeft(minRight, maxRight, rightTiming);

		return (ts > minRight && ts < maxRight) ? true : false;
	}

	return false;
}