Example #1
0
        /// <summary>
        /// Creates a new <see cref="DDFeedback"/> object displaying a
        /// <see cref="System.Windows.Media.Visual"/> in its current state.
        /// </summary>
        /// <param name="visual">The visual object to take a snapshot of</param>
        /// <param name="size">The size to use for the displayed feedback</param>
        /// <returns>A new <see cref="DDFeedback"/> object displaying a snapshot of a
        /// <see cref="System.Windows.Media.Visual"/></returns>
        public static DDFeedback CreateFromVisual(Visual visual, Size size)
        {
            var rv = new DDFeedback();

            var rtb = new RenderTargetBitmap((int)size.Width, (int)size.Height, 96, 96, PixelFormats.Pbgra32);

            var dv = new DrawingVisual();

            using (DrawingContext dc = dv.RenderOpen())
            {
                var brush = new VisualBrush(visual);
                dc.DrawRectangle(brush, null, new Rect(new Point(), size));
            }

            rtb.Render(dv);

            var toolTip = rv._toolTip;

            toolTip.Padding = new Thickness(0);
            toolTip.Content = new Image {
                Source = rtb
            };

            return(rv);
        }
Example #2
0
        private void UIElementGiveFeedback(object sender, GiveFeedbackEventArgs e)
        {
            var oldFeedback = _feedbackObject;

            //Get any UI feedback from the processor if necessary.
            if (CacheFeedback == false || _feedbackObject == null)
            {
                _feedbackObject = _processor.GetDragDropFeedback(e, _dragDropObject);
            }
            if (_feedbackObject != null)
            {
                //If the feedback has changed we want to hide the old one
                if (oldFeedback != null && ReferenceEquals(oldFeedback, _feedbackObject) == false)
                {
                    oldFeedback.HideFeedback();
                }

                var currentLoc = MouseUtil.CurrentMousePoint();
                _feedbackObject.ShowFeedback(currentLoc);

                //If we want to hide the default cursors, mark this event as handled
                if (_feedbackObject.ShowDefaultCursors == false)
                {
                    e.Handled = true;
                }
            }
        }
Example #3
0
        private void UIElementMouseMove(object sender, MouseEventArgs e)
        {
            if (_doDragDrop)
            {
                //If the mouse has previously been pressed, determine if the mouse has moved far enough to start a drag drop operation
                var inputElement = sender as IInputElement;
                if (inputElement == null)
                {
                    return;
                }

                var location = e.GetPosition(inputElement);

                //Calculate the distance the mouse has moved since it was originally pressed
                var yDelta = Math.Abs(location.Y - _mouseDownPoint.Y);
                var xDelta = Math.Abs(location.X - _mouseDownPoint.X);

                if (xDelta < MinimumHorizontalDragDistance && yDelta < MinimumVerticalDragDistance)
                {
                    return;
                }

                //The distance dragged is far enough, invoke the processor to see if we should start the drag drop operation
                _doDragDrop     = false;
                _dragDropObject = _processor.GetDragDropObject(sender, e);
                var dependancyObject = sender as DependencyObject;
                if (_dragDropObject != null && dependancyObject != null)
                {
                    //Raise the appropriate events and start the drag drop operation
                    var @event = DDStarted;
                    if (@event != null)
                    {
                        @event(this, EventArgs.Empty);
                    }

                    DragDrop.DoDragDrop(dependancyObject, _dragDropObject, DragDropEffects); //this call blocks execution

                    @event = DDEnded;
                    if (@event != null)
                    {
                        @event(this, EventArgs.Empty);
                    }

                    _dragDropObject = null;
                    //Cleanup any UI feedback that was presented
                    if (_feedbackObject != null)
                    {
                        _feedbackObject.HideFeedback();
                        _feedbackObject = null;
                    }
                }
            }
        }
Example #4
0
        /// <summary>
        /// Creates a new <see cref="DDFeedback"/> object with the specified text
        /// and optional foreground and background colors
        /// </summary>
        /// <param name="text">The text to display</param>
        /// <param name="background">The background color</param>
        /// <param name="forground">The foreground color</param>
        /// <returns>A new <see cref="DDFeedback"/> object displaying text</returns>
        public static DDFeedback CreateFromText(string text, Color?background = null, Color?forground = null)
        {
            var rv      = new DDFeedback();
            var toolTip = rv._toolTip;

            toolTip.Content = text;
            if (background != null)
            {
                toolTip.Background = new SolidColorBrush(background.Value);
            }
            if (forground != null)
            {
                toolTip.Foreground = new SolidColorBrush(forground.Value);
            }
            return(rv);
        }