Пример #1
0
        // draw the header:
        // class name and expand button
        private RectD DrawHeader(IRenderContext context, VisualGroup group, ClassInfo info, RectD box)
        {
            float height    = titleFont.Height + typeFont.Height + 5 + 2;
            var   headerBox = new RectD(box.X, box.Y, box.Width, height);

            LinearGradientBrush brush = new LinearGradientBrush(headerBox.ToRectangleF(), Color.LightBlue, Color.White, LinearGradientMode.Horizontal);

            group.Add(new RoundedRectangleVisual(headerBox, 7)
            {
                Brush = brush
            });
            if (info.ShowDetails)
            {
                // If the node is expanded, we need to fill in the lower corners as well
                var secondHeaderBox = new RectD(headerBox.X, headerBox.Y + headerBox.Height / 2, headerBox.Width, headerBox.Height / 2);
                group.Add(new RectangleVisual(secondHeaderBox)
                {
                    Brush = brush
                });
            }

            var textBox = new RectD(box.X + 5, box.Y + 5, box.Width - 20, titleFont.Height);

            DrawTrimmedString(context, group, info.Name, titleFont, titleBrush, textBox);
            textBox = new RectD(box.X + 5, box.Y + titleFont.Height + 7, box.Width - 20, typeFont.Height);
            DrawTrimmedString(context, group, info.Type, typeFont, typeBrush, textBox);

            Image image = info.ShowDetails ? imageUp2 : imageDown2;

            group.Add(new ImageVisual {
                Image = image, Rectangle = new RectD(box.X + box.Width - ImageSize - 5, box.Y + 5, ImageSize, ImageSize)
            });
            return(new RectD(box.X, box.Y + height, box.Width, box.Height - height));
        }
            void IVisual.Paint(IRenderContext context, Graphics graphics)
            {
                bool enabled = false;

                if (button != null)
                {
                    enabled = button.CanExecute((INode)label.Owner, context.CanvasControl);
                }

                var layout = new RectD(labelLayout.AnchorX, labelLayout.AnchorY - label.PreferredSize.Height,
                                       label.PreferredSize.Width, label.PreferredSize.Height);
                Brush backgroundBrush;
                Pen   foregroundPen;

                if (enabled)
                {
                    // enabled style
                    backgroundBrush = new LinearGradientBrush(layout.TopLeft, layout.BottomLeft,
                                                              Mix(Color.White, backgroundColor, 0.5d), backgroundColor);
                    foregroundPen = new Pen(foregroundColor);
                }
                else
                {
                    // disabled style
                    backgroundBrush = new LinearGradientBrush(layout.TopLeft, layout.BottomLeft,
                                                              Mix(Color.White, backgroundColor, 0.7),
                                                              Mix(Color.White, backgroundColor, 0.7));
                    foregroundPen = new Pen(Mix(Color.White, foregroundColor, 0.7));
                }
                graphics.FillEllipse(backgroundBrush, layout.ToRectangleF());
                GraphicsPath path;

                switch (icon)
                {
                case ButtonIcon.ShowParent:
                    path = new GraphicsPath(
                        new PointF[] {
                        layout.TopLeft + new PointD(layout.Width * 0.3, layout.Height * 0.7),
                        layout.TopLeft + new PointD(layout.Width * 0.7, layout.Height * 0.7),
                        layout.TopLeft + new PointD(layout.Width * 0.5, layout.Height * 0.3)
                    },
                        new[] { (byte)PathPointType.Start, (byte)PathPointType.Line, (byte)PathPointType.Line });
                    path.CloseAllFigures();
                    graphics.DrawPath(foregroundPen, path);
                    break;

                case ButtonIcon.HideParent:
                    path = new GraphicsPath(
                        new PointF[] {
                        layout.TopLeft + new PointD(layout.Width * 0.3, layout.Height * 0.3),
                        layout.TopLeft + new PointD(layout.Width * 0.7, layout.Height * 0.3),
                        layout.TopLeft + new PointD(layout.Width * 0.5, layout.Height * 0.7)
                    },
                        new[] { (byte)PathPointType.Start, (byte)PathPointType.Line, (byte)PathPointType.Line });
                    path.CloseAllFigures();
                    graphics.DrawPath(foregroundPen, path);
                    break;

                case ButtonIcon.ShowChildren:
                    graphics.DrawLine(foregroundPen, layout.TopLeft + new PointD(layout.Width * 0.3, layout.Height * 0.5),
                                      layout.TopLeft + new PointD(layout.Width * 0.7, layout.Height * 0.5));
                    graphics.DrawLine(foregroundPen, layout.TopLeft + new PointD(layout.Width * 0.5, layout.Height * 0.3),
                                      layout.TopLeft + new PointD(layout.Width * 0.5, layout.Height * 0.7));
                    break;

                case ButtonIcon.HideChildren:
                    graphics.DrawLine(foregroundPen, layout.TopLeft + new PointD(layout.Width * 0.3, layout.Height * 0.5),
                                      layout.TopLeft + new PointD(layout.Width * 0.7, layout.Height * 0.5));
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }