Пример #1
0
        public override void Draw(RenderInfo info)
        {
            int grid = info.GridSize;
            Rectangle renderBounds = Bounds;

            var bboxThis = new BoundingBox();
            bboxThis.Bounds = renderBounds;
            bboxThis.Target = this;
            bboxThis.Data = BodyIdentifier;
            info.BoundingBoxes.Add(bboxThis);

            int x = renderBounds.X;
            int y = renderBounds.Y;
            int width = renderBounds.Width;
            int height = renderBounds.Height;

            GraphicsPath path = GetOutlinePath(x, y, width, height);
            Pen borderPen = GetBorderPen();

            info.Graphics.FillPath(SystemBrushes.Info, path);
            info.Graphics.DrawPath(borderPen, path);

            renderBounds = DrawText(info, renderBounds);

            DrawSelection(info);
        }
Пример #2
0
        public override void Draw(RenderInfo info)
        {
            int grid = info.GridSize;
            Rectangle renderBounds = Bounds;

            var bboxThis = new BoundingBox {Bounds = renderBounds, Target = this, Data = BodyIdentifier};
            info.BoundingItems.Add(bboxThis);

            int x = renderBounds.X;
            int y = renderBounds.Y;
            int width = renderBounds.Width;
            int height = renderBounds.Height;

            GraphicsPath path = GetOutlinePath(x, y, width, height);
            Pen borderPen = GetBorderPen();

            using (Brush captionBrush = GetCaptionBrush(renderBounds))
            {
                if (Expanded)
                    DrawExpanded(info, path, x, y, width, height, captionBrush, borderPen);
                else
                    DrawCollapsed(info, path, x, y, width, height, captionBrush, borderPen);
            }

            DrawTypeExpander(info, x, y, width);
            DrawSelection(info);
            DrawTypeName(info, x, y, width);
            DrawTypeKind(info, x, y, width);
            DrawCustomCaptionInfo(info, x, y, width);
        }
Пример #3
0
        protected void DrawSelectionHandle(RenderInfo info, Point point, object identifier)
        {
            DrawSelectionHandle(info, point);

            var bounds = new Rectangle(point.X - 4, point.Y - 4, 8, 8);
            var bBox = new BoundingBox();
            bBox.Bounds = bounds;
            bBox.Data = identifier;
            bBox.Target = this;
            info.BoundingBoxes.Add(bBox);
        }
Пример #4
0
        protected void DrawTypeExpander(RenderInfo info, int x, int y, int width)
        {
            var typeExpanderBounds = new Rectangle(x + width - 20, y + 6, 13, 13);

            #region add type expander bbox

            var bboxTypeExpander = new BoundingBox();
            bboxTypeExpander.Target = this;
            bboxTypeExpander.Bounds = typeExpanderBounds;
            bboxTypeExpander.Data = TypeExpanderIdentifier;
            info.BoundingItems.Add(bboxTypeExpander);

            #endregion

            if (Expanded)
                info.Graphics.DrawImage(Resources.CollapseType, typeExpanderBounds);
            else
                info.Graphics.DrawImage(Resources.ExpandType, typeExpanderBounds);
        }
Пример #5
0
        protected void DrawCollapsed(RenderInfo info, GraphicsPath path, int x, int y, int width, int height,
                                     Brush captionBrush, Pen borderPen)
        {
            var captionBounds = new Rectangle(x, y, width, height);

            var bboxCaption = new BoundingBox();
            bboxCaption.Bounds = captionBounds;
            bboxCaption.Target = this;
            bboxCaption.Data = CaptionIdentifier;
            info.BoundingItems.Add(bboxCaption);

            info.Graphics.FillPath(captionBrush, path);
            info.Graphics.DrawPath(borderPen, path);
        }
Пример #6
0
        protected int DrawExpandedCaption(RenderInfo info, GraphicsPath path, int x, int y, int width, int height,
                                          Brush captionBrush)
        {
            int captionHeight = 48;
            var captionBounds = new Rectangle(x, y, width, captionHeight);

            #region add caption bbox

            var bboxCaption = new BoundingBox();
            bboxCaption.Bounds = captionBounds;
            bboxCaption.Target = this;
            bboxCaption.Data = CaptionIdentifier;
            info.BoundingItems.Add(bboxCaption);

            #endregion

            info.Graphics.SetClip(path);
            info.Graphics.FillRectangle(captionBrush, captionBounds);
            info.Graphics.FillRectangle(Brushes.White, x, y + captionHeight, width, height - captionHeight);
            info.Graphics.DrawLine(Pens.LightGray, x, y + captionHeight, x + width, y + captionHeight);
            info.Graphics.ResetClip();
            return captionHeight;
        }
