Example #1
0
        /// <summary>
        /// Pass mouse up to appropriate item
        /// </summary>
        /// <param name="e"></param>
        public override bool OnMouseUp(VCItem sender, ItemMouseEventArgs e)
        {
            var pt = e.Location;

            if (mouseDownPlacement != null)
            {
                try
                {
                    var localPt = mouseDownPlacement.ToLocal(pt);
                    return(mouseDownPlacement.Item.OnMouseUp(new ItemMouseEventArgs(e, localPt.X, localPt.Y)));
                }
                finally
                {
                    mouseDownPlacement = null;
                }
            }
            else
            {
                VCItemPlacement placement = null;
                while ((placement = container.Items.Find(pt, placement)) != null)
                {
                    var localPt = placement.ToLocal(pt);
                    if (placement.Item.OnMouseUp(new ItemMouseEventArgs(e, localPt.X, localPt.Y)))
                    {
                        return(true);
                    }
                }
                return(base.OnMouseUp(sender, e));
            }
        }
Example #2
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public MovingPlacement(VCItemPlacement placement)
 {
     this.placement     = placement;
     startLocation      = placement.Location;
     newLocation        = startLocation;
     lastCommitLocation = startLocation;
 }
        /// <summary>
        /// Draw resize handles on the given placement
        /// </summary>
        /// <param name="e"></param>
        /// <param name="placement"></param>
        private void DrawResizeHandles(ItemPaintEventArgs e, VCItemPlacement placement)
        {
            if ((placement == activePlacement) && CanResize(placement))
            {
                Graphics g = e.Graphics;
                handleSize = (int)(DEFAULT_HANDLE_SIZE / e.ZoomFactor);
                int  d  = -handleSize / 2;
                int  s  = handleSize;
                Size sz = placement.Item.Size;

                Brush brush = Brushes.Red;

                // Top-left
                g.FillRectangle(brush, d, d, s, s);
                // Top-right
                g.FillRectangle(brush, sz.Width + d, d, s, s);
                // Bottom-left
                g.FillRectangle(brush, d, sz.Height + d, s, s);
                // Bottom-right
                g.FillRectangle(brush, sz.Width + d, sz.Height + d, s, s);

                // Top-center
                g.FillRectangle(brush, (sz.Width / 2) + d, d, s, s);
                // Bottom-center
                g.FillRectangle(brush, (sz.Width / 2) + d, sz.Height + d, s, s);
                // Left-middle
                g.FillRectangle(brush, d, (sz.Height / 2) + d, s, s);
                // Right-middle
                g.FillRectangle(brush, sz.Width + d, (sz.Height / 2) + d, s, s);
            }
        }
        /// <summary>
        /// Can the given item placement be resized.
        /// Override this method to block items from being resized.
        /// </summary>
        protected override bool CanResize(VCItemPlacement placement)
        {
            var item   = placement.Item as IPositionedEntityItem;
            var entity = (item != null) ? item.Entity : null;

            return((entity != null) && (!entity.Locked) && (!(entity is ISensor) && (!(entity is ISignal))));
        }
        /// <summary>
        /// Gets the constraints from the given placement or an automatic constraints in case
        /// the placement has not table constraints.
        /// </summary>
        /// <param name="placement"></param>
        /// <param name="lastConstraints"></param>
        /// <returns></returns>
        private TableLayoutConstraints GetConstrains(VCItemPlacement placement, TableLayoutConstraints lastConstraints)
        {
            TableLayoutConstraints constraints = placement.Constraints as TableLayoutConstraints;

            if (constraints != null)
            {
                return(constraints);
            }

            // Auto generate constraints
            if (lastConstraints == null)
            {
                return(new TableLayoutConstraints(0, 0));
            }
            else
            {
                int col = lastConstraints.ColumnIndex + lastConstraints.ColumnSpan;

                // Next col ok?
                if (col < colFills.Length)
                {
                    return(new TableLayoutConstraints(col, lastConstraints.RowIndex));
                }

                // Next row ok?
                int row = lastConstraints.RowIndex + lastConstraints.RowSpan;
                if (row < rowsFills.Length)
                {
                    return(new TableLayoutConstraints(0, row));
                }

                // Overflow, restart
                return(new TableLayoutConstraints(0, 0));
            }
        }
