コード例 #1
0
 public void PaintBorder(
     IGraphics graphics,
     ElementShape shape,
     GraphicsPath clippingPath,
     RectangleF preferedRectangle)
 {
     Color[] gradientColors1 = new Color[4] {
         this.borderElement.ForeColor, this.borderElement.ForeColor2, this.borderElement.ForeColor3, this.borderElement.ForeColor4
     };
     if (this.borderElement.BoxStyle == BorderBoxStyle.OuterInnerBorders)
     {
         float num1 = Math.Max(1f, this.borderElement.Width / 2f);
         this.DrawPath(graphics, clippingPath, preferedRectangle, gradientColors1, num1);
         float        num2       = -(float)Math.Floor((double)Math.Max(1f, num1));
         RectangleF   rectangleF = RectangleF.Inflate(preferedRectangle, num2, num2);
         GraphicsPath path       = shape?.CreatePath(rectangleF);
         if (path == null)
         {
             return;
         }
         Color[] gradientColors2 = new Color[4] {
             this.borderElement.InnerColor, this.borderElement.InnerColor2, this.borderElement.InnerColor3, this.borderElement.InnerColor4
         };
         this.DrawPath(graphics, path, rectangleF, gradientColors2, this.borderElement.Width / 2f);
         path.Dispose();
     }
     else
     {
         if ((double)this.borderElement.Width <= 0.0)
         {
             return;
         }
         this.DrawPath(graphics, clippingPath, preferedRectangle, gradientColors1, this.borderElement.Width);
     }
 }
