/// <summary>
        /// Replacement for <see cref="ShapeField.GetBackgroundBrush"/> that recognizes
        /// <see cref="IDynamicColorGeometryHost"/>
        /// </summary>
        public override Pen GetPen(DiagramClientView view, ShapeElement parentShape, ref Color oldColor)
        {
            StyleSet styleSet     = (parentShape != null) ? parentShape.StyleSet : null;
            Color    restoreColor = Color.Empty;
            Pen      pen          = null;

            if (styleSet != null)
            {
                StyleSetResourceId penId = GetPenId(parentShape);
                pen = styleSet.GetPen(penId);
                IDynamicColorGeometryHost dynamicColors = parentShape as IDynamicColorGeometryHost;
                if (dynamicColors == null ||
                    (restoreColor = dynamicColors.UpdateDynamicColor(penId, pen)).IsEmpty)
                {
                    if (view != null)
                    {
                        restoreColor = parentShape.UpdateGeometryLuminosity(view, pen);
                    }
                }
                else if (view != null)
                {
                    parentShape.UpdateGeometryLuminosity(view, pen);
                }
            }
            if (pen != null && !restoreColor.IsEmpty)
            {
                restoreColor = pen.Color;
            }
            return(pen);
        }
        /// <summary>
        /// Replacement for <see cref="ShapeField.GetBackgroundBrush"/> that recognizes
        /// <see cref="IDynamicColorGeometryHost"/>
        /// </summary>
        public override Brush GetBackgroundBrush(DiagramClientView view, ShapeElement parentShape, ref Color oldColor)
        {
            StyleSet   styleSet     = (parentShape != null) ? parentShape.StyleSet : null;
            Brush      brush        = null;
            SolidBrush solidBrush   = null;;
            Color      restoreColor = Color.Empty;

            if (styleSet != null)
            {
                StyleSetResourceId brushId = GetBackgroundBrushId(view, parentShape);
                brush = styleSet.GetBrush(brushId);
                IDynamicColorGeometryHost dynamicColors = parentShape as IDynamicColorGeometryHost;
                if (dynamicColors == null ||
                    (restoreColor = dynamicColors.UpdateDynamicColor(brushId, brush)).IsEmpty)
                {
                    if (view != null)
                    {
                        restoreColor = parentShape.UpdateGeometryLuminosity(view, brush);
                    }
                }
                else if (view != null)
                {
                    parentShape.UpdateGeometryLuminosity(view, brush);
                }
            }
            if (restoreColor.IsEmpty)
            {
                if ((solidBrush ?? (solidBrush = brush as SolidBrush)) != null)
                {
                    restoreColor = solidBrush.Color;
                }
            }
            if (!restoreColor.IsEmpty)
            {
                oldColor = restoreColor;
            }
            return(brush);
        }