Пример #7
0
        private int DrawTypeMembers(RenderInfo info, int x, int y, int width, UmlTypeMemberSection section)
        {
            var memberCaptionBounds = new Rectangle(x, y, width, 20);

            #region add section header bbox

            var bboxGroup = new BoundingBox();
            bboxGroup.Bounds = memberCaptionBounds;
            bboxGroup.Target = this;
            bboxGroup.Data = section.CaptionIdentifier;
            info.BoundingBoxes.Add(bboxGroup);

            #endregion

            if (SelectedObject == section.CaptionIdentifier && Selected)
            {
                info.Graphics.FillRectangle(SystemBrushes.Highlight, memberCaptionBounds);
                memberCaptionBounds.X += 20;
                memberCaptionBounds.Width -= 30;
                memberCaptionBounds.Y += 3;
                info.Graphics.DrawString(section.Name, Fonts.SectionCaption, SystemBrushes.HighlightText,
                                         memberCaptionBounds);
            }
            else
            {
                Brush sectionCaptionBrush = GetSectionCaptionBrush();
                info.Graphics.FillRectangle(sectionCaptionBrush, memberCaptionBounds);

                memberCaptionBounds.X += 20;
                memberCaptionBounds.Width -= 30;
                memberCaptionBounds.Y += 3;
                info.Graphics.DrawString(section.Name, Fonts.SectionCaption, Brushes.Black, memberCaptionBounds);
            }

            #region add section expander bbox

            var bboxGroupExpander = new BoundingBox();
            bboxGroupExpander.Bounds = new Rectangle(x + 4, y + 4, 13, 13);
            bboxGroupExpander.Target = this;
            bboxGroupExpander.Data = section.ExpanderIdentifier;
            info.BoundingBoxes.Add(bboxGroupExpander);

            #endregion

            if (section.Expanded)
                info.Graphics.DrawImage(Resources.CollapseSection, x + 3, y + 3);
            else
                info.Graphics.DrawImage(Resources.ExpandSection, x + 3, y + 3);

            int currentY = y + 20;
            if (section.Expanded)
            {
                StringFormat sf = StringFormat.GenericTypographic;
                sf.Trimming = StringTrimming.EllipsisCharacter;
                foreach (UmlTypeMember member in section.TypeMembers)
                {
                    var memberBounds = new Rectangle(x + Margins.typeBoxSideMargin, currentY, width - 20, 16);

                    #region add property bbox

                    var memberBBox = new BoundingBox();
                    memberBBox.Target = this;
                    memberBBox.Bounds = memberBounds;
                    memberBBox.Data = member;
                    info.BoundingBoxes.Add(memberBBox);

                    #endregion

                    var layoutBounds = new Rectangle(x + Margins.typeBoxSideMargin + Margins.TypeMemberNameIndent,
                                                     currentY, width - 5 - Margins.TypeMemberNameIndent, 16);

                    Font font = GetTypeMemberFont();
                    if (member == SelectedObject && Selected)
                    {
                        var selectionBounds = new Rectangle(x, currentY, width, 16);
                        info.Graphics.FillRectangle(SystemBrushes.Highlight, selectionBounds);
                        info.Graphics.DrawString(member.DataSource.Name, font, SystemBrushes.HighlightText, layoutBounds,
                                                 sf);
                    }
                    else
                    {
                        info.Graphics.DrawString(member.DataSource.Name, font, Brushes.Black, layoutBounds, sf);
                    }
                    info.Graphics.DrawImage(member.DataSource.GetImage(), x + 13, currentY);
                    currentY += 16;
                }

                var newLayoutBounds = new Rectangle(x + Margins.typeBoxSideMargin + Margins.TypeMemberNameIndent,
                                                    currentY, width - 5 - Margins.TypeMemberNameIndent, 16);
                info.Graphics.DrawString("Add new", Fonts.NewTypeMember, Brushes.Blue, newLayoutBounds, sf);

                var newMemberBBox = new BoundingBox();
                newMemberBBox.Target = this;
                newMemberBBox.Bounds = new Rectangle(x + Margins.typeBoxSideMargin, currentY, width - 20, 16);
                newMemberBBox.Data = section.AddNewIdentifier;
                info.BoundingBoxes.Add(newMemberBBox);

                currentY += 16;
            }
            return currentY;
        }