コード例 #2
0
ファイル: ShapedForm.cs プロジェクト: configare/hispeed
        private void ApplyShape()
        {
            if (this.shape != null)
            {
                if (this.Region != null)
                {
                    this.Region.Dispose();
                }

                if (this.borderPath != null)
                {
                    this.borderPath.Dispose();
                }

                if (this.outerPath != null)
                {
                    this.outerPath.Dispose();
                }

                //there is grd API for creating the round rect region, which should be used only in RoundRectShape case
                if (shape.GetType() == typeof(RoundRectShape))
                {
                    borderPath = this.shape.CreatePath(new RectangleF(0, 0, this.Bounds.Width - 1f, this.Bounds.Height - 1f));
                    outerPath  = shape.CreatePath(new RectangleF(0, 0, this.Bounds.Width, this.Bounds.Height));
                    int shapreRadius = ((RoundRectShape)shape).Radius;
                    int radius;
                    radius = 2 * shapreRadius;

                    this.Region = NativeMethods.CreateRoundRectRgn(new Rectangle(Point.Empty, this.Bounds.Size), radius);
                }
                else
                {
                    borderPath  = this.shape.CreatePath(new RectangleF(0, 0, this.Bounds.Width - 1f, this.Bounds.Height - 1f));
                    outerPath   = shape.CreatePath(new RectangleF(0, 0, this.Bounds.Width, this.Bounds.Height + borderWidth));
                    this.Region = new Region(outerPath);
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Virtual method that paints the primitive on the screen. It may be overriden by
        /// the derived types.
        /// </summary>
        public virtual void PaintBorder(IGraphics graphics, float angle, SizeF scale, RectangleF preferedRectangle)
        {
            Size size = this.primitiveElement.Size;

            if ((size.Width <= 0) || (size.Height <= 0))
            {
                return;
            }

            if (IsTransparent())
            {
                return;
            }

            if (this.borderElement.Width <= 0 &&
                (this.borderElement.BoxStyle != BorderBoxStyle.FourBorders ||
                 (this.borderElement.LeftWidth <= 0 &&
                  this.borderElement.RightWidth <= 0 &&
                  this.borderElement.TopWidth <= 0 &&
                  this.borderElement.BottomWidth <= 0)))
            {
                return;
            }

            ElementShape shape = this.primitiveElement.GetCurrentShape();

            Color[] gradientColors = new Color[]
            {
                this.borderElement.ForeColor, this.borderElement.ForeColor2,
                this.borderElement.ForeColor3, this.borderElement.ForeColor4
            };

            GraphicsPath clippingPath = null;

            if (shape != null)
            {
                clippingPath = shape.CreatePath(preferedRectangle);
            }

            if (clippingPath != null)
            {
                if (this.borderElement.BoxStyle == BorderBoxStyle.OuterInnerBorders)
                {
                    float halfWidth = Math.Max(1f, this.borderElement.Width / 2f);
                    this.DrawPath(graphics, clippingPath, preferedRectangle, gradientColors, halfWidth);

                    float      innerBorderWidth = -(float)Math.Floor(Math.Max(1, halfWidth));
                    RectangleF innerRectangle   = RectangleF.Inflate(preferedRectangle, innerBorderWidth, innerBorderWidth);

                    GraphicsPath innerPath = shape.CreatePath(innerRectangle);
                    if (innerPath != null)
                    {
                        Color[] innerColors = new Color[]
                        {
                            this.borderElement.InnerColor, this.borderElement.InnerColor2,
                            this.borderElement.InnerColor3, this.borderElement.InnerColor4
                        };
                        this.DrawPath(graphics, innerPath, innerRectangle, innerColors, this.borderElement.Width / 2);
                        innerPath.Dispose();
                    }
                }
                else
                {
                    this.DrawPath(graphics, clippingPath, preferedRectangle, gradientColors, this.borderElement.Width);
                }

                clippingPath.Dispose();
            }
            else
            {
                if (this.borderElement.BoxStyle == BorderBoxStyle.OuterInnerBorders)
                {
                    //Rectangle rectangle = new Rectangle(Point.Empty, this.Size);
                    DrawRectangle(graphics, preferedRectangle, gradientColors, this.borderElement.Width);

                    float halfWidth = Math.Max(1f, this.borderElement.Width / 2);

                    Color[] innerColors = new Color[]
                    {
                        this.borderElement.InnerColor, this.borderElement.InnerColor2,
                        this.borderElement.InnerColor3, this.borderElement.InnerColor4
                    };
                    float      innerBorderWidth = -(float)Math.Floor(Math.Max(1, halfWidth));
                    RectangleF newRectangle     = RectangleF.Inflate(preferedRectangle, innerBorderWidth, innerBorderWidth);

                    DrawRectangle(graphics, newRectangle, innerColors, this.borderElement.Width);
                }
                else
                {
                    Rectangle rectangle = Rectangle.Round(preferedRectangle);
                    if (this.borderElement.BoxStyle == BorderBoxStyle.FourBorders)
                    {
                        //Note: Contrary to all other border types, four borders uses FillRectangle and paints exactly
                        //in the specified rectanle, so we need to recalculate
                        rectangle = Rectangle.Round(this.primitiveElement.GetExactPaintingRectangle(angle, scale));
                    }
                    if ((this.borderElement.Width == 1f) && (this.borderElement.BoxStyle == BorderBoxStyle.SingleBorder))
                    {
                        //we do not need this any longer since GetPaintRectangle does this job already
                        //rectangle = GetPatchedRect(graphics, this.Size, angle, scale);
                        if ((rectangle.Width <= 0) || (rectangle.Height <= 0))
                        {
                            return;
                        }
                    }

                    DrawRectangle(graphics, rectangle, gradientColors, this.borderElement.Width);
                }
            }
        }
コード例 #4
0
        public virtual void PaintBorder(
            IGraphics graphics,
            float angle,
            SizeF scale,
            RectangleF preferedRectangle)
        {
            if (this.primitiveElement != null)
            {
                Size size = this.primitiveElement.Size;
                if (size.Width <= 0 || size.Height <= 0)
                {
                    return;
                }
            }
            if (this.IsTransparent() || (double)this.borderElement.Width <= 0.0 && (this.borderElement.BoxStyle != BorderBoxStyle.FourBorders || (double)this.borderElement.LeftWidth <= 0.0 && (double)this.borderElement.RightWidth <= 0.0 && ((double)this.borderElement.TopWidth <= 0.0 && (double)this.borderElement.BottomWidth <= 0.0)))
            {
                return;
            }
            ElementShape shape = (ElementShape)null;

            if (this.primitiveElement != null)
            {
                shape = this.primitiveElement.GetCurrentShape();
            }
            else if (this.shapedElement != null)
            {
                shape = this.shapedElement.GetCurrentShape();
            }
            GraphicsPath clippingPath = (GraphicsPath)null;

            if (shape != null)
            {
                clippingPath = shape.CreatePath(preferedRectangle);
            }
            if (clippingPath != null)
            {
                this.PaintBorder(graphics, shape, clippingPath, preferedRectangle);
                clippingPath.Dispose();
            }
            else
            {
                Color[] gradientColors1 = new Color[4] {
                    this.borderElement.ForeColor, this.borderElement.ForeColor2, this.borderElement.ForeColor3, this.borderElement.ForeColor4
                };
                if (this.borderElement.BoxStyle == BorderBoxStyle.OuterInnerBorders)
                {
                    this.DrawRectangle(graphics, preferedRectangle, gradientColors1, this.borderElement.Width);
                    float   val2            = Math.Max(1f, this.borderElement.Width / 2f);
                    Color[] gradientColors2 = new Color[4] {
                        this.borderElement.InnerColor, this.borderElement.InnerColor2, this.borderElement.InnerColor3, this.borderElement.InnerColor4
                    };
                    float      num       = -(float)Math.Floor((double)Math.Max(1f, val2));
                    RectangleF rectangle = RectangleF.Inflate(preferedRectangle, num, num);
                    this.DrawRectangle(graphics, rectangle, gradientColors2, this.borderElement.Width);
                }
                else
                {
                    Rectangle rectangle = Rectangle.Round(preferedRectangle);
                    if (this.borderElement.BoxStyle == BorderBoxStyle.FourBorders && this.primitiveElement != null)
                    {
                        rectangle = Rectangle.Round(this.primitiveElement.GetExactPaintingRectangle(angle, scale));
                    }
                    if ((double)this.borderElement.Width == 1.0 && this.borderElement.BoxStyle == BorderBoxStyle.SingleBorder && (rectangle.Width <= 0 || rectangle.Height <= 0))
                    {
                        return;
                    }
                    this.DrawRectangle(graphics, (RectangleF)rectangle, gradientColors1, this.borderElement.Width);
                }
            }
        }
コード例 #5
0
        public void PaintFill(IGraphics graphics, float angle, SizeF scale, RectangleF paintRect)
        {
            if (this.IsTransparent())
            {
                return;
            }
            Size desired = Size.Round(paintRect.Size);

            if (desired.Width <= 0 || desired.Height <= 0)
            {
                return;
            }
            graphics.ChangeSmoothingMode(this.fillElement.SmoothingMode);
            this.lastScale = scale;
            ElementShape elementShape = (ElementShape)null;

            if (this.primitiveElement != null)
            {
                elementShape = this.primitiveElement.GetCurrentShape();
            }
            else if (this.shapedElement != null)
            {
                elementShape = this.shapedElement.GetCurrentShape();
            }
            FillElementPaintBuffer elementPaintBuffer = this.FillElementPaintBuffer;

            if (elementShape != null && elementPaintBuffer != null)
            {
                string str       = elementShape.SerializeProperties();
                int    shapeHash = string.IsNullOrEmpty(str) ? elementShape.GetHashCode() : str.GetHashCode();
                elementPaintBuffer.SetShapeHash(shapeHash);
            }
            bool flag = elementPaintBuffer != null && !elementPaintBuffer.IsDisabled && elementPaintBuffer.ShouldUsePaintBuffer() && this.primitiveElement.ShouldUsePaintBuffer();

            try
            {
                if (flag)
                {
                    if (!this.primitiveElement.IsDesignMode && elementPaintBuffer.PaintFromBuffer(graphics, scale, desired))
                    {
                        graphics.RestoreSmoothingMode();
                        return;
                    }
                    graphics.ChangeOpacity(1.0);
                    if (!this.primitiveElement.IsDesignMode)
                    {
                        elementPaintBuffer.SetGraphics(graphics, scale);
                    }
                }
            }
            catch
            {
                flag = false;
            }
            GraphicsPath path = (GraphicsPath)null;

            if (elementShape != null)
            {
                path = elementShape.CreatePath(paintRect);
                graphics.PushCurrentClippingPath(path);
            }
            this.FillRectangle(graphics, paintRect);
            if (path != null)
            {
                graphics.PopCurrentClippingPath();
                path.Dispose();
            }
            if (flag)
            {
                graphics.RestoreOpacity();
                if (!this.primitiveElement.IsDesignMode)
                {
                    elementPaintBuffer.ResetGraphics(graphics, scale);
                }
            }
            graphics.RestoreSmoothingMode();
        }
コード例 #6
0
        public void PaintFill(IGraphics graphics, float angle, SizeF scale, RectangleF paintRect)
        {
            if (this.IsTransparent())
            {
                return;
            }

            Size size = Size.Round(paintRect.Size);

            if ((size.Width <= 0) || (size.Height <= 0))
            {
                return;
            }

            this.lastScale = scale;

            ElementShape currentShape = this.primitiveElement.GetCurrentShape();

            //Check if we have already painded in PaintBuffer with this shape
            FillElementPaintBuffer paintBuffer = this.FillElementPaintBuffer;

            if (currentShape != null && paintBuffer != null)
            {
                string shapeProps = currentShape.SerializeProperties();
                int    shapeHash;
                if (!string.IsNullOrEmpty(shapeProps))
                {
                    shapeHash = shapeProps.GetHashCode();
                }
                else
                {
                    shapeHash = currentShape.GetHashCode();
                }

                paintBuffer.SetShapeHash(shapeHash);
            }

            //Graphics graphics = null;
            bool usePaintBuffer = paintBuffer != null && paintBuffer.ShouldUsePaintBuffer() && this.primitiveElement.ShouldUsePaintBuffer();

            try
            {
                if (usePaintBuffer)
                {
                    if (!this.primitiveElement.IsDesignMode && paintBuffer.PaintFromBuffer(graphics, scale, size))
                    {
                        return;
                    }
                    graphics.ChangeOpacity(1d);
                    if (!this.primitiveElement.IsDesignMode)
                    {
                        paintBuffer.SetGraphics(graphics, scale);
                    }
                }
            }
            catch
            {
                usePaintBuffer = false;
            }

            GraphicsPath clippingPath = null;

            if (currentShape != null)
            {
                clippingPath = currentShape.CreatePath(paintRect);
                graphics.PushCurrentClippingPath(clippingPath);
            }

            this.FillRectangle(graphics, paintRect);

            if (clippingPath != null)
            {
                graphics.PopCurrentClippingPath();
                clippingPath.Dispose();
            }

            if (usePaintBuffer)
            {
                graphics.RestoreOpacity();
                if (!this.primitiveElement.IsDesignMode)
                {
                    paintBuffer.ResetGraphics(graphics, scale);
                }
            }
        }