Example #6
0
 /// <summary>
 /// Handle mouse leaves.
 /// </summary>
 /// <param name="e"></param>
 public override void OnMouseLeave(VCItem sender, EventArgs e)
 {
     if (mouseOverPlacement != null)
     {
         mouseOverPlacement.Item.OnMouseLeave(e);
         mouseOverPlacement = null;
     }
     base.OnMouseLeave(sender, e);
 }
Example #7
0
 /// <summary>
 /// Occurs when an object is dragged out of the item's bounds.
 /// </summary>
 /// <param name="e"></param>
 public override void OnDragLeave(VCItem sender, EventArgs e)
 {
     if (dragOverPlacement != null)
     {
         dragOverPlacement.Item.OnDragLeave(e);
         dragOverPlacement = null;
     }
     base.OnDragLeave(sender, e);
 }
        /// <summary>
        /// Adjust the bounds of the given placement.
        /// </summary>
        protected override void Move(VCItemPlacement placement, int dx, int dy)
        {
            var item = placement.Item as IPositionedEntityItem;

            if (item != null)
            {
                item.Entity.X += dx;
                item.Entity.Y += dy;
            }
        }
        /// <summary>
        /// Stop resizing when mouse leaves the container
        /// </summary>
        /// <param name="e"></param>
        public override void OnMouseLeave(VCItem sender, EventArgs e)
        {
            base.OnMouseLeave(sender, e);
            resizing = false;

            if (activePlacement != null)
            {
                activePlacement = null;
                container.Invalidate();
            }
        }
        /// <summary>
        /// Adjust the bounds of the given placement.
        /// </summary>
        protected override void Resize(VCItemPlacement placement, Rectangle newBounds)
        {
            var item = placement.Item as IPositionedEntityItem;

            if (item != null)
            {
                item.Entity.X      = newBounds.Left;
                item.Entity.Y      = newBounds.Top;
                item.Entity.Width  = newBounds.Width;
                item.Entity.Height = newBounds.Height;
                base.Resize(placement, newBounds);
            }
        }
Example #11
0
        /// <summary>
        /// Pass mouse move to appropriate item
        /// </summary>
        /// <param name="e"></param>
        public override bool OnMouseMove(VCItem sender, ItemMouseEventArgs e)
        {
            var pt = e.Location;

            if (mouseDownPlacement != null)
            {
                // Mouse button down, always send events to same placement
                var localPt = mouseDownPlacement.ToLocal(pt);
                return(mouseDownPlacement.Item.OnMouseMove(new ItemMouseEventArgs(e, localPt.X, localPt.Y)));
            }
            else
            {
                VCItemPlacement placement = container.Items.Find(pt, null);

                // Handle mouse leave
                if ((mouseOverPlacement != null) && (mouseOverPlacement != placement))
                {
                    mouseOverPlacement.Item.OnMouseLeave(EventArgs.Empty);
                    mouseOverPlacement = null;
                }

                while (placement != null)
                {
                    // Convert point to local
                    var localPt = placement.ToLocal(pt);

                    // Handle mouse enter
                    if (mouseOverPlacement == null)
                    {
                        mouseOverPlacement = placement;
                        mouseOverPlacement.Item.OnMouseEnter(EventArgs.Empty);
                    }

                    // Send mouse move
                    mouseOverPlacement = placement;
                    if (placement.Item.OnMouseMove(new ItemMouseEventArgs(e, localPt.X, localPt.Y)))
                    {
                        return(true);
                    }

                    placement = container.Items.Find(pt, placement);
                    if ((placement != mouseOverPlacement) && (placement != null))
                    {
                        mouseOverPlacement.Item.OnMouseLeave(EventArgs.Empty);
                        mouseOverPlacement = null;
                    }
                }
                return(base.OnMouseMove(sender, e));
            }
        }
