public DraggedItem(ItemVisualizer sourceItemVisualizer) { DropOnStashEffect = DragDropEffects.Move; DropOnInventoryEffect = DragDropEffects.Copy; DropOnBinEffect = DragDropEffects.Move; SourceItemVisualizer = sourceItemVisualizer; var mainWindow = (MetroWindow)Application.Current.MainWindow; var dragScope = (UIElement)mainWindow.Content; var imageSource = sourceItemVisualizer.Item.Image.ImageSource.Result; var brush = new ImageBrush(imageSource) { Opacity = 0.5 }; _dragAdorner = new DragAdorner(dragScope, new Size(imageSource.Width, imageSource.Height), brush); DragStart = Mouse.GetPosition(SourceItemVisualizer); // DragStart is subtracted for the cursor to be on the item image at the same position as where the drag // was initiated. // The window position is subtracted because the cursor position is retrieved as an absolute value. // The title bar height is subtracted because the content used for the adorner does not include it. var winPos = GetWindowPosition(mainWindow); _offset.X = -DragStart.X - winPos.X; _offset.Y = -DragStart.Y - winPos.Y - mainWindow.TitlebarHeight; _adornerLayer = AdornerLayer.GetAdornerLayer(dragScope); _adornerLayer.Add(_dragAdorner); DragDrop.AddGiveFeedbackHandler(sourceItemVisualizer, GiveFeedback); }
public DraggedItem(ItemVisualizer sourceItemVisualizer) { DropOnStashEffect = DragDropEffects.Move; DropOnInventoryEffect = DragDropEffects.Copy; DropOnBinEffect = DragDropEffects.Move; SourceItemVisualizer = sourceItemVisualizer; var mainWindow = (MetroWindow) Application.Current.MainWindow; var dragScope = (UIElement)mainWindow.Content; var imageSource = sourceItemVisualizer.Item.Image.ImageSource.Result; var brush = new ImageBrush(imageSource) { Opacity = 0.5 }; _dragAdorner = new DragAdorner(dragScope, new Size(imageSource.Width, imageSource.Height), brush); DragStart = Mouse.GetPosition(SourceItemVisualizer); // DragStart is subtracted for the cursor to be on the item image at the same position as where the drag // was initiated. // The window position is subtracted because the cursor position is retrieved as an absolute value. // The title bar height is subtracted because the content used for the adorner does not include it. var winPos = GetWindowPosition(mainWindow); _offset.X = -DragStart.X - winPos.X; _offset.Y = -DragStart.Y - winPos.Y - mainWindow.TitlebarHeight; _adornerLayer = AdornerLayer.GetAdornerLayer(dragScope); _adornerLayer.Add(_dragAdorner); DragDrop.AddGiveFeedbackHandler(sourceItemVisualizer, GiveFeedback); }
private void Iv_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { var siv = sender as ItemVisualizer; if (siv != null) { _dnd_startDrag = Mouse.GetPosition(gcontent);// e.GetPosition(gcontent); _dnd_overlay = new Rectangle() { HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top, Width = siv.ActualWidth, Height = siv.ActualHeight, Fill = Brushes.DarkGreen, Margin = siv.Margin, Opacity = 0.3, }; _dnd_original_Margin = siv.Margin; gcontent.Children.Add(_dnd_overlay); Grid.SetZIndex(_dnd_overlay, 52635); _dndVis = new ItemVisualizer() { HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top, Width = siv.ActualWidth, Height = siv.ActualHeight, Item = siv.Item, Margin = siv.Margin, Opacity = 0.5, Background = null, }; gcontent.Children.Add(_dndVis); Grid.SetZIndex(_dndVis, 52636); siv.Opacity = 0.3; _dnd_item = siv.Item; DragDrop.DoDragDrop(this, sender, DragDropEffects.Link | DragDropEffects.Move); siv.Opacity = 1; gcontent.Children.Remove(_dnd_overlay); gcontent.Children.Remove(_dndVis); _dndVis = null; _dnd_overlay = null; _dnd_item = null; } }
public DraggedItem(ItemVisualizer sourceItemVisualizer) { DropOnStashEffect = DragDropEffects.Move; DropOnInventoryEffect = DragDropEffects.Copy; DropOnBinEffect = DragDropEffects.Move; SourceItemVisualizer = sourceItemVisualizer; var mainWindow = (MetroWindow)Application.Current.MainWindow; var dragScope = (UIElement)mainWindow.Content; var imageSource = sourceItemVisualizer.Item.Image.ImageSource.Result; var brush = new ImageBrush(imageSource) { Opacity = 0.5 }; _dragAdorner = new DragAdorner(dragScope, new Size(imageSource.Width, imageSource.Height), brush); DragStart = Mouse.GetPosition(SourceItemVisualizer); // DragStart is subtracted for the cursor to be on the item image at the same position as where the drag // was initiated. // The window position is subtracted because the cursor position is retrieved as an absolute value. // The title bar height is subtracted because the content used for the adorner does not include it. var winPos = GetWindowPosition(mainWindow); _offset.X = -DragStart.X - winPos.X; _offset.Y = -DragStart.Y - winPos.Y - mainWindow.TitlebarHeight; _adornerLayer = AdornerLayer.GetAdornerLayer(dragScope); _adornerLayer.Add(_dragAdorner); // Win32.GetCursorPos() returns logical pixels, WPF uses physical/device pixels. // Need to scale from logical to physical if user has a custom UI scaling. _uiScaling = PresentationSource.FromVisual(_dragAdorner).CompositionTarget.TransformToDevice; DragDrop.AddGiveFeedbackHandler(sourceItemVisualizer, GiveFeedback); }
private void RedrawItems() { int from = PageTop; int to = PageBottom; foreach (var tab in Bookmarks)//TODO bisection method? { if (tab.Position >= from && tab.Position <= to) { var y = (tab.Position - from) * GridSize; Rectangle r; if (!_usedBMarks.TryGetValue(tab, out r)) { r = new Rectangle { Fill = new SolidColorBrush(tab.Color), Height = 2, Tag = tab, Cursor = Cursors.SizeNS }; r.MouseDown += R_MouseDown; gcontent.Children.Add(r); Panel.SetZIndex(r, 10000); _usedBMarks.Add(tab, r); } r.Margin = new Thickness(0, y - 1, 0, gcontent.ActualHeight - y - 1); continue; } if (_usedBMarks.ContainsKey(tab)) { gcontent.Children.Remove(_usedBMarks[tab]); _usedBMarks.Remove(tab); } } var items = new HashSet <Item>(_stashRange.Query(new Range <int>(from, to))); var toremove = _usedVisualizers.Where(p => !items.Contains(p.Key)).ToArray(); foreach (var item in toremove) { gcontent.Children.Remove(item.Value); _usedVisualizers.Remove(item.Key); } foreach (var item in items) { ItemVisualizer iv; if (!_usedVisualizers.TryGetValue(item, out iv)) { iv = new ItemVisualizer { HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top, Item = item }; Binding b = new Binding(); var menu = Resources["itemContextMenu"] as ContextMenu; b.Source = menu; b.Mode = BindingMode.OneWay; iv.SetBinding(ContextMenuProperty, b); if (_foundItems.Contains(item)) { iv.Background = ItemVisualizer.FoundItemBrush; } iv.MouseLeftButtonDown += Iv_MouseLeftButtonDown; _usedVisualizers.Add(item, iv); gcontent.Children.Add(iv); } Thickness m = new Thickness(item.X * GridSize, (item.Y - from) * GridSize, 0, 0); iv.Margin = m; iv.Width = item.Width * GridSize; iv.Height = item.Height * GridSize; } }