using System; using System.Diagnostics; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Shapes; using static QuikDawEditor.EDITING.MiscMethods; using static QuikDawEditor.EDITING.StaticProperties; namespace QuikDawEditor; public partial class EditingControl { bool _mouseOverRight = false; bool _mouseOverLeft = false; bool MouseOverRangeRectRight { get { return _mouseOverRight; } set { _mouseOverRight = value; Cursor = value ? Cursors.SizeWE : Cursors.Arrow; } } bool MouseOverRangeRectLeft { get { return _mouseOverLeft; } set { _mouseOverLeft = value; Cursor = value ? Cursors.SizeWE : Cursors.Arrow; } } bool MouseDownOverRangeRectRight; bool MouseDownOverRangeRectLeft; double MinSelectRectWidthMs { get { return Math.Max(1000, 2000 / editingProject.ViewXZoomFac); } } private void LoopRangeSelectionRect_MouseMove(object sender, MouseEventArgs e) { Border thisBorder = (Border)sender; double relMouseX = e.GetPosition(thisBorder).X / editingProject.ViewXZoomFac; if (MouseDownOverRangeRectRight) { thisBorder.CaptureMouse(); editingProject.LoopRangeWidthMs = Math.Max(MinSelectRectWidthMs, GetNearestSnapMs(PixelsToMsec(relMouseX), editingProject.CurrentSnapTo)); return; } if (MouseDownOverRangeRectLeft) { thisBorder.CaptureMouse(); double newLeftMs = GetNearestSnapMs(Math.Min(Math.Max(0, editingProject.LoopRangeLeftMs + PixelsToMsec(relMouseX)), editingProject.LoopRangeLeftMs + editingProject.LoopRangeWidthMs - Math.Max(MinSelectRectWidthMs, GetSnapMsVal(editingProject.CurrentSnapTo))), editingProject.CurrentSnapTo); double changeXMs = editingProject.LoopRangeLeftMs - newLeftMs; editingProject.LoopRangeLeftMs = newLeftMs; editingProject.LoopRangeWidthMs += changeXMs; return; } MouseOverRangeRectRight = false; MouseOverRangeRectLeft = false; if (e.GetPosition(thisBorder).X > editingProject.LoopRangeWidthPix - 14) MouseOverRangeRectRight = true; if (e.GetPosition(thisBorder).X < 14) MouseOverRangeRectLeft = true; } private void LoopRangeSelectionRect_MouseDown(object sender, MouseButtonEventArgs e) { MouseDownOverRangeRectRight = MouseOverRangeRectRight; MouseDownOverRangeRectLeft = MouseOverRangeRectLeft; if (MouseDownOverRangeRectRight | MouseDownOverRangeRectLeft) ((Border)sender).CaptureMouse(); } private void LoopRangeSelectionRect_MouseUp(object sender, MouseButtonEventArgs e) { Border thisBorder = (Border)sender; MouseOverRangeRectRight = false; MouseOverRangeRectLeft = false; MouseDownOverRangeRectRight = false; MouseDownOverRangeRectLeft = false; thisBorder.ReleaseMouseCapture(); } private void LoopRangeSelectionRect_MouseLeave(object sender, MouseEventArgs e) { MouseOverRangeRectRight = false; MouseOverRangeRectLeft = false; Border thisRect = (Border)sender; thisRect.ReleaseMouseCapture(); } bool MouseOverFlagsDPRight = false; bool MouseOverFlagsDPLeft = false; bool MouseDownOnFlagsDPRight = false; bool MouseDownOnFlagsDPLeft = false; private void RangeSelectRectFlagsDP_PreviewMouseMove(object sender, MouseEventArgs e) { double mouseX = e.GetPosition(RangeSelectRectFlagsDP).X; if (MouseDownOnFlagsDPLeft) { double newLeftMs = GetNearestSnapMs(Math.Min(Math.Max(0, PixelsToMsecZoomed(e.GetPosition(ScaleBarGrid).X)), editingProject.LoopRangeLeftMs + editingProject.LoopRangeWidthMs - Math.Max(MinSelectRectWidthMs, GetSnapMsVal(editingProject.CurrentSnapTo))), editingProject.CurrentSnapTo); double changeXMs = editingProject.LoopRangeLeftMs - newLeftMs; editingProject.LoopRangeLeftMs = newLeftMs; editingProject.LoopRangeWidthMs += changeXMs; return; } if (MouseDownOnFlagsDPRight) { editingProject.LoopRangeWidthMs = Math.Max(MinSelectRectWidthMs, GetNearestSnapMs(PixelsToMsecZoomed(mouseX), editingProject.CurrentSnapTo)); return; } MouseOverFlagsDPRight = RangeSelectRectFlagsDP.ActualWidth - mouseX < 10; MouseOverFlagsDPLeft = mouseX < 10; if (MouseOverFlagsDPLeft || MouseOverFlagsDPRight) Cursor = Cursors.SizeWE; else Cursor = Cursors.Arrow; } private void RangeSelectRectFlagsDP_MouseLeave(object sender, MouseEventArgs e) { MouseOverFlagsDPLeft = false; MouseOverFlagsDPRight = false; MouseDownOnFlagsDPLeft = false; MouseDownOnFlagsDPRight = false; Cursor = Cursors.Arrow; } private void RangeSelectRectFlagsDP_PreviewMouseDown(object sender, MouseButtonEventArgs e) { MouseDownOnFlagsDPRight = MouseOverFlagsDPRight; MouseDownOnFlagsDPLeft = MouseOverFlagsDPLeft; if (MouseDownOnFlagsDPLeft || MouseDownOnFlagsDPRight) { RangeSelectRectFlagsDP.CaptureMouse(); e.Handled = true; } } private void RangeSelectRectFlagsDP_PreviewMouseUp(object sender, MouseButtonEventArgs e) { MouseDownOnFlagsDPLeft = false; MouseDownOnFlagsDPRight = false; RangeSelectRectFlagsDP.ReleaseMouseCapture(); e.Handled = true; } }