public virtual void Drop(List <object> node, DropPosition mode, bool copy) { bool runningCompositeTask = Services.TaskService.IsRunningCompositeTask; if (!runningCompositeTask) { Services.TaskService.BeginCompositeTask("Drag drop GameObject"); } foreach (object obj in node) { if (!copy) { IDragSource dragSource = obj as IDragSource; if (dragSource != null) { dragSource.Detach(); } } NodeObject gameObjectData = obj as NodeObject; if (gameObjectData != null) { this.LoadDropObject(gameObjectData, mode); } } if (runningCompositeTask) { return; } Services.TaskService.EndCompositeTask(); }
/// <summary> /// Starts a drag. /// </summary> /// <param name="b"> The bitmap to display as the drag image. It will be re-scaled to the /// enlarged size. </param> /// <param name="screenX"> The x position on screen of the left-top of the bitmap. </param> /// <param name="screenY"> The y position on screen of the left-top of the bitmap. </param> /// <param name="textureLeft"> The left edge of the region inside b to use. </param> /// <param name="textureTop"> The top edge of the region inside b to use. </param> /// <param name="textureWidth"> The width of the region inside b to use. </param> /// <param name="textureHeight"> The height of the region inside b to use. </param> /// <param name="source"> An object representing where the drag originated </param> /// <param name="dragInfo"> The data associated with the object that is being dragged </param> /// <param name="dragAction"> The drag action: either <seealso cref="#DRAG_ACTION_MOVE"/> or /// <seealso cref="#DRAG_ACTION_COPY"/> </param> public void StartDrag(Bitmap b, int screenX, int screenY, int textureLeft, int textureTop, int textureWidth, int textureHeight, IDragSource source, object dragInfo, int dragAction) { if (PROFILE_DRAWING_DURING_DRAG) { Debug.StartMethodTracing("Launcher"); } // Hide soft keyboard, if visible if (mInputMethodManager == null) { mInputMethodManager = (InputMethodManager)mContext.GetSystemService(Context.InputMethodService); } mInputMethodManager.HideSoftInputFromWindow(mWindowToken, 0); if (mListener != null) { mListener.OnDragStart(source, dragInfo, dragAction); } int registrationX = ((int)mMotionDownX) - screenX; int registrationY = ((int)mMotionDownY) - screenY; mTouchOffsetX = mMotionDownX - screenX; mTouchOffsetY = mMotionDownY - screenY; mDragging = true; mDragSource = source; mDragInfo = dragInfo; //mVibrator.vibrate(VIBRATE_DURATION); DragView dragView = mDragView = new DragView(mContext, b, registrationX, registrationY, textureLeft, textureTop, textureWidth, textureHeight); dragView.Show(mWindowToken, (int)mMotionDownX, (int)mMotionDownY); }
public override void OnAttached() { if (AssociatedObject is IDragSource dragSource) { DragSource = dragSource; DragSource.ItemsChanged += () => { foreach (FrameworkElement item in DragSource.GetItems()) { item.PreviewMouseLeftButtonDown -= Item_OnPreviewMouseLeftButtonDown; item.PreviewMouseMove -= Item_OnPreviewMouseMove; item.PreviewMouseLeftButtonDown += Item_OnPreviewMouseLeftButtonDown; item.PreviewMouseMove += Item_OnPreviewMouseMove; } }; Background.PreviewMouseMove += Background_OnPreviewMouseMove; Background.MouseLeftButtonUp += Background_OnMouseLeftButtonUp; } else { throw new ArgumentException("This behavior could be attached only to objects of type IDragSource"); } }
private DockPane PaneAtPointNativeFloatingWindows(IDragSource source, double deltaX, double deltaY, out bool stopHitTest) { stopHitTest = false; FloatingWindowCollection floatingWindows = DockControl.FloatingWindows; Point pt = GetStartMousePosition(_overlayWindow); pt.Offset(deltaX, deltaY); for (int i = floatingWindows.Count - 1; i >= 0; i--) { FloatingWindow floatingWindow = floatingWindows[i]; if (!floatingWindow.IsVisible) { continue; } NativeFloatingWindow nativeWindow = NativeFloatingWindow.GetNativeFloatingWindow(floatingWindow); Rect windowBounds = nativeWindow.GetPreviewBounds(_overlayWindow); stopHitTest = windowBounds.Contains(pt); if (stopHitTest) { pt = GetStartMousePosition(nativeWindow); pt.Offset(deltaX, deltaY); var result = PaneFromHitTestResult(source, VisualTreeHelper.HitTest(nativeWindow, pt)); if (result == null || !source.CanDrop(result)) { stopHitTest = false; continue; } return(result); } } return(null); }
public virtual void Drop(List <object> node, DropPosition mode, bool copy) { bool isRunningCompositeTask = Services.TaskService.IsRunningCompositeTask; if (!isRunningCompositeTask) { Services.TaskService.BeginCompositeTask("Drag drop GameObject"); } foreach (object current in node) { if (!copy) { IDragSource dragSource = current as IDragSource; if (dragSource != null) { dragSource.Detach(); } } NodeObject nodeObject = current as NodeObject; if (nodeObject != null) { this.LoadDropObject(nodeObject, mode); } } if (!isRunningCompositeTask) { Services.TaskService.EndCompositeTask(); } }
/// <summary> /// Starts a drag. /// It creates a bitmap of the view being dragged. That bitmap is what you see moving. /// The actual view can be repositioned if that is what the onDrop handle chooses to do. /// </summary> /// <param name="v"> The view that is being dragged </param> /// <param name="source"> An object representing where the drag originated </param> /// <param name="dragInfo"> The data associated with the object that is being dragged </param> /// <param name="dragAction"> The drag action: either <seealso cref="#DRAG_ACTION_MOVE"/> or /// <seealso cref="#DRAG_ACTION_COPY"/> </param> public void StartDrag(View v, IDragSource source, object dragInfo, int dragAction) { // Start dragging, but only if the source has something to drag. bool doDrag = source.AllowDrag(); if (!doDrag) { return; } mOriginator = v; Bitmap b = GetViewBitmap(v); if (b == null) { // out of memory? return; } int[] loc = mCoordinatesTemp; v.GetLocationOnScreen(loc); int screenX = loc[0]; int screenY = loc[1]; StartDrag(b, screenX, screenY, 0, 0, b.Width, b.Height, source, dragInfo, dragAction); b.Recycle(); if (dragAction == DRAG_ACTION_MOVE) { v.Visibility = ViewStates.Gone; } }
public void Drop(IDragSource node, DropPosition mode, bool copy) { var cvm = node as NodeViewModel; if (copy) { cvm = new NodeViewModel(cvm.Node, cvm.Parent); } switch (mode) { case DropPosition.Add: this.Children.Add(cvm); cvm.Parent = this; this.IsExpanded = true; break; case DropPosition.InsertBefore: int index = this.Parent.Children.IndexOf(this); Parent.Children.Insert(index, cvm); cvm.Parent = this.Parent; break; case DropPosition.InsertAfter: int index2 = this.Parent.Children.IndexOf(this); Parent.Children.Insert(index2 + 1, cvm); cvm.Parent = this.Parent; break; } }
static void DragSource_PreviewMouseMove(object sender, MouseEventArgs e) { if (m_DragInfo != null) { Point dragStart = m_DragInfo.DragStartPosition; Point position = e.GetPosition(null); if (Math.Abs(position.X - dragStart.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(position.Y - dragStart.Y) > SystemParameters.MinimumVerticalDragDistance) { IDragSource dragHandler = GetDragHandler(m_DragInfo.VisualSource); if (dragHandler != null) { dragHandler.StartDrag(m_DragInfo); } else { DefaultDragHandler.StartDrag(m_DragInfo); } if (m_DragInfo.Effects != DragDropEffects.None && m_DragInfo.Data != null) { DataObject data = new DataObject(m_Format.Name, m_DragInfo.Data); System.Windows.DragDrop.DoDragDrop(m_DragInfo.VisualSource, data, m_DragInfo.Effects); m_DragInfo = null; } } } }
public void Drop(IDragSource dragSource, UIElement draggedElement) { dragSource.CompleteDrag(); Actions.InsertColumn(panel, column); Actions.AddNewCell(panel, column, row, draggedElement); dragSource.AfterDropComplete(); Actions.InvalidateLayout(panel); }
protected override bool OnDragOver(DragEventArgs args) { if (this.dragSource == null) { this.dragSource = Enumerable.First <IDragSource>(DragSourceHelper.DataOfType <IDragSource>(args.Data)); this.dragSource.GiveFeedback += new GiveFeedbackEventHandler(this.DragSourceGiveFeedback); } this.dragCursor = (Cursor)null; args.Effects = DragDropEffects.None; DataBindingDragDropModel dragFeedback = this.GetDragFeedback(args); if (dragFeedback == null || !dragFeedback.CheckDropFlags(DataBindingDragDropFlags.SetBinding | DataBindingDragDropFlags.CreateElement, false)) { this.previewHighlighter.Option = HighlightOption.Default; this.previewHighlighter.InsertionPointPreview = (ISceneInsertionPoint)null; this.FeedbackAdorner.Text = string.Empty; this.FeedbackAdorner.CloseAdorner(); base.OnDragOver(args); return(true); } if (dragFeedback.CheckDropFlags(DataBindingDragDropFlags.CreateElement)) { if (!((SceneElement)dragFeedback.TargetNode).IsEffectiveRoot) { this.previewHighlighter.Option = HighlightOption.Insert; this.previewHighlighter.InsertionPointPreview = (ISceneInsertionPoint)dragFeedback.InsertionPoint; } else { this.previewHighlighter.Option = HighlightOption.Default; this.previewHighlighter.InsertionPointPreview = (ISceneInsertionPoint)null; } args.Effects = DragDropEffects.Copy; this.dragCursor = DataBindingModeModel.Instance.NormalizedMode != DataBindingMode.Details ? ToolCursors.DataBindingMasterAddCursor : ToolCursors.DataBindingDetailsAddCursor; } else { this.previewHighlighter.Option = HighlightOption.Preview; this.previewHighlighter.InsertionPointPreview = (ISceneInsertionPoint)dragFeedback.InsertionPoint; args.Effects = DragDropEffects.Move; this.dragCursor = DataBindingModeModel.Instance.NormalizedMode != DataBindingMode.Details ? ToolCursors.DataBindingMasterCursor : ToolCursors.DataBindingDetailsCursor; } if (DataBindingModeModel.Instance.NormalizedMode == DataBindingMode.Details) { this.FeedbackAdorner.Background = this.detailsBackground; } else { this.FeedbackAdorner.Background = this.masterBackground; } this.FeedbackAdorner.Text = dragFeedback.Tooltip; this.SetTextCuePosition(args.GetPosition((IInputElement)this.ActiveView.Artboard.ContentArea)); this.FeedbackAdorner.DrawAdorner(this.OpenFeedback()); this.CloseFeedback(); DataBindingToolBehavior.PokeWpfToRefresh(); base.OnDragOver(args); return(true); }
public void RegisterDragSource(IDragSource dragSource) { if (DragSources.Contains(dragSource)) { throw new Exception("Элемент уже был зарегистрирован ранее"); } DragSources.Add(dragSource); RegisterDragCaptureZoneEvents(dragSource); }
private void OnDrag(IDragSource dragSource, FrameworkElement displayDragSource, Point position, MouseEventArgs mouseEventArgs) { if (Drag == null) { return; } Drag(this, new DragEventArgs(dragSource, displayDragSource, position, mouseEventArgs)); }
public void RemoveDragSource(IDragSource dragSource) { if (!DragSources.Contains(dragSource)) { throw new Exception("Элемент не найден"); } DragSources.Remove(dragSource); UnregisterDragCaptureZoneEvents(dragSource); }
/// <summary> /// Callback for the MouseDown event. /// </summary> /// <param name="e">The event.</param> protected void OnMouseDown(MouseDownEvent e) { if (m_Active) { e.StopImmediatePropagation(); return; } m_Active = false; m_Dragging = false; m_AddedByMouseDown = false; if (target == null) { return; } m_SelectionContainer = target.GetFirstAncestorOfType <IDragSource>(); if (m_SelectionContainer == null) { // Keep for potential later use in OnMouseUp (where e.target might be different then) m_SelectionContainer = target.GetFirstOfType <IDragSource>(); m_SelectedElement = e.target as GraphElement; return; } m_SelectedElement = target.GetFirstOfType <GraphElement>(); if (m_SelectedElement == null) { return; } // Since we didn't drag after all, update selection with current element only if (!m_SelectedElement.IsSelected()) { var selectionMode = e.actionKey ? SelectElementsCommand.SelectionMode.Add : SelectElementsCommand.SelectionMode.Replace; m_SelectedElement.CommandDispatcher.Dispatch(new SelectElementsCommand(selectionMode, m_SelectedElement.Model)); m_AddedByMouseDown = true; } if (e.button == (int)m_ActivateButton) { // avoid starting a manipulation on a non movable object if (!m_SelectedElement.Model.IsDroppable()) { return; } m_MouseDownPosition = e.localMousePosition; m_Active = true; target.CaptureMouse(); e.StopPropagation(); } }
private void OnDrop(IDragSource dragSource, IDropTarget dropTarget, FrameworkElement displayDragSource, Point position, MouseEventArgs mouseEventArgs) { if (Drop == null) { return; } Drop(this, new DropEventArgs(dragSource, dropTarget, displayDragSource, position, mouseEventArgs)); }
public AdornerContent(UIElement adornedElement, IDragSource content, DataTemplate template) : base(adornedElement) { visuals = new List <UIElement>(); contentPresenter = new ContentPresenter { Content = content, ContentTemplate = template }; visuals.Add(contentPresenter); this.IsHitTestVisible = false; }
public void SetCurrentDragSource(IDragSource dragSource, string dragGroupName) { ClearDrag(); dragSource.DragGroupName = dragGroupName; _mainDragSource = dragSource; _currentDragSources.Add(dragSource); FrameworkElement instanse = dragSource.Instanse; _currentDragSourceMouseDownPosition = new Point(instanse.ActualWidth / 2, instanse.ActualHeight / 2); }
static void DragSource_PreviewMouseMove(object sender, MouseEventArgs e) { if (m_DragInfo != null && !m_DragInProgress) { Point dragStart = m_DragInfo.DragStartPosition; Point position = e.GetPosition(null); if (Math.Abs(position.X - dragStart.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(position.Y - dragStart.Y) > SystemParameters.MinimumVerticalDragDistance) { IDragSource dragHandler = GetDragHandler(m_DragInfo.VisualSource); if (dragHandler != null) { dragHandler.StartDrag(m_DragInfo); } else { DefaultDragHandler.StartDrag(m_DragInfo); } if (m_DragInfo.Effects != DragDropEffects.None && m_DragInfo.Data != null) { DataObject data = new DataObject(DataFormat.Name, m_DragInfo.Data); // Auch noch die Daten für den File-DragDrop einbauen StringCollection files = new StringCollection(); if (m_DragInfo.Data is Track) { files.Add(((Track)m_DragInfo.Data).Soundfile); } if (files.Count > 0 && !string.IsNullOrEmpty(files[0])) { data.SetFileDropList(files); m_DragInfo.Effects = DragDropEffects.Copy; } try { m_DragInProgress = true; System.Windows.DragDrop.DoDragDrop(m_DragInfo.VisualSource, data, m_DragInfo.Effects); } finally { m_DragInProgress = false; } m_DragInfo = null; } } } }
public static void BeginDrag(IDragSource source, Vector3 screenPos) { instance.source = source; instance.dragIcon.sprite = source.icon; Vector2 pos; RectTransformUtility.ScreenPointToLocalPointInRectangle(instance.rect, screenPos, null, out pos); instance.dragIcon.rectTransform.anchoredPosition = pos; instance.dragIcon.gameObject.SetActive(true); }
private int GetOldIndex(IDragSource dragSource, UIElement draggedElement) { var sourcePanel = dragSource as StackPanelControl; int oldIndex = -1; if (sourcePanel != null && sourcePanel.Panel == panel) { oldIndex = sourcePanel.Panel.Children.IndexOf(draggedElement); } return(oldIndex); }
protected override void OnDragEnter(IDragSource source) { if (isUsed) { return; } if (source is GPDragSource && (source as GPDragSource).sourceType == targetType) { preView.SetActive(true); } }
void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData) { IDragSource source = DragDropManager.GetCurrentSource(); if (source != null) { DragDropManager.SetTarget(this); isDragEntered = true; OnDragEnter(source); } }
private void OnDragSourceCaptureZoneMouseDown(object sender, MouseEventArgs e) { if (_mainDragSource != null) { return; } _mainDragSource = GetParentDragSource((DependencyObject)sender); _mainDragSource = FindParentSelectedDragSource(_mainDragSource) ?? _mainDragSource; _globalMouseDownPosition = e.GetPosition(_rootDropArea); _currentDragSourceMouseDownPosition = e.GetPosition(_mainDragSource.Instanse); }
public void OnDragOver(IDragSource source, int x, int y, int xOffset, int yOffset, DragView dragView, object dragInfo) { View v = (View)dragInfo; int w = v.Width; int h = v.Height; int left = x - xOffset; int top = y - yOffset; DragLayer.LayoutParams lp = new DragLayer.LayoutParams(w, h, left, top); this.UpdateViewLayout(v, lp); }
private static void DropTarget_PreviewDrop(object sender, DragEventArgs e) { var dropInfo = new DropInfo(sender, e, _dragInfo); IDropTarget dropHandler = GetDropHandler((UIElement)sender) ?? DefaultDropHandler; IDragSource dragHandler = GetDragHandler((UIElement)sender) ?? DefaultDragHandler; DragAdorner = null; DropTargetAdorner = null; dropHandler.Drop(dropInfo); dragHandler.Dropped(dropInfo); e.Handled = true; }
private DragEventArgs OnBeforeDrag(IDragSource dragSource, FrameworkElement displayDragSource, Point position, MouseEventArgs mouseEventArgs) { if (BeforeDrag == null) { return(null); } var args = new DragEventArgs(dragSource, displayDragSource, position, mouseEventArgs); BeforeDrag(this, args); return(args); }
public override void OnDragDrop(IDragSource source) { if (source is GPDragSource && (source as GPDragSource).sourceType == index.ToString()) { index++; animator.SetInteger("Action", index); Lenin.TryPlayMessage("GoodQueue"); } else { Lenin.TryPlayMessage("WrongQueue"); } }
/// <summary> /// Gets the drag handler from the drag info or from the sender, if the drag info is null /// </summary> /// <param name="dragInfo">the drag info object</param> /// <param name="sender">the sender from an event, e.g. mouse down, mouse move</param> /// <returns></returns> private static IDragSource TryGetDragHandler(DragInfo dragInfo, UIElement sender) { IDragSource dragHandler = null; if (dragInfo != null && dragInfo.VisualSource != null) { dragHandler = GetDragHandler(dragInfo.VisualSource); } if (dragHandler == null && sender != null) { dragHandler = GetDragHandler(sender); } return(dragHandler ?? DefaultDragHandler); }
private void ClearDrag() { _mainDragSource = null; _currentDragSources.Clear(); if (HasCurrentDisplayDragSources) { foreach (var item in _currentDisplayDragSources) { _rootDropArea.Children.Remove(item); } _currentDisplayDragSources.Clear(); } CursorManager.ClearGlobalCursor(); }
public bool CanDrop(IDragSource node, DropPosition mode, DragDropEffect effect) { var cvm2 = this; while (cvm2 != null) { if (cvm2 == node) { return(false); } cvm2 = cvm2.Parent; } return(node is NodeViewModel && (mode == DropPosition.Add || this.Parent != null)); }
public void Drop(IDragSource node, DropPosition mode, bool copy) { var cvm = node as NodeViewModel; if (copy) cvm = new NodeViewModel(cvm.Node, cvm.Parent); switch (mode) { case DropPosition.Add: this.Children.Add(cvm); cvm.Parent = this; this.IsExpanded = true; break; case DropPosition.InsertBefore: int index = this.Parent.Children.IndexOf(this); Parent.Children.Insert(index, cvm); cvm.Parent = this.Parent; break; case DropPosition.InsertAfter: int index2 = this.Parent.Children.IndexOf(this); Parent.Children.Insert(index2 + 1, cvm); cvm.Parent = this.Parent; break; } }
public bool CanDrop(IDragSource node, DropPosition mode, DragDropEffect effect) { return node is NodeViewModel && (mode == DropPosition.Add || this.Parent != null); }
public static void SetDragHandler(UIElement target, IDragSource value) { target.SetValue(DragHandlerProperty, value); }
/// <summary> /// Sets the DragSource property. /// </summary> /// <param name = "dependencyObject">The dependency object.</param> /// <param name = "value">The value.</param> public static void SetDragSource(DependencyObject dependencyObject, IDragSource value) { dependencyObject.SetValue(DragSourceProperty, value); }