diff --git a/aegisub/src/audio_timing_dialogue.cpp b/aegisub/src/audio_timing_dialogue.cpp index 033ff7b7a..5ee64b02d 100644 --- a/aegisub/src/audio_timing_dialogue.cpp +++ b/aegisub/src/audio_timing_dialogue.cpp @@ -225,11 +225,9 @@ public: /// Get the leftmost of the markers DialogueTimingMarker *GetLeftMarker() { return left_marker; } - const DialogueTimingMarker *GetLeftMarker() const { return left_marker; } /// Get the rightmost of the markers DialogueTimingMarker *GetRightMarker() { return right_marker; } - const DialogueTimingMarker *GetRightMarker() const { return right_marker; } /// Does this line have a marker in the given range? bool ContainsMarker(TimeRange const& range) const @@ -345,6 +343,12 @@ class AudioTimingControllerDialogue : public AudioTimingController, private Sele /// Regenerate the list of active and inactive line markers void RegenerateMarkers(); + /// Get the start markers for the active line and all selected lines + std::vector GetLeftMarkers(); + + /// Get the end markers for the active line and all selected lines + std::vector GetRightMarkers(); + /// @brief Set the position of markers and announce the change to the world /// @param upd_markers Markers to move /// @param ms New position of the markers @@ -585,6 +589,8 @@ std::vector AudioTimingControllerDialogue::OnLeftClick(int ms, boo assert(sensitivity >= 0); assert(snap_range >= 0); + std::vector ret; + DialogueTimingMarker *left = active_line.GetLeftMarker(); DialogueTimingMarker *right = active_line.GetRightMarker(); @@ -597,14 +603,14 @@ std::vector AudioTimingControllerDialogue::OnLeftClick(int ms, boo // Insta-set the left marker to the clicked position and return the // right as the dragged one, such that if the user does start dragging, // he will create a new selection from scratch - std::vector ret(1, left); - SetMarkers(ret, SnapPosition(ms, snap_range, ret)); - ret[0] = right; + std::vector jump = GetLeftMarkers(); + ret = GetRightMarkers(); + // Get ret before setting as setting may swap left/right + SetMarkers(jump, SnapPosition(ms, snap_range, jump)); return ret; } DialogueTimingMarker *clicked = dist_l <= dist_r ? left : right; - std::vector ret; if (ctrl_down) { @@ -628,7 +634,7 @@ std::vector AudioTimingControllerDialogue::OnLeftClick(int ms, boo std::vector AudioTimingControllerDialogue::OnRightClick(int ms, bool, int sensitivity, int snap_range) { - std::vector ret(1, active_line.GetRightMarker()); + std::vector ret = GetRightMarkers(); SetMarkers(ret, SnapPosition(ms, snap_range, ret)); return ret; } @@ -787,6 +793,26 @@ void AudioTimingControllerDialogue::RegenerateMarkers() AnnounceMarkerMoved(); } +std::vector AudioTimingControllerDialogue::GetLeftMarkers() +{ + std::vector ret; + ret.reserve(selected_lines.size() + 1); + ret.push_back(active_line.GetLeftMarker()); + transform(selected_lines.begin(), selected_lines.end(), back_inserter(ret), + bind(&TimeableLine::GetLeftMarker, std::tr1::placeholders::_1)); + return ret; +} + +std::vector AudioTimingControllerDialogue::GetRightMarkers() +{ + std::vector ret; + ret.reserve(selected_lines.size() + 1); + ret.push_back(active_line.GetRightMarker()); + transform(selected_lines.begin(), selected_lines.end(), back_inserter(ret), + bind(&TimeableLine::GetRightMarker, std::tr1::placeholders::_1)); + return ret; +} + int AudioTimingControllerDialogue::SnapPosition(int position, int snap_range, std::vector const& exclude) const { if (snap_range <= 0)