Exemplo n.º 1
0
            /// <summary>
            /// Initialize paint settings. This is initialized after the base shape
            /// has been painted.
            /// </summary>
            public PaintHelper(DiagramPaintEventArgs e, ExternalConstraintShape constraintShape)
            {
                StyleSet           styleSet = constraintShape.StyleSet;
                StyleSetResourceId penId    = constraintShape.OutlinePenId;
                Pen        pen          = styleSet.GetPen(penId);
                Brush      brush        = styleSet.GetBrush(ExternalConstraintBrush);
                SolidBrush coloredBrush = brush as SolidBrush;

                // Keep the pen color in sync with the color being used for highlighting
                Color startColor = constraintShape.UpdateDynamicColor(constraintShape.OutlinePenId, pen);

                if (startColor.IsEmpty)
                {
                    startColor = constraintShape.UpdateGeometryLuminosity(e.View, pen);
                }
                else
                {
                    constraintShape.UpdateGeometryLuminosity(e.View, pen);
                }
                myPenStartColor = startColor;
                Color newColor = pen.Color;

                if (coloredBrush != null)
                {
                    myBrushStartColor  = coloredBrush.Color;
                    coloredBrush.Color = newColor;
                }
                else
                {
                    myBrushStartColor = Color.Empty;
                }
                myBrush = brush;
                myPen   = pen;
            }
        private void AdjustForFillColor()
        {
            dynamic brush = StyleSet.GetBrush(DiagramBrushes.ShapeBackground);

            // If the shape is very dark, we make the title text white, and viceversa.
            StyleSet.OverrideBrushColor(DiagramBrushes.ShapeText, CachedFillColorAppearance((Color)brush.Color).TextColor);
            // We draw a thin outline of a sligtly different color to improve distinguishability when shape color looks like background (and because it looks good).
            StyleSet.OverridePenColor(OutlinePenId, CachedFillColorAppearance((Color)brush.Color).OutlineColor);
            // We shouldn't need to do this again unless the user changes the color for this shape.
            _isAdjustedForFillColor = true;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Add error brushes to the styleSet
        /// </summary>
        protected override void InitializeResources(StyleSet classStyleSet)
        {
            base.InitializeResources(classStyleSet);

            IORMFontAndColorService colorService  = (Store as IORMToolServices).FontAndColorService;
            BrushSettings           brushSettings = new BrushSettings();

            //UNDONE: This color isn't permanent. probably want a better color for the errors.
            brushSettings.ForeColor = Color.LightPink;
            //brushSettings.ForeColor = colorService.GetForeColor(ORMDesignerColor.ConstraintError);
            brushSettings.HatchStyle = HatchStyle.LightDownwardDiagonal;
            brushSettings.BrushType  = typeof(HatchBrush);
            classStyleSet.AddBrush(ORMDiagram.ErrorBackgroundResource, DiagramBrushes.DiagramBackground, brushSettings);
            brushSettings.ForeColor = ORMDiagram.ModifyLuminosity(brushSettings.ForeColor);
            brushSettings.BackColor = ORMDiagram.ModifyLuminosity(((SolidBrush)classStyleSet.GetBrush(DiagramBrushes.DiagramBackground)).Color);
            classStyleSet.AddBrush(ORMDiagram.HighlightedErrorBackgroundResource, DiagramBrushes.DiagramBackground, brushSettings);

            BrushSettings transBrush = new BrushSettings();

            transBrush.ForeColor = Color.Transparent;
            classStyleSet.AddBrush(ORMDiagram.TransparentBrushResource, DiagramBrushes.DiagramBackground, transBrush);
        }
        /// <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);
        }
        /// <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;
                    }
                }
            }
        }
Exemplo n.º 6
0
		/// <summary>
		/// Add error brushes to the styleSet
		/// </summary>
		protected override void InitializeResources(StyleSet classStyleSet)
		{
			base.InitializeResources(classStyleSet);

			IORMFontAndColorService colorService = (Store as IORMToolServices).FontAndColorService;
			BrushSettings brushSettings = new BrushSettings();
			//UNDONE: This color isn't permanent. probably want a better color for the errors.
			brushSettings.ForeColor = Color.LightPink;
			//brushSettings.ForeColor = colorService.GetForeColor(ORMDesignerColor.ConstraintError);
			brushSettings.HatchStyle = HatchStyle.LightDownwardDiagonal;
			brushSettings.BrushType = typeof(HatchBrush);
			classStyleSet.AddBrush(ORMDiagram.ErrorBackgroundResource, DiagramBrushes.DiagramBackground, brushSettings);
			brushSettings.ForeColor = ORMDiagram.ModifyLuminosity(brushSettings.ForeColor);
			brushSettings.BackColor = ORMDiagram.ModifyLuminosity(((SolidBrush)classStyleSet.GetBrush(DiagramBrushes.DiagramBackground)).Color);
			classStyleSet.AddBrush(ORMDiagram.HighlightedErrorBackgroundResource, DiagramBrushes.DiagramBackground, brushSettings);

			BrushSettings transBrush = new BrushSettings();
			transBrush.ForeColor = Color.Transparent;
			classStyleSet.AddBrush(ORMDiagram.TransparentBrushResource, DiagramBrushes.DiagramBackground, transBrush);
		}