Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
2.9 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();
}

auto isInRange = [](MTime left, MTime right, MTime resizeTimeStamp) { return (resizeTimeStamp > left && resizeTimeStamp < right); };

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 (isInRange(minLeft, maxLeft, ts) || isInRange(minRight, maxRight, ts));
	}

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

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

		return isInRange(minRight, maxRight, ts);
	}

	return false;
}