Ejemplo n.º 1
0
        /// <summary>
        /// Handles the Drag event which raises a DoDragDrop event used by the
        /// DesignSurface to drag items from the Toolbox to the DesignSurface.
        /// If the currently selected item is the pointer item then the drag drop
        /// operation is not started.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnItemDrag(object sender, ItemDragEventArgs e)
        {
            if (e.Button == MouseButtons.Left &&
                e.Item.GetType() == typeof(ListViewItem))
            {
                ToolboxItem lItem = (e.Item as ListViewItem).Tag as ToolboxItem;

                if (lItem.TypeName != NameConsts.Pointer)
                {
                    mIsDragging = true;

                    IToolboxService lToolboxService = mToolboxService as IToolboxService;
                    object          lDataObject     = lToolboxService.SerializeToolboxItem(lItem);
                    DrawingTool     lTool           = lItem.CreateComponents().FirstOrDefault() as DrawingTool;

                    lTool.CreatePersistence();
                    Rectangle lRect = lTool.SurroundingRect;

                    using (DragImage image = new DragImage(lTool.DefaultImage, lRect.Width / 2, lRect.Height / 2))
                    {
                        DoDragDrop(lDataObject, DragDropEffects.All);
                    }

                    mIsDragging = false;
                }
            }
        }
