예제 #1
0
        protected override IVisual CreateVisual(IRenderContext context, IPort port)
        {
            var ellipse = new EllipseVisual {
                Pen = pen
            };

            ellipse.Rect.Reshape(GetBounds(context, port));
            return(ellipse);
        }
        protected override VisualGroup CreateVisual(IRenderContext context, INode node)
        {
            // Fetch information for the child visuals
            var employee = (Employee)node.Tag;

            Color borderColor, backgroundColor1, backgroundColor2, ribbonColor;

            if (((GraphControl)context.CanvasControl).CurrentItem == node)
            {
                borderColor      = Color.Orange;
                backgroundColor1 = Color.White;
                backgroundColor2 = Color.Orange;
            }
            else
            {
                borderColor      = Color.FromArgb(255, 24, 154, 231);
                backgroundColor1 = Color.FromArgb(255, 204, 255, 255);
                backgroundColor2 = Color.FromArgb(255, 24, 154, 231);
            }

            if (employee.Status == EmployeeStatus.Travel)
            {
                ribbonColor = Color.Purple;
            }
            else if (employee.Status == EmployeeStatus.Unavailable)
            {
                ribbonColor = Color.Red;
            }
            else
            {
                ribbonColor = Color.Green;
            }

            var layout = node.Layout;

            var icon = GetIcon(employee.Icon);
            var iconScalingFactor = (layout.Height - 10d) / icon.Height;
            var iconWidth         = icon.Width * iconScalingFactor;

            var nameText = new TextVisual {
                Text     = employee.Name,
                Font     = new Font("Arial", 13, FontStyle.Regular, GraphicsUnit.Pixel),
                Brush    = Brushes.Black,
                Location = new PointD(iconWidth + 10, 10)
            };
            var positionText = new TextVisual {
                Text     = employee.Position,
                Font     = new Font("Arial", 11, FontStyle.Regular, GraphicsUnit.Pixel),
                Brush    = Brushes.Black,
                Location = new PointD(iconWidth + 10, 35)
            };
            var emailText = new TextVisual {
                Text     = employee.Email,
                Font     = new Font("Arial", 11, FontStyle.Regular, GraphicsUnit.Pixel),
                Brush    = Brushes.Black,
                Location = new PointD(iconWidth + 10, 50)
            };
            var phone1Text = new TextVisual {
                Text     = employee.Phone,
                Font     = new Font("Arial", 11, FontStyle.Regular, GraphicsUnit.Pixel),
                Brush    = Brushes.Black,
                Location = new PointD(iconWidth + 10, 65)
            };
            var faxText = new TextVisual {
                Text     = employee.Fax,
                Font     = new Font("Arial", 11, FontStyle.Regular, GraphicsUnit.Pixel),
                Brush    = Brushes.Black,
                Location = new PointD(iconWidth + 10, 80)
            };

            var border = new RectangleVisual(0, 0, layout.Width, layout.Height)
            {
                Pen = new Pen(borderColor)
            };
            var background = new RectangleVisual(0, 0, layout.Width, layout.Height)
            {
                Brush = new LinearGradientBrush(new PointF(0, 0), new PointF((float)layout.Width, (float)layout.Height), backgroundColor1, backgroundColor2)
            };
            var iconVisual = new ImageVisual {
                Image     = icon,
                Rectangle = new RectD(5, 5, icon.Width * iconScalingFactor, icon.Height * iconScalingFactor)
            };

            IRectangle rect    = new RectD(layout.Width - 30, 5, 25, 25);
            var        circle1 = new EllipseVisual(rect)
            {
                Brush = new SolidBrush(ribbonColor)
            };
            IRectangle rect1   = new RectD(layout.Width - 25, 10, 15, 15);
            var        circle2 = new EllipseVisual(rect1)
            {
                Brush = Brushes.White
            };
            IRectangle rect2   = new RectD(layout.Width - 20, 15, 5, 5);
            var        circle3 = new EllipseVisual(rect2)
            {
                Brush = circle1.Brush
            };

            // Set a transform on the group, matching the node's location.
            // That way only the transform has to be updated instead of every single child visual.
            var transform = new Matrix();

            transform.Translate((float)layout.X, (float)layout.Y);

            var group = new VisualGroup {
                Transform = transform,
                Children  =
                {
                    border,
                    background,
                    iconVisual,
                    nameText,
                    positionText,
                    emailText,
                    phone1Text,
                    faxText,
                    circle1,
                    circle2,
                    circle3
                }
            };

            return(group);
        }