Example #12
0
        /// <summary>
        /// Can the given item placement be selected.
        /// Override this method to block items from being selected.
        /// </summary>
        protected override bool CanSelect(VCItemPlacement placement)
        {
            if (!(placement.Item is IPositionedEntityItem))
            {
                return(false);
            }
            var moduleItem = placement.Item as ModuleEditItem;

            if (moduleItem != null)
            {
                return(!moduleItem.ContentsEditable);
            }
            return(true);
        }
        /// <summary>
        /// Calculate what side or corner or the placement the given point touches.
        /// </summary>
        /// <param name="placement"></param>
        /// <param name="pt"></param>
        /// <returns></returns>
        private HitSide CalcHitSide(VCItemPlacement placement, PointF pt)
        {
            if (placement == null)
            {
                return(HitSide.None);
            }

            Rectangle bounds = placement.Bounds;
            int       max    = handleSize;

            var topDist    = Math.Abs(bounds.Top - pt.Y);
            var bottomDist = Math.Abs(bounds.Bottom - pt.Y);
            var leftDist   = Math.Abs(bounds.Left - pt.X);
            var rightDist  = Math.Abs(bounds.Right - pt.X);

            if (topDist <= max)
            {
                if (leftDist <= max)
                {
                    return(HitSide.Top | HitSide.Left);
                }
                if (rightDist <= max)
                {
                    return(HitSide.Top | HitSide.Right);
                }
                return(HitSide.Top);
            }
            else if (bottomDist <= max)
            {
                if (leftDist <= max)
                {
                    return(HitSide.Bottom | HitSide.Left);
                }
                if (rightDist <= max)
                {
                    return(HitSide.Bottom | HitSide.Right);
                }
                return(HitSide.Bottom);
            }
            else if (leftDist <= max)
            {
                return(HitSide.Left);
            }
            else if (rightDist <= max)
            {
                return(HitSide.Right);
            }
            return(HitSide.None);
        }
Example #14
0
        /// <summary>
        /// Occurs when a drag-and-drop operation is completed.
        /// </summary>
        /// <param name="e"></param>
        public override bool OnDragDrop(VCItem sender, ItemDragEventArgs e)
        {
            var             pt        = new Point(e.X, e.Y);
            VCItemPlacement placement = null;

            while ((placement = container.Items.Find(pt, placement)) != null)
            {
                Point localPt = placement.ToLocal(pt);
                if (placement.Item.OnDragDrop(new ItemDragEventArgs(e, localPt.X, localPt.Y)))
                {
                    return(true);
                }
            }
            return(base.OnDragDrop(sender, e));
        }
Example #15
0
        /// <summary>
        /// Pass mouse double click to appropriate item
        /// </summary>
        /// <param name="e"></param>
        public override bool OnMouseDoubleClick(VCItem sender, ItemMouseEventArgs e)
        {
            var             pt        = e.Location;
            VCItemPlacement placement = null;

            while ((placement = container.Items.Find(pt, placement)) != null)
            {
                var localPt = placement.ToLocal(pt);
                if (placement.Item.OnMouseDoubleClick(new ItemMouseEventArgs(e, localPt.X, localPt.Y)))
                {
                    return(true);
                }
            }
            return(base.OnMouseDoubleClick(sender, e));
        }
        /// <summary>
        /// Pass mouse move to appropriate item
        /// </summary>
        /// <param name="e"></param>
        public override bool OnMouseMove(VCItem sender, ItemMouseEventArgs e)
        {
            var pt = e.Location;

            if (resizing)
            {
                var rect = CalcResizedBounds(startBounds, startMousePt, LimitMoveToPosition(pt), startSide);
                Resize(activePlacement, rect);
                container.Invalidate();
                return(true);
            }
            else if (e.Button == MouseButtons.None)
            {
                VCItemPlacement placement = Find(pt, null);

                // Can placement be resized?
                if ((placement != null) && (placement != activePlacement) && !CanResize(placement))
                {
                    // No, it cannot be resized
                    placement = null;
                }

                HitSide hitSide = HitSide.None;
                if ((placement != null) || (activePlacement != null))
                {
                    hitSide = CalcHitSide(placement, pt);
                    if (hitSide != HitSide.None)
                    {
                        e.Cursor = GetCursor(hitSide);
                    }
                }

                if (activePlacement != placement)
                {
                    activePlacement = placement;
                    container.Invalidate();
                }

                if (hitSide != HitSide.None)
                {
                    return(true);
                }
            }

            return(base.OnMouseMove(sender, e));
        }
