using QuikDawEditor.EditingClasses; using QuikDawEditor.Properties; using QuikDawEditor.Undo; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; using static QuikDawEditor.EDITING.MiscMethods; using static QuikDawEditor.EDITING.StaticProperties; namespace QuikDawEditor; public partial class EditingControl { private void EditingControl_MouseWheel(object sender, MouseWheelEventArgs e) { e.Handled = true; if (Keyboard.IsKeyDown(Key.LeftShift) | Keyboard.IsKeyDown(Key.RightShift)) TracksContentSV.ScrollToHorizontalOffset(TracksContentSV.HorizontalOffset + Settings.Default.ScrollSpeedPixels * Math.Sign(e.Delta)); else { if (Math.Abs(e.Delta) <= 120) HorizontalZoomMainTracks(Math.Sign(e.Delta)); } } private void PlayLine_MouseLeave(object sender, MouseEventArgs e) { Cursor = Cursors.Arrow; } private void PlayLine_MouseMove(object sender, MouseEventArgs e) { } private void PlayLine_MouseDown(object sender, MouseButtonEventArgs e) { } private void PlayLine_MouseUp(object sender, MouseButtonEventArgs e) { } private void HiddenTrackTB_MouseDown(object sender, MouseButtonEventArgs e) { Track thisHiddenTrack = (Track)((TextBlock)sender).DataContext; undoActions.Add(new TrackHideToggleUndo(thisHiddenTrack.UndoTrackID)); thisHiddenTrack.IsTrackCollapsed = false; editingProject.hiddenTracks.Remove(thisHiddenTrack); HidTracksMenu.IsSubmenuOpen = false; } private void ShowAllHiddenTB_MouseDown(object sender, MouseButtonEventArgs e) { foreach (Track ht in editingProject.GetAllTracksInProject.Where(t => t.IsTrackCollapsed)) { undoActions.Add(new TrackHideToggleUndo(ht.UndoTrackID)); ht.IsTrackCollapsed = false; } editingProject.hiddenTracks.Clear(); } private void TrackContentControlsContextMenu_Opened(object sender, RoutedEventArgs e) { lastMouseDownX = Mouse.GetPosition(ScaleBarGrid).X; } private void Polygon_MouseEnter(object sender, MouseEventArgs e) { MouseOverPolygon = true; } private void Polygon_MouseLeave(object sender, MouseEventArgs e) { MouseOverPolygon = false; } private void ScaleBarGridContextMenu_Opened(object sender, RoutedEventArgs e) { lastMouseDownX = Mouse.GetPosition(ScaleBarGrid).X; } private void DockPanel_PreviewMouseDown(object sender, MouseButtonEventArgs e) { foreach (RecordInput rinpt in editingProject.RecordInputs) rinpt.IsActiveInput = false; DockPanel thisDP = (DockPanel)sender; RecordInput rinp = (RecordInput)thisDP.DataContext; Settings.Default.RecordInIndex = editingProject.RecordInputs.IndexOf(rinp); Settings.Default.Save(); rinp.IsActiveInput = true; foreach (Track t in editingProject.GetAllTracksInProject) t.UpdateRecInToolTip(); } private void TextBlock_MouseEnter(object sender, MouseEventArgs e) { TextBlock thisTB = (TextBlock)sender; DockPanel thisDP = (DockPanel)thisTB.Parent; //thisTB.Background = new SolidColorBrush(Colors.Azure) { Opacity = 0.65 }; thisDP.Background = new SolidColorBrush(Colors.Azure) { Opacity = 0.65 }; } private void TextBlock_MouseLeave(object sender, MouseEventArgs e) { TextBlock thisTB = (TextBlock)sender; //thisTB.Background = Brushes.Transparent; DockPanel thisDP = (DockPanel)thisTB.Parent; thisDP.Background = Brushes.Transparent; } private double lastMouseDownX = 0; private bool MouseOverPolygon = false; bool MouseDownOnScaleBar = false; double MouseDownOnScaleBarX; double MouseDownOnScaleBarY; double LastMouseDownOnScaleBarY; bool RectSelectionMode = false; bool MouseScrollingOnScaleBar; private void ScaleBarGrid_MouseDown(object sender, MouseButtonEventArgs e) { if (MouseOverPolygon) return; ScaleBarGrid.CaptureMouse(); double realX = e.GetPosition(ScaleBarGrid).X / editingProject.ViewXZoomFac; MouseDownOnScaleBar = true; MouseDownOnScaleBarX = GetNearestSnapPix(realX); MouseDownOnScaleBarY = e.GetPosition(ScaleBarGrid).Y; LastMouseDownOnScaleBarY = e.GetPosition(ScaleBarGrid).Y; projPlayer.SendLocalMessage("TimePoint= " + TimeSpan.FromMilliseconds(PixelsToMsec(realX)).ToString().Substring(3)); } private void ScaleBarGrid_MouseUp(object sender, MouseButtonEventArgs e) { e.Handled = true; ScaleBarGrid.ReleaseMouseCapture(); if (RectSelectionMode) { RectSelectionMode = false; return; } double realX = e.GetPosition(ScaleBarGrid).X / editingProject.ViewXZoomFac; if (e.ChangedButton == MouseButton.Left && !MouseScrollingOnScaleBar) { projPlayer.CurrentPlayingPosMS = GetNearestSnapMs(realX / PixelsPerSecond * 1000, editingProject.CurrentSnapTo); projPlayer.ChangePlayPos(projPlayer.CurrentPlayingPosMS); projPlayer.UpdatePlayPosLine(); } MouseDownOnScaleBar = false; MouseScrollingOnScaleBar = false; } private void ScaleBarGrid_MouseMove(object sender, MouseEventArgs e) { if (MouseDownOnScaleBar) { //double realX = e.GetPosition(ScaleBarGrid).X / editingProject.ViewXZoomFac; //if (RectSelectionMode) //{ // projPlayer.RangeSelectRect.rectWidth = GetNearestSnapPix(Math.Max(MsecToPixels(GetSnapMsVal(editingProject.CurrentSnapTo)), realX - MouseDownOnScaleBarX)); // return; //} //if (Math.Abs(realX - MouseDownOnScaleBarX) > MsecToPixels(GetSnapMsVal(editingProject.CurrentSnapTo))) //minimum width of 1 sec //{ // ScaleBarGrid.CaptureMouse(); // projPlayer.RangeSelectRect.rectLeft = MouseDownOnScaleBarX; // RectSelectionMode = true; // projPlayer.RangeSelectRect.rectWidth = GetNearestSnapPix(MsecToPixels(GetSnapMsVal(editingProject.CurrentSnapTo))); // projPlayer.RangeSelectRect.Selected = true; //} double diffY = e.GetPosition(ScaleBarGrid).Y - LastMouseDownOnScaleBarY; double diffMouseDownY = e.GetPosition(ScaleBarGrid).Y - MouseDownOnScaleBarY; if (Math.Abs(diffY) >=1 && Math.Abs(diffMouseDownY) > 5) { MouseScrollingOnScaleBar = true; //if (Math.Sign(diffY) == 1 || MsecToPixelsZoomed(editingProject.projectEndPointMs) > TracksContentSV.ActualWidth) HorizontalZoomMainTracks(Math.Sign(diffY)); LastMouseDownOnScaleBarY = e.GetPosition(ScaleBarGrid).Y; } } } private void Marker_PreviewMouseUp(object sender, MouseButtonEventArgs e) { Border thisBorder = (Border)sender; Marker thisMarker = (Marker)thisBorder.DataContext; if (MouseDownOnMarker) { if (thisMarker.timePosMs != lastMarkerTimeMs) undoActions.Add(new ArrangeMarkerPosChangeUndo(editingProject.Markers.IndexOf(thisMarker), lastMarkerTimeMs)); } if (MouseDownOnMarkerRight) undoActions.Add(new ArrangeMarkerWidthChangeUndo(editingProject.Markers.IndexOf(thisMarker), lastMarkerWidthMs)); e.Handled = true; thisBorder.ReleaseMouseCapture(); MouseDownOnMarkerRight = false; MouseDownOnMarker = false; MouseOverMarker = false; MouseOverMarkerRight = false; } private void Marker_PreviewMouseMove(object sender, MouseEventArgs e) { Border thisBorder = (Border)sender; Marker thisMarker = (Marker)thisBorder.DataContext; e.Handled = true; if (MouseDownOnMarker) { thisMarker.timePosMs = Math.Max(0, GetNearestSnapMs(thisMarker.timePosMs + PixelsToMsecZoomed(e.GetPosition(thisBorder).X - MouseDownOnMarkerX), editingProject.CurrentSnapTo)); editingProject.NeedsSaving = true; return; } if (MouseDownOnMarkerRight) { thisMarker.widthMs = (double)Math.Max(editingProject.BeatsPerMeasure * MillisecondsPerBeat, GetNearestSnapMs(PixelsToMsecZoomed(e.GetPosition(thisBorder).X), editingProject.CurrentSnapTo)); editingProject.NeedsSaving = true; return; } if (e.GetPosition(thisBorder).X > thisMarker.widthPixels - 7) { MouseOverMarkerRight = true; Cursor = Cursors.SizeWE; } else { MouseOverMarkerRight = false; Cursor = Cursors.Hand; } } bool MouseOverMarker = false; bool MouseOverMarkerRight = false; bool MouseDownOnMarkerRight = false; bool MouseDownOnMarker = false; double MouseDownOnMarkerX = 0; double MouseDownOnMarkertimePosMs = 0; double lastMarkerTimeMs, lastMarkerWidthMs; private void Marker_PreviewMouseDown(object sender, MouseButtonEventArgs e) { Border thisBorder = (Border)sender; Marker thisMarker = (Marker)thisBorder.DataContext; e.Handled = true; thisBorder.CaptureMouse(); if (e.ChangedButton == MouseButton.Right) { thisBorder.ContextMenu.IsOpen = true; currentMarker = thisMarker; return; } if (e.ClickCount == 2) { projPlayer.ChangePlayPos(thisMarker.timePosMs); projPlayer.UpdatePlayPosDisplay(); TracksContentSV.ScrollToHorizontalOffset(Math.Max(0, MsecToPixelsZoomed(thisMarker.timePosMs) - 50)); return; } if (MouseOverMarkerRight) { MouseDownOnMarkerRight = true; lastMarkerWidthMs = thisMarker.widthMs; return; } MouseDownOnMarker = true; MouseDownOnMarkerX = e.GetPosition(thisBorder).X; MouseDownOnMarkertimePosMs = thisMarker.timePosMs; MarkersCBSelectionChanged(editingProject.Markers.IndexOf(thisMarker)); lastMarkerTimeMs = thisMarker.timePosMs; MouseDownOnArrangerBar = false; } private void markerBorder_MouseLeave(object sender, MouseEventArgs e) { MouseOverMarkerRight = false; MouseOverMarker = false; Cursor = Cursors.Arrow; } private void markerBorder_MouseEnter(object sender, MouseEventArgs e) { MouseOverMarker = true; Cursor = Cursors.Hand; } bool MouseDownOnArrangerBar = false; double MouseDownOnArrangerBarX = 0; private void ArrangerBar_PreviewMouseDown(object sender, MouseButtonEventArgs e) { if (MouseOverMarker | MouseOverMarkerRight | MouseDownOnMarkerRight | MouseDownOnMarker) return; MouseDownOnArrangerBarX = e.GetPosition(ArrangerBar).X; MouseDownOnArrangerBar = true; ArrangerBar.CaptureMouse(); } Marker newMarker = null; bool addingNewMarker = false; private void ArrangerBar_PreviewMouseUp(object sender, MouseButtonEventArgs e) { ArrangerBar.ReleaseMouseCapture(); MouseDownOnArrangerBar = false; MouseOverMarker = false; MouseOverMarkerRight = false; addingNewMarker = false; } private void ArrangerBar_PreviewMouseMove(object sender, MouseEventArgs e) { if (MouseDownOnArrangerBar) { double MeasureWidthMs = editingProject.BeatsPerMeasure * MillisecondsPerBeat; if (e.GetPosition(ArrangerBar).X - MouseDownOnArrangerBarX > MsecToPixels(MeasureWidthMs / 2)) { if (addingNewMarker) newMarker.widthMs = Math.Max(MeasureWidthMs, PixelsToMsecZoomed(e.GetPosition(ArrangerBar).X - MouseDownOnArrangerBarX)); else { newMarker = new Marker() { Name = "New section", widthMs = MeasureWidthMs, timePosMs = GetNearestSnapMs((int)PixelsToMsecZoomed(MouseDownOnArrangerBarX), editingProject.CurrentSnapTo) }; Marker insertBeforeMarker = editingProject.Markers.FirstOrDefault(m => m.timePosMs >= newMarker.timePosMs); int insertIdx = insertBeforeMarker == null ? editingProject.Markers.Count : editingProject.Markers.IndexOf(insertBeforeMarker); editingProject.Markers.Insert(insertIdx, newMarker); undoActions.Add(new ArrangeMarkerAddUndo(insertIdx)); editingProject.NeedsSaving = true; addingNewMarker = true; } } } } private void TrackContentControlsIC_MouseDown(object sender, MouseButtonEventArgs e) { MouseDownOnTCC_IC = true; MouseDownOnTCC_ICPoint = e.GetPosition(TrackContentControlsIC); editingProject.ClipGainSliderVisibility = Visibility.Hidden; } private void TrackContentControlsIC_MouseUp(object sender, MouseButtonEventArgs e) { MouseDownOnTCC_IC = false; projPlayer.ClipSelectionRect.IsVisible = false; TrackContentControlsIC.ReleaseMouseCapture(); } bool MouseDownOnTCC_IC; Point MouseDownOnTCC_ICPoint; private void ClipGainSlider_PreviewMouseUp(object sender, MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.Right) editingProject.GainSliderValue = 0; undoActions.Add(new ClipGainChangeUndoClass(editingProject.GainAdjustingClip.UndoClipID, editingProject.preSliderGainValue)); editingProject.NeedsSaving = true; } private void ClipGainSlider_PreviewMouseDown(object sender, MouseButtonEventArgs e) { editingProject.preSliderGainValue = editingProject.GainAdjustingClip.ClipGainFactor; } private void ColorPicker16_MouseDown(object sender, MouseButtonEventArgs e) { ColorPicker16 cp16 = (ColorPicker16)sender; undoActions.Add(new ArrangeMarkerColorChangeUndo(editingProject.Markers.IndexOf(currentMarker), currentMarker.markerBackground)); currentMarker.markerBackground = cp16.SelectedBrush.ToString(); editingProject.NeedsSaving = true; } private void TrackContentControlsIC_MouseMove(object sender, MouseEventArgs e) { if (TrackContentControlChildBeingModified) { TrackContentControlsIC.ReleaseMouseCapture(); return; } if (MouseDownOnTCC_IC) { Vector v = Point.Subtract(e.GetPosition(TrackContentControlsIC), MouseDownOnTCC_ICPoint); if (v.X > 9 | v.Y > 9) { TrackContentControlsIC.CaptureMouse(); projPlayer.ClipSelectionRect.IsVisible = true; projPlayer.ClipSelectionRect.rectLeft = MouseDownOnTCC_ICPoint.X / editingProject.ViewXZoomFac; projPlayer.ClipSelectionRect.rectTop = MouseDownOnTCC_ICPoint.Y; projPlayer.ClipSelectionRect.rectWidth = Math.Max(5, v.X * editingProject.ViewXZoomFac); projPlayer.ClipSelectionRect.rectHeight = Math.Max(5, v.Y); Rect msRect = projPlayer.ClipSelectionRect.GetClipSelectingRect; List containedClips = GetContainedClips(msRect); foreach (Clip c in editingProject.GetAllClips) c.IsSelected = false; foreach (Clip c in containedClips) c.IsSelected = true; } } } private void lyricBorder_PreviewMouseDown(object sender, MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.Right) return; Border thisBorder = (Border)sender; LyricLine thisLyricLine = (LyricLine)thisBorder.DataContext; if (e.ClickCount == 2) { projPlayer.ChangePlayPos(thisLyricLine.timePosMs); projPlayer.UpdatePlayPosDisplay(); TracksContentSV.ScrollToHorizontalOffset(Math.Max(0, MsecToPixelsZoomed(thisLyricLine.timePosMs) - 50)); return; } e.Handled = true; thisBorder.CaptureMouse(); MouseDownOnLyricLine = true; MouseDownOnLyricLineX = e.GetPosition(thisBorder).X; MouseDownOnLyricLinetimePosMs = thisLyricLine.timePosMs; lastLyricLineTimeMs = MouseDownOnLyricLinetimePosMs; } bool MouseDownOnLyricLine = false; double MouseDownOnLyricLineX = 0; double MouseDownOnLyricLinetimePosMs = 0; double lastLyricLineTimeMs; private void lyricBorder_PreviewMouseUp(object sender, MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.Right) return; Border thisBorder = (Border)sender; LyricLine thisLyricLine = (LyricLine)thisBorder.DataContext; if (MouseDownOnLyricLine) { if (thisLyricLine.timePosMs != lastLyricLineTimeMs) undoActions.Add(new LyricLineTimePosChangeUndo(editingProject.shownLyricLines.IndexOf(thisLyricLine), lastLyricLineTimeMs)); } e.Handled = true; thisBorder.ReleaseMouseCapture(); MouseDownOnLyricLine = false; } private void lyricBorder_PreviewMouseMove(object sender, MouseEventArgs e) { Cursor = Cursors.Hand; if (MouseDownOnLyricLine) { Border thisBorder = (Border)sender; LyricLine thisLyricLine = (LyricLine)thisBorder.DataContext; e.Handled = true; int thisLyricIdx = editingProject.shownLyricLines.IndexOf(thisLyricLine); if (thisLyricIdx > -1) { double maxMovableDistanceLeftMs = thisLyricLine.timePosMs - (thisLyricIdx == 0 ? 0 : editingProject.shownLyricLines[thisLyricIdx - 1].timePosMs + minLyricLineWidthMs); //double distanceMoved = Math.Max(-maxMovableDistanceLeft, PixelsToMsecZoomed(e.GetPosition(thisBorder).X - MouseDownOnLyricLineX)); double maxMoveableDistanceRightMs = thisLyricIdx == editingProject.shownLyricLines.Count - 1 ? Double.PositiveInfinity : editingProject.shownLyricLines[thisLyricIdx + 1].timePosMs - minLyricLineWidthMs / 2 - thisLyricLine.timePosMs; double distanceMoved = Math.Min(maxMoveableDistanceRightMs, Math.Max(-maxMovableDistanceLeftMs, PixelsToMsecZoomed(e.GetPosition(thisBorder).X - MouseDownOnLyricLineX))); if (Keyboard.IsKeyDown(Key.LeftCtrl) | Keyboard.IsKeyDown(Key.RightCtrl)) { for (int lidx = thisLyricIdx; lidx < editingProject.shownLyricLines.Count; lidx++) { LyricLine nextLL = editingProject.shownLyricLines[lidx]; nextLL.timePosMs = GetNearestSnapMs(nextLL.timePosMs + distanceMoved, editingProject.CurrentSnapTo); } } else thisLyricLine.timePosMs = GetNearestSnapMs(thisLyricLine.timePosMs + distanceMoved, editingProject.CurrentSnapTo); editingProject.NeedsSaving = true; } else Debug.WriteLine("lyricidx= " + thisLyricIdx.ToString()); return; } } private void lyricBorder_MouseLeave(object sender, MouseEventArgs e) { MouseDownOnLyricLine = false; Cursor = Cursors.Arrow; } }