Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ConnectorPoint"/> class.
        /// </summary>
        /// <param name="exolutioCanvas">Canvas where the point is created.</param>
        public ConnectorPoint(ExolutioCanvas exolutioCanvas)
        {
            Width     = 0;
            Height    = 0;
            dragThumb = new DragThumb(exolutioCanvas, this);
            dragThumb.PositionChanged         += InvokePositionChanged;
            dragThumb.FellowTravellersUpdated += AlignFellowTravellers;
            OrderInConnector = -1;
            Background       = ViewToolkitResources.GoldBrush;

            Cursor = Cursors.Hand;

            this.SetValue(TemplateProperty, null);

#if SILVERLIGHT
            this.Width   = 10;
            this.Height  = 10;
            this.Content = new Ellipse()
            {
                Fill = Background
            };
            this.RenderTransform = new TranslateTransform()
            {
                X = -5, Y = -5
            };
#endif
#if SILVERLIGHT
#else
            this.PreviewMouseDown += ConnectorPoint_PreviewMouseDown;
#endif
        }
Example #2
0
 internal void AddedToCanvas()
 {
     this.UpdateCanvasPosition(true);
     if (Draggable)
     {
         this.dragThumb             = new DragThumb(ExolutioCanvas, this);
         dragThumb.Placement        = EPlacementKind.AbsoluteCanvas;
         dragThumb.PositionChanged += InvokePositionChanged;
     }
 }
 /// <summary>
 /// Updates positiosn of <see cref="FellowTravellers"/>
 /// </summary>
 public void FellowTravellersUpdate()
 {
     if (FellowTravellers != null)
     {
         foreach (DragThumb element in FellowTravellers)
         {
             DragThumb.UpdatePos(element);
         }
     }
 }
Example #4
0
        void AlignFellowTravellers()
        {
            if (NodesInBadPosition())
            {
                ParentControl.GetBounds().AlignLabelsToPoint(this.Position, FellowTravellers.OfType <DragThumb>().Select(t => t.DraggedControl).OfType <Node>());

                foreach (DragThumb fellowTraveller in FellowTravellers)
                {
                    DragThumb.UpdatePos(fellowTraveller);
                }
            }
        }
