コード例 #1
0
ファイル: NodeViewData.cs プロジェクト: XyzalZhang/behaviac
        /// <summary>
        /// Set the source sub item before the target one.
        /// </summary>
        /// <param name="targetNvd">The target node view data in the current view.</param>
        /// <param name="sourceItem">The source sub item of the current node view data.</param>
        /// <param name="targetItem">The target sub item of the target node view data.</param>
        public bool SetSubItem(NodeViewData targetNvd, SubItemAttachment sourceItem, SubItemAttachment targetItem, bool insertPreviously, bool isCopied)
        {
            if (targetNvd == null ||
            sourceItem == null || sourceItem.Attachment == null ||
            !isCopied && targetItem == sourceItem ||
            !targetNvd.Node.AcceptsAttachment(sourceItem.Attachment))
            { return false; }

            if (!isCopied) {
            this.Node.RemoveAttachment(sourceItem.Attachment);
            this.RemoveSubItem(sourceItem);

            } else {
            sourceItem = sourceItem.Clone(targetNvd.Node) as SubItemAttachment;
            sourceItem.Attachment.ResetId();
            }

            if (targetItem == null) {
            targetNvd.Node.AddAttachment(sourceItem.Attachment);

            } else {
            Debug.Check(targetItem.Attachment != null);

            for (int i = 0; i < targetNvd.Node.Attachments.Count; ++i) {
                if (targetNvd.Node.Attachments[i] == targetItem.Attachment) {
                    targetNvd.Node.AddAttachment(sourceItem.Attachment, insertPreviously ? i : i + 1);
                    break;
                }
            }
            }

            if (targetItem == null) {
            targetNvd.AddSubItem(sourceItem);

            } else {
            for (int i = 0; i < targetNvd.SubItems.Count; ++i) {
                if (targetNvd.SubItems[i] == targetItem) {
                    targetNvd.AddSubItem(sourceItem, insertPreviously ? i : i + 1);
                    break;
                }
            }
            }

            bool setDirty = false;

            if (!isCopied) {
            sourceItem.Attachment.OnPropertyValueChanged(!setDirty);
            setDirty = true;
            }

            for (int i = 0; i < targetNvd.SubItems.Count; ++i) {
            SubItemAttachment attach = targetNvd.SubItems[i] as SubItemAttachment;

            if (attach != null && attach != sourceItem) {
                attach.Attachment.OnPropertyValueChanged(!setDirty);
                setDirty = true;
            }
            }

            targetNvd.SelectedSubItem = sourceItem;

            return true;
        }
コード例 #2
0
ファイル: NodeViewData.cs プロジェクト: XyzalZhang/behaviac
        private void DrawFSMCurve(SubItemAttachment attachment, Graphics graphics, Pen edgePen, RectangleF startBox, RectangleF endBox, bool isPointedBySelf)
        {
            float penHalfWidth = edgePen.Width * 0.5f;
            float centerY = startBox.Top + startBox.Height * 0.5f;
            PointF startPos = new PointF(startBox.Right, centerY - penHalfWidth);
            PointF endPos = new PointF(endBox.Left, endBox.Top + 5.0f);

            if (endBox.Right < startBox.Left) {
            startPos.X = startBox.Left;
            endPos.X = endBox.Right;

            } else if (endBox.Left < startBox.Right) {
            startPos.X = startBox.Left;
            endPos.X = endBox.Left;
            }

            float middleX = startPos.X + (endPos.X - startPos.X) * 0.5f;
            float controlStartX = middleX;
            float controlEndX = middleX;

            if (endBox.Right < startBox.Left) {
            } else if (endBox.Left < startBox.Right) {
            if (endBox.Left < startBox.Left)
            { controlEndX = endBox.Left - (middleX - endBox.Left); }

            else
            { controlStartX = startBox.Left - (middleX - startBox.Left); }
            }

            if (isPointedBySelf) {
            controlStartX -= startBox.Width * 0.5f;
            }

            edgePen.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
            edgePen.CustomEndCap = new System.Drawing.Drawing2D.AdjustableArrowCap(edgePen.Width, edgePen.Width);

            if (attachment.DrawnPath == null) {
            attachment.DrawnPath = new System.Drawing.Drawing2D.GraphicsPath();

            } else {
            attachment.DrawnPath.Reset();
            }

            attachment.DrawnPath.AddBezier(startPos.X, startPos.Y,
                                       controlStartX, startPos.Y,
                                       controlEndX, endPos.Y,
                                       endPos.X, endPos.Y);

            graphics.DrawPath(edgePen, attachment.DrawnPath);

            //bool isIn = attachment.DrawnPath.IsOutlineVisible(startPos.X + 0.01f, startPos.Y + 0.01f, edgePen);
            //Debug.Check(isIn);
        }
コード例 #3
0
ファイル: NodeViewData.cs プロジェクト: KeyleXiao/behaviac
        /// <summary>
        /// Set the source sub item before the target one.
        /// </summary>
        /// <param name="targetNvd">The target node view data in the current view.</param>
        /// <param name="targetItem">The target sub item of the target node view data.</param>
        /// <param name="sourceItem">The source sub item of the current node view data.</param>
        public bool SetSubItem(NodeViewData targetNvd, SubItemAttachment targetItem, SubItemAttachment sourceItem, bool insertPrevious)
        {
            if (targetNvd == null ||
                targetItem == null || targetItem.Attachment == null ||
                sourceItem == null || sourceItem.Attachment == null ||
                targetItem == sourceItem)
                return false;

            this.Node.RemoveAttachment(sourceItem.Attachment);
            for (int i = 0; i < targetNvd.Node.Attachments.Count; ++i)
            {
                if (targetNvd.Node.Attachments[i] == targetItem.Attachment)
                {
                    targetNvd.Node.AddAttachment(sourceItem.Attachment, insertPrevious ? i : i + 1);
                    break;
                }
            }

            this.RemoveSubItem(sourceItem);
            for (int i = 0; i < targetNvd.SubItems.Count; ++i)
            {
                if (targetNvd.SubItems[i] == targetItem)
                {
                    targetNvd.AddSubItem(sourceItem, insertPrevious ? i : i + 1);
                    break;
                }
            }

            sourceItem.Attachment.OnPropertyValueChanged(true);
            for (int i = 0; i < targetNvd.SubItems.Count; ++i)
            {
                SubItemAttachment attach = targetNvd.SubItems[i] as SubItemAttachment;
                if (attach != null && attach != sourceItem)
                    attach.Attachment.OnPropertyValueChanged(false);
            }

            return true;
        }