using QuikDawEditor.EditingClasses; using System; using System.ComponentModel; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; using static QuikDawEditor.EDITING.VstMethods; using static QuikDawEditor.EDITING.StaticProperties; using QuikDawEditor.VST; namespace QuikDawEditor { public partial class VstFxWindow : Window, INotifyPropertyChanged { bool mouseDownInTitleBar = false; System.Windows.Point MouseDownPos; private void TitleLabel_PreviewMouseDown(object sender, MouseButtonEventArgs e) { mouseDownInTitleBar = true; MouseDownPos = e.GetPosition(this); Mouse.Capture(this.TitleLabel); } private void TitleLabel_PreviewMouseMove(object sender, MouseEventArgs e) { if (mouseDownInTitleBar) { var newPoint = e.GetPosition(this) - MouseDownPos; this.Left += newPoint.X; this.Top += newPoint.Y; } } private void TitleLabel_PreviewMouseUp(object sender, MouseButtonEventArgs e) { mouseDownInTitleBar = false; Mouse.Capture(this.TitleLabel, CaptureMode.None); } private void VstFxFavoritesTV_MouseDown(object sender, MouseButtonEventArgs e) { if (VstFavoriteFolderEditing && !MouseInTextBox) { VstFavorite thisVF = (VstFavorite)editingTB.DataContext; if (editingTB.Text == "") { MessageBox.Show("Cannot have empty folder name"); return; } editingTB.BorderThickness = new Thickness(0); editingTB.Background = Brushes.Transparent; editingTB.IsReadOnly = true; editingTB.Focusable = false; VstFavoriteFolderEditing = false; thisVF.FolderName = editingTB.Text; SaveVstFxFavorites(); } } bool MouseInTextBox = false; private void DisplayNameTextBox_MouseEnter(object sender, MouseEventArgs e) { TextBox thisTB = (TextBox)sender; thisTB.Background = thisTB.IsReadOnly ? Brushes.Gray : Brushes.White; MouseInTextBox = true; } private void DisplayNameTextBox_MouseLeave(object sender, MouseEventArgs e) { TextBox thisTB = (TextBox)sender; thisTB.Background = thisTB.IsReadOnly ? Brushes.Transparent : Brushes.White; MouseInTextBox = false; } bool MouseDownOnVstItem = false; Point MouseDownPoint = new Point(); private void VstFxItemsGrid_PreviewMouseDown(object sender, MouseButtonEventArgs e) { Grid thisGrid = (Grid)sender; MouseDownPoint = e.GetPosition(thisGrid); thisGrid.CaptureMouse(); MouseDownOnVstItem = true; } private void VstFxItemsGrid_PreviewMouseUp(object sender, MouseButtonEventArgs e) { MouseDownOnVstItem = false; ((Grid)sender).ReleaseMouseCapture(); } private void VstFxItemsGrid_PreviewMouseMove(object sender, MouseEventArgs e) { Grid thisGrid = (Grid)sender; if (MouseDownOnVstItem) { Vector vec = Point.Subtract(e.GetPosition(thisGrid), MouseDownPoint); bool dragme = (Math.Abs(vec.X) > 6 || Math.Abs(vec.Y) > 6); if (dragme) { MouseDownOnVstItem = false; thisGrid.ReleaseMouseCapture(); var dataObj = new DataObject(); dataObj.SetData("vstfxrefdrag", (VstPluginReference)thisGrid.DataContext); DragDrop.DoDragDrop(thisGrid, dataObj, DragDropEffects.Copy); } } } private void SelectedVstsLV_Drop(object sender, DragEventArgs e) { Track thisTrack = (Track)this.DataContext; if (e.Data.GetDataPresent("vstfxrefdrag")) { VstPluginReference thisVSTRef = (VstPluginReference)e.Data.GetData("vstfxrefdrag"); if (thisVSTRef.isNotifying) return; AddVSTEffect(thisTrack, thisVSTRef); editingProject.NeedsSaving = true; if (SelectedVstsLV.Items.Count > 0) SelectedVstsLV.ScrollIntoView(SelectedVstsLV.Items[SelectedVstsLV.Items.Count - 1]); } else if (e.Data.GetDataPresent("vstfxfavdrag")) { VstFavorite thisVSTFav = (VstFavorite)e.Data.GetData("vstfxfavdrag"); VstPluginReference thisVSTRef = thisVSTFav.myPluginRef; if (thisVSTRef != null) { if (thisVSTRef.isNotifying) return; AddVSTEffect(thisTrack, thisVSTRef); editingProject.NeedsSaving = true; if (SelectedVstsLV.Items.Count > 0) SelectedVstsLV.ScrollIntoView(SelectedVstsLV.Items[SelectedVstsLV.Items.Count - 1]); } } } private void SelectedVstsLV_DragOver(object sender, DragEventArgs e) { e.Handled = true; if (e.Data.GetDataPresent("vstfxrefdrag") | e.Data.GetDataPresent("vstfxfavdrag")) { if (e.Data.GetDataPresent("vstfxfavdrag")) { VstFavorite thisVSTFav = (VstFavorite)e.Data.GetData("vstfxfavdrag"); if (thisVSTFav.ItemType == "Folder") e.Effects = DragDropEffects.None; else e.Effects = DragDropEffects.Copy; } else e.Effects = DragDropEffects.Copy; } else e.Effects = DragDropEffects.None; } bool MouseOverVstItem = false; private void VstItemStackPanel_MouseLeave(object sender, MouseEventArgs e) { } private void VstItemStackPanel_MouseEnter(object sender, MouseEventArgs e) { MouseOverVstItem = true; } private void VstFxFavoritesTV_DragOver(object sender, DragEventArgs e) { if (e.Data.GetDataPresent("vstfxrefdrag")) { e.Effects = DragDropEffects.Copy; } else if (e.Data.GetDataPresent("vstfxfavdrag")) { e.Effects = DragDropEffects.Move; } else e.Effects = DragDropEffects.None; } private void VstFxFavoritesTV_Drop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent("vstfxrefdrag")) { VstPluginReference thisVSTRef = (VstPluginReference)e.Data.GetData("vstfxrefdrag"); VstFxFavorites.Add(new VstFavorite("Plugin", thisVSTRef)); SaveVstFxFavorites(); } else if (e.Data.GetDataPresent("vstfxfavdrag")) { VstFavorite thisVSTFav = (VstFavorite)e.Data.GetData("vstfxfavdrag"); GetParentFavoriteCollection(VstFxFavorites, thisVSTFav).Remove(thisVSTFav); VstFxFavorites.Add(thisVSTFav); SaveVstFxFavorites(); } } private void TextBox_PreviewDragOver(object sender, DragEventArgs e) { e.Handled = true; StackPanel thisSP = (StackPanel)sender; VstFavorite vstf = (VstFavorite)thisSP.DataContext; if (vstf.ItemType == "Folder") { if (e.Data.GetDataPresent("vstfxrefdrag")) { e.Effects = DragDropEffects.Copy; } else if (e.Data.GetDataPresent("vstfxfavdrag")) { VstFavorite vfavsource = (VstFavorite)e.Data.GetData("vstfxfavdrag"); bool folderContainsFolder = vfavsource.ItemType == "Folder" && FolderContainsFolder(vfavsource, vstf); if (vstf.VstFavorites.Contains(vfavsource) || folderContainsFolder) e.Effects = DragDropEffects.None; else e.Effects = DragDropEffects.Move; } } else e.Effects = DragDropEffects.None; } private void TextBox_PreviewDrop(object sender, DragEventArgs e) { e.Handled = true; StackPanel thisSP = (StackPanel)sender; VstFavorite vstf = (VstFavorite)thisSP.DataContext; if (e.Data.GetDataPresent("vstfxrefdrag")) { VstPluginReference thisVSTRef = (VstPluginReference)e.Data.GetData("vstfxrefdrag"); vstf.VstFavorites.Insert(0, new VstFavorite("Plugin", thisVSTRef)); vstf.IsExpanded = true; SaveVstFxFavorites(); } else if (e.Data.GetDataPresent("vstfxfavdrag")) { VstFavorite thisVSTFav = (VstFavorite)e.Data.GetData("vstfxfavdrag"); GetParentFavoriteCollection(VstFxFavorites, thisVSTFav).Remove(thisVSTFav); vstf.VstFavorites.Insert(0, thisVSTFav); vstf.IsExpanded = true; SaveVstFxFavorites(); } } bool MouseDownOnVstFavorite = false; Point MouseDownOnVstFavoritePoint = new Point(); bool VstFavoriteFolderEditing = false; private void DisplayNameTextBox_PreviewMouseDown(object sender, MouseButtonEventArgs e) { TextBox thisTB = (TextBox)sender; VstFavorite thisVF = (VstFavorite)thisTB.DataContext; if (e.ClickCount == 2) { if (VstFavoriteFolderEditing) return; if (thisVF.ItemType == "Folder") { editingTB = thisTB; thisTB.BorderThickness = new Thickness(1); thisTB.Background = Brushes.White; thisTB.IsReadOnly = false; VstFavoriteFolderEditing = true; thisTB.Focusable = true; thisTB.SelectAll(); } return; } MouseDownOnVstFavorite = true; MouseDownOnVstFavoritePoint = e.GetPosition(thisTB); thisTB.CaptureMouse(); } private void DisplayNameTextBox_PreviewMouseUp(object sender, MouseButtonEventArgs e) { MouseDownOnVstFavorite = false; ((TextBox)sender).ReleaseMouseCapture(); } private void DisplayNameTextBox_PreviewMouseMove(object sender, MouseEventArgs e) { if (MouseDownOnVstFavorite) { TextBox vstfTB = (TextBox)sender; VstFavorite thisVFav = (VstFavorite)vstfTB.DataContext; bool isDraggablePlugin = thisVFav.ItemType == "Plugin" && thisVFav.ExistsVstFx; if (isDraggablePlugin) { Vector vec = Point.Subtract(e.GetPosition(vstfTB), MouseDownOnVstFavoritePoint); bool dragme = (Math.Abs(vec.X) > 5 || Math.Abs(vec.Y) > 3); if (dragme) { MouseDownOnVstFavorite = false; vstfTB.ReleaseMouseCapture(); var dataObj = new DataObject(); dataObj.SetData("vstfxfavdrag", (VstFavorite)vstfTB.DataContext); DragDrop.DoDragDrop(vstfTB, dataObj, DragDropEffects.Move | DragDropEffects.Copy); } } } } bool scrolling = false; private void ScrollViewer_PreviewMouseWheel(object sender, MouseWheelEventArgs e) { if (scrolling) return; scrolling = true; ScrollViewer sviewer = (ScrollViewer)sender; sviewer.ScrollToVerticalOffset(sviewer.VerticalOffset - e.Delta / 3); scrolling = false; } } }