Ejemplo n.º 2
0
    private Sprite GetSprite(PointerEventData eventData)
    {
        GameObject goSource = eventData.pointerDrag;

        if (goSource == null)
        {
            return(null);
        }

        Image imgSource = eventData.pointerDrag.GetComponent <Image>();

        if (imgSource == null)
        {
            return(null);
        }

        DragImage DragSource = imgSource.GetComponent <DragImage>();

        if (DragSource == null)
        {
            return(null);
        }

        return(imgSource.sprite);
    }
 void ReleaseDesignerOutlets()
 {
     if (DoubleTouchImage != null)
     {
         DoubleTouchImage.Dispose();
         DoubleTouchImage = null;
     }
     if (DragImage != null)
     {
         DragImage.Dispose();
         DragImage = null;
     }
     if (TouchImage != null)
     {
         TouchImage.Dispose();
         TouchImage = null;
     }
     if (TouchStatus != null)
     {
         TouchStatus.Dispose();
         TouchStatus = null;
     }
     if (TouchView != null)
     {
         TouchView.Dispose();
         TouchView = null;
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 新增一个可拖拽图片
        /// </summary>
        /// <param name="size">图片大小</param>
        /// <param name="point">图片位置</param>
        /// <param name="source">图片目录</param>
        /// <param name="background"></param>
        /// <param name="borderBrush"></param>
        /// <param name="zIndex">顺序</param>
        /// <returns></returns>
        public DragImage AddDragImage(string name, Size size, Point point, ImageSource source, Brush background, Brush borderBrush, int zIndex)
        {
            int       childCount = this.Children.Count;
            DragImage tb         = new DragImage()
            {
                CtrlName     = string.IsNullOrEmpty(name) ? Guid.NewGuid().ToString("N"): name,
                Background   = background,
                BorderBrush  = borderBrush,
                Name         = "DragImage" + childCount.ToString(),
                Width        = size.Width,
                Height       = size.Height,
                Position     = point,
                ZIndex       = zIndex,
                BelongCanvas = this,            //设置为当前Canvas
                IsReadOnly   = this.IsReadOnly, //只读
                Source       = source,
            };

            tb.DragDelta     += DragDelta;
            tb.DragStarted   += DragStarted;
            tb.DragCompleted += DragCompleted;

            bSaved = false;
            DragThumbs.Add(tb);
            this.Children.Add(tb);        //添加到界面上
            Canvas.SetZIndex(tb, zIndex); //设置界面ZIndex属性

            tb.IsSelected = !IsReadOnly;
            return(tb);
        }
Ejemplo n.º 5
0
 private void CommandBox_DragDrop(object sender, DragEventArgs e)
 {
     DragImage.DragLeave((Control)sender);
     foreach (string NextFileName in e.Data.GetFileDrop())
     {
         _CommandBox.Text += PathHelper.EnquoteString(NextFileName) + ' ';
     }
 }
Ejemplo n.º 6
0
 private void OutputBox_DragOver(object sender, DragEventArgs e)
 {
     DragImage.DragOver((Control)sender, e);
     if (!Idling)
     {
         e.Effect = DragDropEffects.None;
     }
 }
Ejemplo n.º 7
0
        public HoldCardInteraction(DragImage draggedImage, ItemsControl context, ScrollViewer scrollViewer)
        {
            _draggedImage = draggedImage;
            _context      = context;
            _scrollViewer = scrollViewer;

            IsEnabled = true;
        }
Ejemplo n.º 8
0
        private void OutputBox_DragDrop(object sender, DragEventArgs e)
        {
            DragImage.DragLeave((Control)sender);
            string FileName = e.Data.GetFileName();

            if (!string.IsNullOrEmpty(FileName) && Idling)
            {
                InsertToInputBuffer(FileName);
            }
        }
Ejemplo n.º 9
0
 public override void OnMouseDown(MouseButtons button, int x, int y)
 {
     if (button == MouseButtons.Left)
     {
         for (int i = 0; i < _drawnPointers.Count; ++i)
         {
             var rc = _drawnPointers[i].Bounds;
             if (rc.X <= x && rc.Right > x)
             {
                 var branch = _drawnPointers[i].RevisionPointer as Branch;
                 if (branch != null && !branch.IsRemote)
                 {
                     int dx = _drawnPointers[i].Bounds.X - x - 1;
                     int w  = 0;
                     using (var bmp = new Bitmap(1, 1))
                         using (var gx = Graphics.FromImage(bmp))
                         {
                             w = GlobalBehavior.GraphStyle.MeasureBranch(
                                 gx, ListBox.Font, GitterApplication.TextRenderer.LeftAlign, branch);
                         }
                     using (var dragImage = new DragImage(new Size(w, 21), -dx, y,
                                                          eargs => DrawBranchDragImage(branch, eargs.Graphics)))
                     {
                         dragImage.ShowDragVisual(ListBox);
                         ListBox.DoDragDrop(branch, DragDropEffects.None | DragDropEffects.Scroll | DragDropEffects.Move);
                     }
                     return;
                 }
                 else
                 {
                     var tag = _drawnPointers[i].RevisionPointer as Tag;
                     if (tag != null && tag.TagType == TagType.Annotated)
                     {
                         //var message = tag.Message;
                         //if(!string.IsNullOrEmpty(message))
                         //{
                         //    var tt = new ToolTip()
                         //    {
                         //        AutomaticDelay = 0,
                         //        AutoPopDelay = 0,
                         //        IsBalloon = false,
                         //        UseAnimation = false,
                         //        UseFading = false,
                         //        InitialDelay = 0,
                         //        StripAmpersands = false,
                         //    };
                         //    tt.Show(message, ListBox);
                         //}
                     }
                 }
             }
         }
     }
     base.OnMouseDown(button, x, y);
 }
        private void WireUpDragGestureRecognizer()
        {
            // Create a new tap gesture
            UIPanGestureRecognizer gesture = new UIPanGestureRecognizer();

            // Wire up the event handler (have to use a selector)
            gesture.AddTarget(() => HandleDrag(gesture));

            // Add the gesture recognizer to the view
            DragImage.AddGestureRecognizer(gesture);
        }
Ejemplo n.º 11
0
 private async void DragImage_PointerMoved(object sender, PointerRoutedEventArgs e)
 {
     if (_dragPointerId == e.Pointer.PointerId)
     {
         var pt = e.GetCurrentPoint(this).Position;
         if (Math.Abs(pt.X - _lastPressedPosition.X) >= 5 || Math.Abs(pt.Y - _lastPressedPosition.Y) >= 5)
         {
             _dragPointerId = 0;
             await DragImage.StartDragAsync(e.GetCurrentPoint(DragImage));
         }
     }
 }
Ejemplo n.º 12
0
 private void CommandBox_DragEnter(object sender, DragEventArgs e)
 {
     DragImage.DragEnter((Control)sender, e);
     if (((e.AllowedEffect & (DragDropEffects.Copy | DragDropEffects.Link)) > 0) && e.Data.HasFileDrop())
     {
         e.Effect = DragDropEffects.Copy;
     }
     else
     {
         e.Effect = DragDropEffects.None;
     }
 }
Ejemplo n.º 13
0
        private void StopDrag()
        {
            DragImage.Dispose();
            StaticToolsImage.Dispose();
            Dragging = false;
            var point = new Point((MapControl.ClientSize.Width / 2 + (DragStartPoint.X - DragEndPoint.X)),
                                  (MapControl.ClientSize.Height / 2 + (DragStartPoint.Y - DragEndPoint.Y)));

            Map.Center = Map.ImageToWorld(point);

            MapControl.Cursor = Cursors.Default;
            MapControl.Refresh();
        }
Ejemplo n.º 14
0
        private void AssociatedObject_GiveFeedback(object sender, GiveFeedbackEventArgs e)
        {
            if (!IsDropPreviewEnabled)
            {
                return;
            }

            if (_cursorWindow == null)
            {
                if (e.Source is FrameworkElement element && element != null)
                {
                    var rtb            = WPFHelper.GetRenderTargetBitmap(element);
                    var shadowAreaSize = (double)AssociatedObject.FindResource("DragWindowShadowAreaSize");
                    _cursorWindow = new DragImage()
                    {
                        Title  = $"{AppSettings.AppTitle} cursor",
                        Width  = rtb.Width + shadowAreaSize * 2d,
                        Height = rtb.Height + shadowAreaSize * 2d
                    };
                    _cursorWindowXHotSpot        = -shadowAreaSize / 2d + 2d; // TODO: 2d gap could depends on system cursor size
                    _cursorWindowYHotSpot        = -shadowAreaSize / 2d + 2d;
                    _cursorWindow.IMG.Source     = rtb;
                    _cursorWindow.BackImg.Source = WPFHelper.GetImageMask(rtb);
                }
            }

            var p = new NativeTypes.POINT();

            GetCursorPos(ref p);

            if (_cursorWindow != null)
            {
                var x = p.X - _cursorWindow.ActualWidth - _cursorWindowXHotSpot;
                var y = p.Y - _cursorWindow.ActualHeight - _cursorWindowYHotSpot;

                _cursorWindow.SetPos(x, y, (IntPtr)SpecialWindowHandles.HWND_TOP);

                if (!_cursorWindow.IsVisible)
                {
                    _cursorWindow.Show();
                }
            }

            if (CanDropOnDesktop && CheckIsOverDesktop(p.X, p.Y))
            {
                e.UseDefaultCursors = false;
                Mouse.SetCursor(Cursors.Hand);
                e.Handled = true;
            }
        }
        public DragReOrderInteraction(DragImage dragImage)
        {
            _dragImage = dragImage;

              // a timer which is used to periodically detect the position of the
              // item being dragged in order to allow auto-scroll behaviour
              _autoScrollTimer = new DispatcherTimer();
              _autoScrollTimer.Interval = TimeSpan.FromMilliseconds(50);
              _autoScrollTimer.Tick += (s, e) =>
              {
            AutoScrollList();
            ShuffleItemsOnDrag();
              };

              _moveSound = SoundEffect.FromStream(TitleContainer.OpenStream("Sounds/Windows XP Menu Command.wav"));
        }
Ejemplo n.º 16
0
        private static void PopoutCard(UIElement element, DragImage image, Point relativePosition)
        {
            // Copy the selected card into a bitmap for use as the movement target
            var bitmap = new WriteableBitmap(element, null);

            image.Image.Source = bitmap;
            image.Visibility   = Visibility.Visible;
            image.Opacity      = 1.0;

            // this needs to be relative to the scrolled position
            image.SetVerticalOffset(relativePosition.Y);
            //image.SetHorizontalOffset(relativePosition.X);

            // hide the underlying item
            element.Opacity = 0.0;
        }
Ejemplo n.º 17
0
        public DragReOrderInteraction(DragImage dragImage)
        {
            _dragImage = dragImage;

            // a timer which is used to periodically detect the position of the
            // item being dragged in order to allow auto-scroll behaviour
            _autoScrollTimer          = new DispatcherTimer();
            _autoScrollTimer.Interval = TimeSpan.FromMilliseconds(50);
            _autoScrollTimer.Tick    += (s, e) =>
            {
                AutoScrollList();
                ShuffleItemsOnDrag();
            };

            //_moveSound = SoundEffect.FromStream(TitleContainer.OpenStream("Sounds/Windows XP Menu Command.wav"));
        }
Ejemplo n.º 18
0
        public override void OnMouseUp(ICoordinate worldPosition, MouseEventArgs e)
        {
            if (!Dragging)
            {
                return;
            }
            DragImage.Dispose();
            StaticToolsImage.Dispose();
            Dragging = false;
            Point point = new Point((MapControl.ClientSize.Width / 2 + (DragStartPoint.X - DragEndPoint.X)),
                                    (MapControl.ClientSize.Height / 2 + (DragStartPoint.Y - DragEndPoint.Y)));

            Map.Center = Map.ImageToWorld(point);

            MapControl.Cursor = Cursors.Default;
            MapControl.Refresh();
        }
Ejemplo n.º 19
0
        public DragVerticalInteraction(DragImage dragImage, ItemsControl itemsControl, ScrollViewer scrollViewer,
                                       IEventAggregator eventAggregator)
        {
            _dragImage       = dragImage;
            _itemsControl    = itemsControl;
            _eventAggregator = eventAggregator;
            _scrollViewer    = scrollViewer;
            _cardsModel      = (BindableCollection <CardViewModel>)itemsControl.ItemsSource;

            // This indexes the cards and their positions in the list
            // so that we can more readily determine how to visually reorganize
            _pointIndex = new PointIndex();

            // setup the timer that solves movement and card relations
            _dispatcherTimer = new DispatcherTimer {
                Interval = TimeSpan.FromMilliseconds(50)
            };
            _dispatcherTimer.Tick += (sender, args) =>
            {
                AutoScrollLayout();
                ReorganizeLayout();
            };
        }
Ejemplo n.º 20
0
    // Start is called before the first frame update
    void Start()
    {
        image = this.gameObject.GetComponentInParent <DragImage>();

        // image.SetNum(0);
    }
Ejemplo n.º 21
0
 void DestroyCursorWindow()
 {
     _cursorWindow?.Close();
     _cursorWindow = null;
 }
Ejemplo n.º 22
0
 private void CommandBox_DragOver(object sender, DragEventArgs e)
 {
     DragImage.DragOver((Control)sender, e);
 }
Ejemplo n.º 23
0
 private void CommandBox_DragLeave(object sender, EventArgs e)
 {
     DragImage.DragLeave((Control)sender);
 }