Example #5
0
        /// <summary>
        /// Updates the x and y coordinates of an element
        /// </summary>
        /// <param name="element">The element whose position is updated</param>
        internal static void UpdatePos(ISnappable element)
        {
            DragThumb thumb = (DragThumb)element;
            double    _x    = Canvas.GetLeft(thumb.DraggedControl);
            double    _y    = Canvas.GetTop(thumb.DraggedControl);

            double placementModifierX = 0;
            double placementModifierY = 0;

            if (thumb.PlacementCenter == EPlacementCenter.Center)
            {
                placementModifierX = -thumb.DraggedControl.ActualWidth / 2;
                placementModifierY = -thumb.DraggedControl.ActualHeight / 2;
            }

            Point idealPosition = new Point();

            switch (thumb.Placement)
            {
            case EPlacementKind.AbsoluteCanvas:
            case EPlacementKind.ParentAutoPos:
            case EPlacementKind.AbsoluteSubCanvas:
                idealPosition.X = thumb.X + placementModifierX;
                idealPosition.Y = thumb.Y + placementModifierY;
                break;

            case EPlacementKind.RelativeCanvas:
                if (thumb.ReferentialElement != null)
                {
                    idealPosition.X = thumb.X + thumb.ReferentialElement.CanvasPosition.X + placementModifierX;
                    idealPosition.Y = thumb.Y + thumb.ReferentialElement.CanvasPosition.Y + placementModifierY;
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            Canvas.SetLeft(thumb.DraggedControl, idealPosition.X);
            Canvas.SetTop(thumb.DraggedControl, idealPosition.Y);

            if ((int)_x != (int)Canvas.GetLeft(thumb.DraggedControl) || (int)_y != (int)Canvas.GetTop(thumb.DraggedControl))
            {
                ((DragThumb)element).InvokePositionChanged(new DragDeltaEventArgs(0.1, 0.1));
                ((DragThumb)element).FellowTravellersUpdate();
            }

            if (thumb.DraggedControl is Node)
            {
                ((Node)thumb.DraggedControl).SetPositionSilent(thumb.X, thumb.Y);
            }
        }
Example #6
0
        /// <summary>
        /// Called when dragging starts, stores old positions of the dragged element
        /// </summary>
        private void DragStarted()
        {
            startPositions = new Dictionary <DragThumb, rPoint>();
            IsDragged      = true;

            if (!(this.DraggedControl is ISelectable) ||
                !ExolutioCanvas.SelectedItems.Contains(this.DraggedControl as ISelectable))
            {
                startPositions.Add(this, new rPoint(this.Left, this.Top));
            }
            else
            {
                foreach (ISelectable item in ExolutioCanvas.SelectedItems)
                {
                    if (item.CanBeDraggedInGroup || DraggingAllone(item))
                    {
                        DragThumb thumb = ((IDraggable)item).DragThumb;
                        if (thumb != null)
                        {
                            startPositions.Add(thumb, new rPoint(thumb.Position)
                            {
                                tag = thumb.Placement
                            });
                        }
                        else
                        {
                            throw new InvalidOperationException(
                                      string.Format("Dragging is implemented only for DragThumb and descendants. Object {0} of type {1} does not derive from DrugThumb. ", item, item.GetType()));
                        }
                    }
                }
            }

            //if (this is IAlignable)
            //{
            //    AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(ExolutioCanvas);
            //    visualAidsAdorner = new VisualAidsAdorner(ExolutioCanvas, this);
            //    adornerLayer.Add(visualAidsAdorner);
            //}
        }
Example #7
0
        /// <summary>
        /// Called during dragging. Checks whether dragging can proceed (not out of bounds) and
        /// also calls method <see cref="AdjustDrag"/> that allows subclasses of DragThumb
        /// to alter default dragging.
        /// </summary>
        /// <param name="deltaEventArgs">The <see cref="System.Windows.Controls.Primitives.DragDeltaEventArgs"/> instance containing the event data.</param>
        private void DragDelta(DragDeltaEventArgs deltaEventArgs)
        {
            IEnumerable <IDraggable> draggedElements = ExolutioCanvas.SelectedItems.Where
                                                           (item => item is IDraggable && (item.CanBeDraggedInGroup ||
                                                                                           DraggingAllone(item))).Cast <IDraggable>();

            if (draggedElements.Count() > 0)
            {
                IsDragged = true;
                double minLeft = draggedElements.Min(item => item.GetBounds().Left);
                double minTop  = draggedElements.Min(item => item.GetBounds().Top);

                double deltaHorizontal = Math.Max(-minLeft, deltaEventArgs.HorizontalChange);
                double deltaVertical   = Math.Max(-minTop, deltaEventArgs.VerticalChange);
                deltaEventArgs = new DragDeltaEventArgs(deltaHorizontal, deltaVertical);

                ((IDraggable)DraggedControl).AdjustDrag(ref deltaEventArgs);

                foreach (IDraggable draggedElement in draggedElements)
                {
                    DragThumb dragThumb = draggedElement.DragThumb;
                    dragThumb.x = dragThumb.x + deltaEventArgs.HorizontalChange;
                    dragThumb.y = dragThumb.y + deltaEventArgs.VerticalChange;
                    if (dragThumb.Placement == EPlacementKind.ParentAutoPos)
                    {
                        dragThumb.Placement = EPlacementKind.AbsoluteSubCanvas;
                    }
                    UpdatePos(dragThumb);
                }
                InvokePositionChanged(deltaEventArgs);
                ExolutioCanvas.InvalidateMeasure();
                //if (visualAidsAdorner != null)
                //{
                //    visualAidsAdorner.d = deltaEventArgs;
                //    visualAidsAdorner.InvalidateVisual();
                //}
            }
        }
Example #8
0
 internal void RemovedFromCanvas()
 {
     this.DragThumb.ParentControl = null;
     this.dragThumb = null;
 }