Example #17
0
        /// <summary>
        /// Occurs when an object is dragged over the item's bounds.
        /// </summary>
        /// <param name="e"></param>
        public override bool OnDragOver(VCItem sender, ItemDragEventArgs e)
        {
            var             pt        = new Point(e.X, e.Y);
            VCItemPlacement placement = container.Items.Find(pt, null);

            // Handle drag leave
            if ((dragOverPlacement != null) && (dragOverPlacement != placement))
            {
                dragOverPlacement.Item.OnDragLeave(EventArgs.Empty);
                dragOverPlacement = null;
            }

            while (placement != null)
            {
                // Convert point to local
                Point localPt = placement.ToLocal(pt);

                // Handle drag enter
                if (dragOverPlacement == null)
                {
                    dragOverPlacement = placement;
                    dragOverPlacement.Item.OnDragEnter(EventArgs.Empty);
                }

                // Send drag over
                dragOverPlacement = placement;
                if (placement.Item.OnDragOver(new ItemDragEventArgs(e, localPt.X, localPt.Y)))
                {
                    return(true);
                }

                placement = container.Items.Find(pt, placement);
                if ((placement != dragOverPlacement) && (placement != null))
                {
                    dragOverPlacement.Item.OnDragLeave(EventArgs.Empty);
                    dragOverPlacement = null;
                }
            }

            return(base.OnDragOver(sender, e));
        }
        /// <summary>
        /// Pass mouse down to appropriate item
        /// </summary>
        /// <param name="e"></param>
        public override bool OnMouseDown(VCItem sender, ItemMouseEventArgs e)
        {
            var pt        = e.Location;
            var placement = Find(pt, null);

            // Can placement be resized?
            if ((placement != null) && (placement != activePlacement) && !CanResize(placement))
            {
                // No, it cannot be resized
                placement = null;
            }

            HitSide side = HitSide.None;

            if (placement != null)
            {
                side = CalcHitSide(placement, pt);
                if (side == HitSide.None)
                {
                    placement = null;
                }
            }

            if (placement != null)
            {
                activePlacement = placement;
                startBounds     = placement.Bounds;
                startMousePt    = pt;
                startSide       = side;
                resizing        = true;
                container.Invalidate();
                return(true);
            }
            else
            {
                // Pass event on
                return(base.OnMouseDown(sender, e));
            }
        }
 /// <summary>
 /// Adjust the bounds of the given placement.
 /// </summary>
 /// <param name="placement"></param>
 /// <param name="newBounds"></param>
 protected virtual void Resize(VCItemPlacement placement, Rectangle newBounds)
 {
     activePlacement.Bounds = newBounds;
 }
        /// <summary>
        /// Can the given item placement be moved.
        /// Override this method to block items from being moved.
        /// </summary>
        protected override bool CanMove(VCItemPlacement placement)
        {
            var item = placement.Item as IPositionedEntityItem;

            return((item != null) && !item.Entity.Locked);
        }
 /// <summary>
 /// Can the given item placement be resized.
 /// Override this method to block items from being resized.
 /// </summary>
 /// <param name="placement"></param>
 /// <returns></returns>
 protected virtual bool CanResize(VCItemPlacement placement)
 {
     return(true);
 }
Example #22
0
 /// <summary>
 /// Can the given item placement be selected.
 /// Override this method to block items from being selected.
 /// </summary>
 protected virtual bool CanSelect(VCItemPlacement placement)
 {
     return(true);
 }
 /// <summary>
 /// Find the placement to resize at the given virtual point.
 /// </summary>
 /// <param name="pt"></param>
 /// <returns></returns>
 private VCItemPlacement Find(PointF pt, VCItemPlacement after)
 {
     // This can be smarter so it also finds items the mouse is (a bit) outside of.
     return(container.Items.Find(pt, after));
 }
Example #24
0
 /// <summary>
 /// Adjust the bounds of the given placement.
 /// </summary>
 protected abstract void Move(VCItemPlacement placement, int dx, int dy);