Пример #3
0
        /// <summary>
        /// Replacement for BinaryLinkShapeGeometry.DoPaintGeometry
        /// </summary>
        protected override void DoPaintGeometry(DiagramPaintEventArgs e, IGeometryHost geometryHost)
        {
            LinkShape            linkShape;
            IJumpFreeLinkShape   jumpFreeShape;
            VGObjectLineJumpCode expectedJumpCode;

            if (null != (jumpFreeShape = geometryHost as IJumpFreeLinkShape) &&
                null != (linkShape = geometryHost as LinkShape) &&
                linkShape.RouteJumpType != (expectedJumpCode = (jumpFreeShape.IsJumpFree ? VGObjectLineJumpCode.VGObjectJumpCodeNever : VGObjectLineJumpCode.VGObjectJumpCodePage)))
            {
                // Backup plan, sometimes we can't set this during configuration, and
                // it tends to revert in undo/redo scenarios when the backing graph
                // wrapper is not preserved.
                linkShape.RouteJumpType = expectedJumpCode;
            }
            Graphics           g     = e.Graphics;
            GraphicsPath       path  = this.GetPath(geometryHost);
            StyleSetResourceId penId = GetOutlinePenId(geometryHost);
            Pen pen = geometryHost.GeometryStyleSet.GetPen(penId);

            if ((path != null) && (pen != null))
            {
                IDynamicColorGeometryHost dynamicColors = geometryHost as IDynamicColorGeometryHost;
                if (this.HasOutline(geometryHost))
                {
                    Color restoreColor;
                    if (null == (dynamicColors = geometryHost as IDynamicColorGeometryHost) ||
                        (restoreColor = dynamicColors.UpdateDynamicColor(penId, pen)).IsEmpty)
                    {
                        restoreColor = geometryHost.UpdateGeometryLuminosity(e.View, pen);
                    }
                    else
                    {
                        geometryHost.UpdateGeometryLuminosity(e.View, pen);
                    }
                    GeometryUtility.SafeDrawPath(g, pen, path);
                    pen.Color = restoreColor;
                }
                IBinaryLinkGeometryData hostData;
                EdgePointCollection     edgePoints;
                int edgePointCount;
                if (null != (hostData = geometryHost as IBinaryLinkGeometryData) &&
                    null != (edgePoints = hostData.GeometryEdgePoints) &&
                    1 < (edgePointCount = edgePoints.Count))
                {
                    float         rotationAngle = 0f;
                    LinkDecorator decorator;
                    if (null != (decorator = hostData.GeometryDecoratorFrom))
                    {
                        rotationAngle = CalculateRotationAngle(edgePoints[0].Point, edgePoints[1].Point);
                        DrawDecorator(e, geometryHost, rotationAngle, edgePoints[0].Point, decorator
#if VISUALSTUDIO_10_0
                                      , hostData.GeometryDecoratorFromSize
#endif
                                      );
                    }
                    if (null != (decorator = hostData.GeometryDecoratorTo))
                    {
                        rotationAngle = CalculateRotationAngle(edgePoints[edgePointCount - 1].Point, edgePoints[edgePointCount - 2].Point);
                        DrawDecorator(e, geometryHost, rotationAngle, edgePoints[edgePointCount - 1].Point, decorator
#if VISUALSTUDIO_10_0
                                      , hostData.GeometryDecoratorToSize
#endif
                                      );
                    }
                }
            }
        }
        /// <summary>
        /// Copy of <see cref="TextField.DoPaint"/> modified to support the
        /// <see cref="IDynamicColorGeometryHost"/> on the parent shape.
        /// </summary>
        public override void DoPaint(DiagramPaintEventArgs e, ShapeElement parentShape)
        {
            DiagramClientView clientView = e.View;

            if (!HasPendingEdit(parentShape, clientView))
            {
                if (GetVisible(parentShape))
                {
                    string     text     = GetDisplayText(parentShape);
                    StyleSet   styleSet = parentShape.StyleSet;
                    Graphics   g        = e.Graphics;
                    RectangleF clip     = g.ClipBounds;
                    clip.Inflate(InflateFocus, InflateFocus);
                    clip.Height -= InflateFocus;
                    g.SetClip(clip);
                    RectangleD shapeBounds    = GetBounds(parentShape);
                    RectangleF shapeRect      = RectangleD.ToRectangleF(shapeBounds);
                    Matrix     startTransform = null;
                    if (!DefaultIsHorizontal)
                    {
                        PointF point = PointD.ToPointF(shapeBounds.Center);
                        startTransform = g.Transform;
                        Matrix verticalTransform = g.Transform;
                        verticalTransform.RotateAt(-90f, point);
                        verticalTransform.Translate(0f, (-point.X / 2f) - shapeRect.X);
                        g.Transform = verticalTransform;
                    }
                    if (parentShape.ClipWhenDrawingFields)
                    {
                        RectangleD parentBounds = parentShape.BoundingBox;
                        shapeRect.Intersect(new RectangleF(0f, 0f, (float)parentBounds.Width, (float)parentBounds.Height));
                    }
                    if (FillBackground)
                    {
                        Color startColor = Color.White;
                        Brush brush      = GetBackgroundBrush(clientView, parentShape, ref startColor);
                        g.FillRectangle(brush, shapeRect);
                        SolidBrush solidBrush = brush as SolidBrush;
                        if (solidBrush != null)
                        {
                            solidBrush.Color = startColor;
                        }
                    }
                    if (DrawBorder)
                    {
                        Color oldColor = Color.White;
                        Pen   pen      = GetPen(clientView, parentShape, ref oldColor);
                        GeometryUtility.SafeDrawRectangle(g, pen, shapeRect.X, shapeRect.Y, shapeRect.Width, shapeRect.Height);
                        pen.Color = oldColor;
                    }
                    if (text.Length > 0x0)
                    {
                        using (Font font = GetFont(parentShape))
                        {
                            // Note that this ignores the base GetTextBrush, which is trivial
                            // and has no overrides. Note that we follow the convention used with
                            // the base and do not update luminosity on the text.
                            StyleSetResourceId textBrushId = GetTextBrushId(clientView, parentShape);
                            Brush textBrush        = styleSet.GetBrush(textBrushId);
                            Color restoreTextColor = Color.Empty;
                            IDynamicColorGeometryHost dynamicColors = parentShape as IDynamicColorGeometryHost;
                            if (dynamicColors != null)
                            {
                                restoreTextColor = dynamicColors.UpdateDynamicColor(textBrushId, textBrush);
                            }
                            g.DrawString(text, font, textBrush, shapeRect, GetStringFormat(parentShape));
                            SolidBrush solidTextBrush;
                            if (!restoreTextColor.IsEmpty &&
                                null != (solidTextBrush = textBrush as SolidBrush))
                            {
                                solidTextBrush.Color = restoreTextColor;
                            }
                        }
                    }
                    if (HasFocusedAppearance(parentShape, clientView))
                    {
                        // Note that the base makes a copy of shapeRect and
                        // assymetrically modifies the focus rectangle. I don't
                        // think this adds anything and gives focus floating shapes a
                        // focus rectangle that arbitrarily overlaps nearby shapes.
                        //RectangleF focusRect = shapeRect;
                        //focusRect.Inflate(0f, InflateFocus);
                        //focusRect.Height -= InflateFocus;
                        //GeometryUtility.SafeDrawRectangle(g, styleSet.GetPen(DiagramPens.FocusIndicatorBackground), focusRect.X, focusRect.Y, focusRect.Width, focusRect.Height);
                        //GeometryUtility.SafeDrawRectangle(g, styleSet.GetPen(DiagramPens.FocusIndicator), focusRect.X, focusRect.Y, focusRect.Width, focusRect.Height);
                        // UNDONE: The bottom line is drawing clipped. The original code has the same problem
                        // with both the top and bottom lines. This appears to be an issue with the Center
                        // alignment on the default focus indicator pens.
                        shapeRect.Inflate(0f, TextFocusTopPadding);
                        shapeRect.Height -= TextFocusTopPadding - TextFocusBottomPadding;
                        GeometryUtility.SafeDrawRectangle(g, styleSet.GetPen(DiagramPens.FocusIndicatorBackground), shapeRect.X, shapeRect.Y, shapeRect.Width, shapeRect.Height);
                        GeometryUtility.SafeDrawRectangle(g, styleSet.GetPen(DiagramPens.FocusIndicator), shapeRect.X, shapeRect.Y, shapeRect.Width, shapeRect.Height);
                    }
                    if (startTransform != null)
                    {
                        g.Transform = startTransform;
                    }
                }
            }
        }
