addtool: better snapping

This commit is contained in:
itsmattkc
2020-06-14 01:20:02 +10:00
parent 37b7330274
commit 9a49235e40
+14 -5
View File
@@ -57,6 +57,7 @@ void TimelineWidget::AddTool::MousePress(TimelineViewMouseEvent *event)
// Leave as "none", which means this block can be placed on any track
break;
case OLIVE_NAMESPACE::Tool::kAddableCount:
// Return so we do nothing
return;
}
@@ -64,6 +65,14 @@ void TimelineWidget::AddTool::MousePress(TimelineViewMouseEvent *event)
|| add_type == track.type()) {
drag_start_point_ = event->GetFrame();
if (Core::instance()->snapping()) {
rational movement;
parent()->SnapPoint({drag_start_point_}, &movement);
if (!movement.isNull()) {
drag_start_point_ += movement;
}
}
ghost_ = new TimelineViewGhostItem();
ghost_->SetIn(drag_start_point_);
ghost_->SetOut(drag_start_point_);
@@ -160,6 +169,11 @@ void TimelineWidget::AddTool::MouseMoveInternal(const rational &cursor_frame, bo
// Calculate movement
rational movement = cursor_frame - drag_start_point_;
// Validation: Ensure in point never goes below 0
if (movement < -ghost_->In() || (outwards && -movement < -ghost_->In())) {
movement = -ghost_->In();
}
// Snap movement
bool snapped = parent()->SnapPoint(snap_points_, &movement);
@@ -171,11 +185,6 @@ void TimelineWidget::AddTool::MouseMoveInternal(const rational &cursor_frame, bo
// We don't need to un-neg here because outwards means all future processing will be done both pos and neg
}
// Validation: Ensure in point never goes below 0
if (movement < -ghost_->In() || (outwards && -movement < -ghost_->In())) {
movement = -ghost_->In();
}
// Make adjustment
if (!movement) {
ghost_->SetInAdjustment(0);