Пример #8
0
        private void DrawPortSelector(RenderInfo info, float x1, float y1, float x2, float y2, object portIdentifier)
        {
            #region Add BBox

            var bbox = new BoundingBox {Target = this, Data = portIdentifier};
            var tmp = new Rectangle((int) Math.Min(x1, x2), (int) Math.Min(y1, y2), (int) Math.Abs(x2 - x1),
                                    (int) Math.Abs(y2 - y1));

            tmp.Inflate(6, 6);

            bbox.Bounds = tmp;
            info.BoundingItems.Add(bbox);

            #endregion

            if (Selected)
            {
                tmp.Inflate(-2, -2);
                info.Graphics.FillRectangle(Brushes.Selection, tmp);
            }
        }
Пример #9
0
        protected virtual Rectangle DrawText(RenderInfo info, Rectangle renderBounds)
        {
            Rectangle textBounds = renderBounds;
            textBounds.Inflate(-10, -10);

            var bboxText = new BoundingBox();
            bboxText.Bounds = textBounds;
            bboxText.Target = this;
            bboxText.Data = TextIdentifier;
            info.BoundingBoxes.Add(bboxText);

            var textBoundsF = new RectangleF(textBounds.X, textBounds.Y, textBounds.Width, textBounds.Height);

            //info.Graphics.FillRectangle(Brushes.White, textBounds);
            info.Graphics.DrawString(Text, Fonts.CommentText, Brushes.Black, textBoundsF,
                                     StringFormat.GenericTypographic);
            return renderBounds;
        }
Пример #10
0
        private void DrawLineBackground(RenderInfo info, float x1, float y1, float x2, float y2)
        {
            LineDrawer drawLine = (xx1, yy1, xx2, yy2) =>
                                      {
                                          #region Add BBox

                                          var bbox = new BoundingBox {Target = this, Data = this};
                                          var tmp = new Rectangle((int) Math.Min(xx1, xx2), (int) Math.Min(yy1, yy2),
                                                                  (int) Math.Abs(xx2 - xx1),
                                                                  (int) Math.Abs(yy2 - yy1));
                                          tmp.Inflate(6, 6);
                                          bbox.Bounds = tmp;
                                          info.BoundingItems.Add(bbox);

                                          #endregion

                                          if (Selected)
                                          {
                                              info.Graphics.DrawLine(Pens.Selection, xx1, yy1, xx2, yy2);
                                          }
                                      };

            RouteLine(drawLine, x1, y1, x2, y2);
        }
Пример #11
0
        private void MainCanvas_MouseUp(object sender, MouseEventArgs e)
        {
            var x = (int) ((e.X - MainCanvas.AutoScrollPosition.X)/Zoom);
            var y = (int) ((e.Y - MainCanvas.AutoScrollPosition.Y)/Zoom);

            if (EditMode == EditMode.DrawRelation)
            {
                relationEnd = null;

                for (int i = BoundingBoxes.Count - 1; i >= 0; i--)
                {
                    BoundingBox bbox = BoundingBoxes[i];
                    if (bbox.Bounds.Contains(x, y))
                    {
                        if (bbox.Target is Shape)
                        {
                            relationEnd = bbox.Target as Shape;
                        }
                    }
                }

                endDrawRelation(relationStart, relationEnd);

                //end drawing
                EditMode = EditMode.Normal;
                MainCanvas.Refresh();
            }
            else if (EditMode == EditMode.Normal)
            {
                Cursor = Cursors.Default;
                currentBoundingBox = null;
                isPanning = false;
                for (int i = BoundingBoxes.Count - 1; i >= 0; i--)
                {
                    BoundingBox bbox = BoundingBoxes[i];
                    if (bbox.Bounds.Contains(x, y))
                    {
                        if (bbox.Target is Shape)
                        {
                            var shape = (Shape) bbox.Target;
                            var args = new ShapeMouseEventArgs();
                            args.BoundingBox = bbox;
                            args.X = x;
                            args.Y = y;
                            args.Button = e.Button;
                            args.Sender = this;
                            args.GridSize = GridSize;
                            args.SnapToGrid = SnapToGrid;
                            shape.OnMouseUp(args);
                            if (args.Redraw)
                                Refresh();
                        }

                        return;
                    }
                }
            }
        }