Пример #5
0
		/// <summary>
		/// Paint the background and outline of a <see cref="IGeometryHost"/> using
		/// dynamic colors provided by the <see cref="IDynamicColorGeometryHost"/> interface.
		/// This is a helper method designed to be called by an override of the <see cref="NodeShapeGeometry.DoPaintGeometry"/> method.
		/// </summary>
		/// <param name="e">The <see cref="DiagramPaintEventArgs"/> passed to DoPaintGeometry</param>
		/// <param name="geometryHost">The <see cref="IGeometryHost"/> passed to DoPaintGeometry</param>
		/// <param name="dynamicColors">The <see cref="IDynamicColorGeometryHost"/> retrieved from the <paramref name="geometryHost"/></param>
		/// <param name="shapeGeometry">The <see cref="ShapeGeometry"/> this is a helper for.</param>
		/// <param name="hasFilledBackground">The result of the <see cref="ShapeGeometry.HasFilledBackground"/> method</param>
		/// <param name="hasOutline">The result of the <see cref="ShapeGeometry.HasOutline"/> method</param>
		/// <remarks>
		/// The DoPaintGeometry override should look similar to
		/// <code>
		/// protected override void DoPaintGeometry(DiagramPaintEventArgs e, IGeometryHost geometryHost)
		/// {
		///     IDynamicColorGeometryHost dynamicColors = geometryHost as IDynamicColorGeometryHost;
		///     if (dynamicColors != null)
		///     {
		///         GeometryUtility.PaintDynamicColorGeometry(e, geometryHost, dynamicColors, this, this.HasFilledBackground(geometryHost), this.HasOutline(geometryHost));
		///     }
		///     else
		///     {
		///         base.DoPaintGeometry(e, geometryHost);
		///     }
		/// }
		/// </code>
		/// </remarks>
		public static void PaintDynamicColorGeometry(DiagramPaintEventArgs e, IGeometryHost geometryHost, IDynamicColorGeometryHost dynamicColors, ShapeGeometry shapeGeometry, bool hasFilledBackground, bool hasOutline)
		{
			if (hasFilledBackground || hasOutline)
			{
				StyleSet geometryStyleSet = geometryHost.GeometryStyleSet;
				GraphicsPath path;
				StyleSetResourceId penId = null;
				Pen pen = null;
				StyleSetResourceId brushId = null;
				Brush brush = null;
				if (null != (path = shapeGeometry.GetPath(geometryHost)) &&
					(!hasFilledBackground || null != (brush = geometryStyleSet.GetBrush(brushId = shapeGeometry.GetBackgroundBrushId(geometryHost)))) &&
					(!hasOutline || null != (pen = geometryStyleSet.GetPen(penId = shapeGeometry.GetOutlinePenId(geometryHost)))))
				{
					Graphics g = e.Graphics;
					DiagramClientView clientView = e.View;
					Color restoreColor;
					if (brush != null)
					{
						restoreColor = Color.Empty;
						if (dynamicColors == null ||
							(restoreColor = dynamicColors.UpdateDynamicColor(brushId, brush)).IsEmpty)
						{
							if (clientView != null)
							{
								restoreColor = geometryHost.UpdateGeometryLuminosity(clientView, brush);
							}
						}
						else if (clientView != null)
						{
							geometryHost.UpdateGeometryLuminosity(clientView, brush);
						}
						g.FillPath(brush, path);
						SolidBrush solidBrush = brush as SolidBrush;
						if (!restoreColor.IsEmpty &&
							null != (solidBrush = brush as SolidBrush))
						{
							solidBrush.Color = restoreColor;
						}
					}
					if (pen != null)
					{
						restoreColor = Color.Empty;
						if (dynamicColors == null ||
							(restoreColor = dynamicColors.UpdateDynamicColor(penId, pen)).IsEmpty)
						{
							if (clientView != null)
							{
								restoreColor = geometryHost.UpdateGeometryLuminosity(clientView, pen);
							}
						}
						else if (clientView != null)
						{
							geometryHost.UpdateGeometryLuminosity(clientView, pen);
						}
						SafeDrawPath(g, pen, path);
						if (!restoreColor.IsEmpty)
						{
							pen.Color = restoreColor;
						}
					}
				}
			}
		}