/// <summary> /// Default public constructor. /// </summary> public Border3DAnnotation() : base() { isRectVisible = false; _borderSkin = new BorderSkin(this) { PageColor = SKColors.Transparent, SkinStyle = BorderSkinStyle.Raised }; // Change default appearance styles lineColor = SKColor.Empty; }
/// <summary> /// Draws 3D border. /// </summary> /// <param name="graph">Graphics to draw the border on.</param> /// <param name="borderSkin">Border skin object.</param> /// <param name="rect">Rectangle of the border.</param> /// <param name="backColor">Color of rectangle</param> /// <param name="backHatchStyle">Hatch style</param> /// <param name="backImage">Back Image</param> /// <param name="backImageWrapMode">Image mode</param> /// <param name="backImageTransparentColor">Image transparent color.</param> /// <param name="backImageAlign">Image alignment</param> /// <param name="backGradientStyle">Gradient type</param> /// <param name="backSecondaryColor">Gradient End Color</param> /// <param name="borderColor">Border Color</param> /// <param name="borderWidth">Border Width</param> /// <param name="borderDashStyle">Border Style</param> public virtual void DrawBorder( ChartGraphics graph, BorderSkin borderSkin, SKRect rect, SKColor backColor, ChartHatchStyle backHatchStyle, string backImage, ChartImageWrapMode backImageWrapMode, SKColor backImageTransparentColor, ChartImageAlignmentStyle backImageAlign, GradientStyle backGradientStyle, SKColor backSecondaryColor, SKColor borderColor, int borderWidth, ChartDashStyle borderDashStyle) { SKRect absolute = ChartGraphics.Round(rect); // Calculate shadow colors (0.2 - 0.6) float colorDarkeningIndex = 0.2f + (0.4f * (borderSkin.PageColor.Red + borderSkin.PageColor.Green + borderSkin.PageColor.Blue) / 765f); SKColor shadowColor = new( (byte)(borderSkin.PageColor.Red * colorDarkeningIndex), (byte)(borderSkin.PageColor.Green * colorDarkeningIndex), (byte)(borderSkin.PageColor.Blue * colorDarkeningIndex)); if (borderSkin.PageColor == SKColors.Transparent) { shadowColor = new(0, 0, 0, 60); } colorDarkeningIndex += 0.2f; SKColor shadowLightColor = new( (byte)(borderSkin.PageColor.Red * colorDarkeningIndex), (byte)(borderSkin.PageColor.Green * colorDarkeningIndex), (byte)(borderSkin.PageColor.Blue * colorDarkeningIndex)); // Calculate rounded rect radius float radius = defaultRadiusSize; radius = Math.Max(radius, 2f * resolution / 96.0f); radius = Math.Min(radius, rect.Width / 2f); radius = Math.Min(radius, rect.Height / 2f); radius = (float)Math.Ceiling(radius); // Fill page background color using (SKPaint brush = new() { Style = SKPaintStyle.Fill, Color = borderSkin.PageColor }) { graph.FillRectangle(brush, rect); } // Top/Left shadow SKRect shadowRect = absolute; shadowRect.Right -= radius * .3f; shadowRect.Bottom -= radius * .3f; graph.DrawRoundedRectShadowAbs(shadowRect, cornerRadius, radius + 1 * resolution / 96.0f, shadowLightColor, borderSkin.PageColor, 1.4f); // Bottom/Right shadow shadowRect = absolute; shadowRect.Left = absolute.Left + radius / 3f; shadowRect.Top = absolute.Top + radius / 3f; shadowRect.Right -= radius / 3.5f; shadowRect.Bottom -= radius / 3.5f; graph.DrawRoundedRectShadowAbs(shadowRect, cornerRadius, radius, shadowColor, borderSkin.PageColor, 1.3f); // Draw Background shadowRect = absolute; shadowRect.Left = absolute.Left + 3f * resolution / 96.0f; shadowRect.Top = absolute.Top + 3f * resolution / 96.0f; shadowRect.Right -= radius * .75f; shadowRect.Bottom -= radius * .75f; SKPath path = ChartGraphics.CreateRoundedRectPath(shadowRect, cornerRadius); graph.DrawPathAbs( path, backColor, backHatchStyle, backImage, backImageWrapMode, backImageTransparentColor, backImageAlign, backGradientStyle, backSecondaryColor, borderColor, borderWidth, borderDashStyle, PenAlignment.Inset); // Dispose Graphic path if (path != null) { path.Dispose(); } // Bottom/Right inner shadow SKRegion innerShadowRegion = new( ChartGraphics.CreateRoundedRectPath( new SKRect( shadowRect.Left - radius, shadowRect.Top - radius, shadowRect.Width + radius - radius * 0.25f, shadowRect.Height + radius - radius * 0.25f), cornerRadius)); innerShadowRegion.Op(ChartGraphics.CreateRoundedRectPath(shadowRect, cornerRadius), SKRegionOperation.Difference); graph.Clip = innerShadowRegion; graph.DrawRoundedRectShadowAbs( shadowRect, cornerRadius, radius, SKColors.Transparent, new(SKColors.Gray.Red, SKColors.Gray.Green, SKColors.Gray.Blue, 128), .5f); graph.Clip = new(); }
/// <summary> /// Draws 3D border /// </summary> /// <param name="graph">Graphics to draw the border on.</param> /// <param name="borderSkin">Border skin object.</param> /// <param name="rect">Rectangle of the border.</param> /// <param name="backColor">Color of rectangle</param> /// <param name="backHatchStyle">Hatch style</param> /// <param name="backImage">Back Image</param> /// <param name="backImageWrapMode">Image mode</param> /// <param name="backImageTransparentColor">Image transparent color.</param> /// <param name="backImageAlign">Image alignment</param> /// <param name="backGradientStyle">Gradient type</param> /// <param name="backSecondaryColor">Gradient End Color</param> /// <param name="borderColor">Border Color</param> /// <param name="borderWidth">Border Width</param> /// <param name="borderDashStyle">Border Style</param> public virtual void DrawBorder( ChartGraphics graph, BorderSkin borderSkin, SKRect rect, SKColor backColor, ChartHatchStyle backHatchStyle, string backImage, ChartImageWrapMode backImageWrapMode, SKColor backImageTransparentColor, ChartImageAlignmentStyle backImageAlign, GradientStyle backGradientStyle, SKColor backSecondaryColor, SKColor borderColor, int borderWidth, ChartDashStyle borderDashStyle) { SKRect absolute = ChartGraphics.Round(rect); // Calculate shadow colors (0.2 - 0.6) float colorDarkeningIndex = 0.3f + (0.4f * (borderSkin.PageColor.Red + borderSkin.PageColor.Green + borderSkin.PageColor.Blue) / 765f); SKColor shadowColor = new( (byte)(backColor.Red * colorDarkeningIndex), (byte)(backColor.Green * colorDarkeningIndex), (byte)(backColor.Blue * colorDarkeningIndex)); colorDarkeningIndex += 0.2f; SKColor shadowLightColor = new( (byte)(borderSkin.PageColor.Red * colorDarkeningIndex), (byte)(borderSkin.PageColor.Green * colorDarkeningIndex), (byte)(borderSkin.PageColor.Blue * colorDarkeningIndex)); if (borderSkin.PageColor == SKColors.Transparent) { shadowLightColor = new SKColor(0, 0, 0, 60); } // Calculate rounded rect radius float radius = defaultRadiusSize; radius = Math.Max(radius, 2f * resolution / 96.0f); radius = Math.Min(radius, rect.Width / 2f); radius = Math.Min(radius, rect.Height / 2f); radius = (float)Math.Ceiling(radius); // Fill page background color using (SKPaint brush = new() { Color = borderSkin.PageColor, Style = SKPaintStyle.Fill }) { graph.FillRectangle(brush, rect); } SKRect shadowRect; if (drawOutsideTopLeftShadow) { // Top/Left outside shadow shadowRect = absolute; shadowRect.Left -= radius * 0.3f; shadowRect.Top -= radius * 0.3f; shadowRect.Right -= radius * .3f; shadowRect.Bottom -= radius * .3f; graph.DrawRoundedRectShadowAbs(shadowRect, cornerRadius, radius, Color.FromArgb(128, SKColors.Black), borderSkin.PageColor, outsideShadowRate); } // Bottom/Right outside shadow shadowRect = absolute; shadowRect.Left += radius * 0.3f; shadowRect.Top += radius * 0.3f; shadowRect.Right -= radius * .3f; shadowRect.Bottom -= radius * .3f; graph.DrawRoundedRectShadowAbs(shadowRect, cornerRadius, radius, shadowLightColor, borderSkin.PageColor, outsideShadowRate); // Background shadowRect = absolute; shadowRect.Right -= radius * .3f; shadowRect.Bottom -= radius * .3f; SKPath path = ChartGraphics.CreateRoundedRectPath(shadowRect, cornerRadius); graph.DrawPathAbs( path, backColor, backHatchStyle, backImage, backImageWrapMode, backImageTransparentColor, backImageAlign, backGradientStyle, backSecondaryColor, borderColor, borderWidth, borderDashStyle, PenAlignment.Inset); // Dispose Graphic path if (path != null) { path.Dispose(); } // Draw screws imitation in the corners of the farame if (drawScrews) { // Left/Top screw SKRect screwRect = SKRect.Empty; float offset = radius * 0.4f; screwRect.Left = shadowRect.Left + offset; screwRect.Top = shadowRect.Top + offset; screwRect.Size = new(radius * 0.55f, screwRect.Width); DrawScrew(graph, screwRect); // Right/Top screw screwRect.Left = shadowRect.Right - offset - screwRect.Width; DrawScrew(graph, screwRect); // Right/Bottom screw screwRect.Left = shadowRect.Right - offset - screwRect.Width; screwRect.Top = shadowRect.Bottom - offset - screwRect.Height; DrawScrew(graph, screwRect); // Left/Bottom screw screwRect.Left = shadowRect.Left + offset; screwRect.Top = shadowRect.Bottom - offset - screwRect.Height; DrawScrew(graph, screwRect); } // Bottom/Right inner shadow SKRegion innerShadowRegion; if (drawBottomShadow) { shadowRect = absolute; shadowRect.Right -= radius * .3f; shadowRect.Bottom -= radius * .3f; innerShadowRegion = new SKRegion( ChartGraphics.CreateRoundedRectPath( new SKRect( shadowRect.Left - radius, shadowRect.Top - radius, shadowRect.Width + 0.5f * radius, shadowRect.Height + 0.5f * radius), cornerRadius)); // TODO: innerShadowRegion.Complement(graph.CreateRoundedRectPath(shadowRect, cornerRadius)); graph.Clip = innerShadowRegion; shadowRect.Left -= 0.5f * radius; shadowRect.Top -= 0.5f * radius; shadowRect.Right += 0.5f * radius; shadowRect.Bottom += 0.5f * radius; graph.DrawRoundedRectShadowAbs( shadowRect, cornerRadius, radius, SKColors.Transparent, Color.FromArgb(175, (sunken) ? SKColors.White : shadowColor), 1.0f); graph.Clip = new SKRegion(); } // Top/Left inner shadow shadowRect = absolute; shadowRect.Right -= radius * .3f; shadowRect.Bottom -= radius * .3f; innerShadowRegion = new( ChartGraphics.CreateRoundedRectPath( new SKRect( shadowRect.Left + radius * .5f, shadowRect.Top + radius * .5f, shadowRect.Width - .2f * radius, shadowRect.Height - .2f * radius), cornerRadius)); SKRect shadowWithOffset = shadowRect; shadowWithOffset.Right += radius; shadowWithOffset.Bottom += radius; // TODO: innerShadowRegion.Complement(graph.CreateRoundedRectPath(shadowWithOffset, cornerRadius)); innerShadowRegion.SetPath(ChartGraphics.CreateRoundedRectPath(shadowRect, cornerRadius), innerShadowRegion); graph.Clip = innerShadowRegion; graph.DrawRoundedRectShadowAbs( shadowWithOffset, cornerRadius, radius, SKColors.Transparent, Color.FromArgb(175, (sunken) ? shadowColor : SKColors.White), 1.0f); graph.Clip = new(); }
/// <summary> /// Draws 3D border. /// </summary> /// <param name="graph">Graphics to draw the border on.</param> /// <param name="borderSkin">Border skin object.</param> /// <param name="rect">Rectangle of the border.</param> /// <param name="backColor">Color of rectangle</param> /// <param name="backHatchStyle">Hatch style</param> /// <param name="backImage">Back Image</param> /// <param name="backImageWrapMode">Image mode</param> /// <param name="backImageTransparentColor">Image transparent color.</param> /// <param name="backImageAlign">Image alignment</param> /// <param name="backGradientStyle">Gradient type</param> /// <param name="backSecondaryColor">Gradient End Color</param> /// <param name="borderColor">Border Color</param> /// <param name="borderWidth">Border Width</param> /// <param name="borderDashStyle">Border Style</param> public override void DrawBorder( ChartGraphics graph, BorderSkin borderSkin, SKRect rect, SKColor backColor, ChartHatchStyle backHatchStyle, string backImage, ChartImageWrapMode backImageWrapMode, SKColor backImageTransparentColor, ChartImageAlignmentStyle backImageAlign, GradientStyle backGradientStyle, SKColor backSecondaryColor, SKColor borderColor, int borderWidth, ChartDashStyle borderDashStyle) { drawBottomShadow = true; sunken = false; outsideShadowRate = .9f; drawOutsideTopLeftShadow = false; bool oldScrewsFlag = drawScrews; drawScrews = false; base.DrawBorder( graph, borderSkin, rect, borderSkin.BackColor, borderSkin.BackHatchStyle, borderSkin.BackImage, borderSkin.BackImageWrapMode, borderSkin.BackImageTransparentColor, borderSkin.BackImageAlignment, borderSkin.BackGradientStyle, borderSkin.BackSecondaryColor, borderSkin.BorderColor, borderSkin.BorderWidth, borderSkin.BorderDashStyle); drawScrews = oldScrewsFlag; rect.Left += sizeLeftTop.Width; rect.Top += sizeLeftTop.Height; rect.Right -= sizeRightBottom.Width + sizeLeftTop.Width; rect.Bottom -= sizeRightBottom.Height + sizeLeftTop.Height; if (rect.Width > 0 && rect.Height > 0) { float[] oldCorners = (float[])cornerRadius.Clone(); cornerRadius = innerCorners; drawBottomShadow = false; sunken = true; drawOutsideTopLeftShadow = true; outsideShadowRate = 1.4f; SKColor oldPageColor = borderSkin.PageColor; borderSkin.PageColor = SKColors.Transparent; base.DrawBorder( graph, borderSkin, rect, backColor, backHatchStyle, backImage, backImageWrapMode, backImageTransparentColor, backImageAlign, backGradientStyle, backSecondaryColor, borderColor, borderWidth, borderDashStyle); borderSkin.PageColor = oldPageColor; cornerRadius = oldCorners; } }