Пример #12
0
        private void MainCanvas_MouseDown(object sender, MouseEventArgs e)
        {
            EndInput();
            var x = (int) ((e.X - MainCanvas.AutoScrollPosition.X)/Zoom);
            var y = (int) ((e.Y - MainCanvas.AutoScrollPosition.Y)/Zoom);

            if (EditMode == EditMode.BeginDrawRelation)
            {
                mouseDownPoint = new Point(e.X, e.Y);
                EditMode = EditMode.DrawRelation;
                relationStart = null;

                for (int i = BoundingBoxes.Count - 1; i >= 0; i--)
                {
                    BoundingBox bbox = BoundingBoxes[i];
                    if (bbox.Bounds.Contains(x, y))
                    {
                        if (bbox.Target is Shape)
                        {
                            relationStart = bbox.Target as Shape;
                        }
                    }
                }
            }
            else if (EditMode == EditMode.Normal)
            {
                mouseDownPoint = new Point(e.X, e.Y);
                mouseDownAutoscrollPoint = new Point(-MainCanvas.AutoScrollPosition.X, -MainCanvas.AutoScrollPosition.Y);

                for (int i = BoundingBoxes.Count - 1; i >= 0; i--)
                {
                    BoundingBox bbox = BoundingBoxes[i];
                    if (bbox.Bounds.Contains(x, y))
                    {
                        if (bbox.Target is Shape)
                        {
                            currentBoundingBox = bbox;
                            var shape = (Shape) bbox.Target;
                            currentShape = shape;
                            var args = new ShapeMouseEventArgs();
                            args.BoundingBox = bbox;
                            args.X = x;
                            args.Y = y;
                            args.Button = e.Button;
                            args.Sender = this;
                            args.GridSize = GridSize;
                            args.SnapToGrid = SnapToGrid;
                            shape.OnMouseDown(args);
                            if (args.Redraw)
                                Refresh();
                        }

                        return;
                    }
                }
                isPanning = true;
            }
        }
Пример #13
0
        private void MainCanvas_DoubleClick(object sender, EventArgs e)
        {
            var x = (int) ((mouseDownPoint.X - MainCanvas.AutoScrollPosition.X)/Zoom);
            var y = (int) ((mouseDownPoint.Y - MainCanvas.AutoScrollPosition.Y)/Zoom);

            for (int i = BoundingBoxes.Count - 1; i >= 0; i--)
            {
                BoundingBox bbox = BoundingBoxes[i];
                if (bbox.Bounds.Contains(x, y))
                {
                    if (bbox.Target is Shape)
                    {
                        currentBoundingBox = bbox;
                        var shape = (Shape) bbox.Target;
                        var args = new ShapeMouseEventArgs();
                        args.BoundingBox = bbox;
                        args.X = x;
                        args.Y = y;
                        args.Button = MouseButtons.Left;
                        args.Sender = this;
                        shape.OnDoubleClick(args);
                        if (args.Redraw)
                            Refresh();
                    }

                    return;
                }
            }
        }
Пример #14
0
        private void DrawStraightLineSelector(RenderInfo info, float x1, float y1, float x2, float y2)
        {
            #region Add BBox

            var bbox = new BoundingBox();
            bbox.Target = this;
            bbox.Data = this;
            var tmp = new Rectangle((int) Math.Min(x1, x2), (int) Math.Min(y1, y2), (int) Math.Abs(x2 - x1),
                                    (int) Math.Abs(y2 - y1));
            tmp.Inflate(6, 6);
            bbox.Bounds = tmp;
            info.BoundingBoxes.Add(bbox);

            #endregion

            if (Selected)
            {
                tmp.Inflate(-2, -2);
                info.Graphics.FillRectangle(Brushes.Selection, tmp);
            }
        }