Exemplo n.º 1
0
        /// <summary>
        /// Draws a marker that represents a data point in FastPoint series.
        /// </summary>
        /// <param name="graph">Chart graphics used to draw the marker.</param>
        /// <param name="point">Series data point drawn.</param>
        /// <param name="pointIndex">Data point index in the series.</param>
        /// <param name="location">Marker location in pixels.</param>
        /// <param name="markerStyle">Marker style.</param>
        /// <param name="markerSize">Marker size in pixels.</param>
        /// <param name="brush">Brush used to fill marker shape.</param>
        /// <param name="borderPen">Marker border pen.</param>
        virtual protected void DrawMarker(
            ChartGraphics graph,
            DataPoint point,
            int pointIndex,
            SKPoint location,
            MarkerStyle markerStyle,
            int markerSize,
            SKPaint brush,
            SKPaint borderPen)
        {
            // Transform 3D coordinates
            if (chartArea3DEnabled)
            {
                Point3D[] points = new Point3D[1];
                location  = graph.GetRelativePoint(location);
                points[0] = new Point3D(location.X, location.Y, seriesZCoordinate);
                matrix3D.TransformPoints(points);
                location.X = points[0].X;
                location.Y = points[0].Y;
                location   = graph.GetAbsolutePoint(location);
            }

            // Create marker bounding rectangle in pixels
            SKRect markerBounds = new(
                location.X - markerSize / 2f, location.Y - markerSize / 2f, markerSize, markerSize);

            // Draw Marker
            switch (markerStyle)
            {
            case (MarkerStyle.Star4):
            case (MarkerStyle.Star5):
            case (MarkerStyle.Star6):
            case (MarkerStyle.Star10):
            {
                // Set number of corners
                int cornerNumber = 4;
                if (markerStyle == MarkerStyle.Star5)
                {
                    cornerNumber = 5;
                }
                else if (markerStyle == MarkerStyle.Star6)
                {
                    cornerNumber = 6;
                }
                else if (markerStyle == MarkerStyle.Star10)
                {
                    cornerNumber = 10;
                }

                // Get star polygon
                SKPoint[] points = ChartGraphics.CreateStarPolygon(markerBounds, cornerNumber);

                // Fill shape
                graph.FillPolygon(brush, points);

                // Draw border
                if (borderPen != null)
                {
                    graph.DrawPolygon(borderPen, points);
                }
                break;
            }

            case (MarkerStyle.Circle):
            {
                graph.FillEllipse(brush, markerBounds);

                // Draw border
                if (borderPen != null)
                {
                    graph.DrawEllipse(borderPen, markerBounds);
                }

                break;
            }

            case (MarkerStyle.Square):
            {
                graph.FillRectangle(brush, markerBounds);

                // Draw border
                if (borderPen != null)
                {
                    graph.DrawRectangle(
                        borderPen,
                        (int)Math.Round(markerBounds.Left, 0),
                        (int)Math.Round(markerBounds.Top, 0),
                        (int)Math.Round(markerBounds.Width, 0),
                        (int)Math.Round(markerBounds.Height, 0));
                }

                break;
            }

            case (MarkerStyle.Cross):
            {
                // Calculate cross line width and size
                float crossLineWidth = (float)Math.Ceiling(markerSize / 4F);
                float crossSize      = markerSize;      // * (float)Math.Sin(45f/180f*Math.PI)

                // Calculate cross coordinates
                SKPoint[] points = new SKPoint[12];
                points[0].X = location.X - crossSize / 2F;
                points[0].Y = location.Y + crossLineWidth / 2F;
                points[1].X = location.X - crossSize / 2F;
                points[1].Y = location.Y - crossLineWidth / 2F;

                points[2].X = location.X - crossLineWidth / 2F;
                points[2].Y = location.Y - crossLineWidth / 2F;
                points[3].X = location.X - crossLineWidth / 2F;
                points[3].Y = location.Y - crossSize / 2F;
                points[4].X = location.X + crossLineWidth / 2F;
                points[4].Y = location.Y - crossSize / 2F;

                points[5].X = location.X + crossLineWidth / 2F;
                points[5].Y = location.Y - crossLineWidth / 2F;
                points[6].X = location.X + crossSize / 2F;
                points[6].Y = location.Y - crossLineWidth / 2F;
                points[7].X = location.X + crossSize / 2F;
                points[7].Y = location.Y + crossLineWidth / 2F;

                points[8].X  = location.X + crossLineWidth / 2F;
                points[8].Y  = location.Y + crossLineWidth / 2F;
                points[9].X  = location.X + crossLineWidth / 2F;
                points[9].Y  = location.Y + crossSize / 2F;
                points[10].X = location.X - crossLineWidth / 2F;
                points[10].Y = location.Y + crossSize / 2F;
                points[11].X = location.X - crossLineWidth / 2F;
                points[11].Y = location.Y + crossLineWidth / 2F;

                // Rotate cross coordinates 45 degrees
                SKMatrix rotationMatrix = SKMatrix.CreateRotationDegrees(45, location.X, location.Y);
                rotationMatrix.TransformPoints(points);

                // Fill shape
                graph.FillPolygon(brush, points);

                // Draw border
                if (borderPen != null)
                {
                    graph.DrawPolygon(borderPen, points);
                }
                break;
            }

            case (MarkerStyle.Diamond):
            {
                SKPoint[] points = new SKPoint[4];
                points[0].X = markerBounds.Left;
                points[0].Y = markerBounds.Top + markerBounds.Height / 2F;
                points[1].X = markerBounds.Left + markerBounds.Width / 2F;
                points[1].Y = markerBounds.Top;
                points[2].X = markerBounds.Right;
                points[2].Y = markerBounds.Top + markerBounds.Height / 2F;
                points[3].X = markerBounds.Left + markerBounds.Width / 2F;
                points[3].Y = markerBounds.Bottom;

                graph.FillPolygon(brush, points);

                // Draw border
                if (borderPen != null)
                {
                    graph.DrawPolygon(borderPen, points);
                }
                break;
            }

            case (MarkerStyle.Triangle):
            {
                SKPoint[] points = new SKPoint[3];
                points[0].X = markerBounds.Left;
                points[0].Y = markerBounds.Bottom;
                points[1].X = markerBounds.Top + markerBounds.Width / 2F;
                points[1].Y = markerBounds.Top;
                points[2].X = markerBounds.Right;
                points[2].Y = markerBounds.Bottom;

                graph.FillPolygon(brush, points);

                // Draw border
                if (borderPen != null)
                {
                    graph.DrawPolygon(borderPen, points);
                }
                break;
            }

            default:
            {
                throw (new InvalidOperationException(SR.ExceptionFastPointMarkerStyleUnknown));
            }
            }

            // Process selection regions
            if (Common.ProcessModeRegions)
            {
                Common.HotRegionsList.AddHotRegion(
                    graph.GetRelativeRectangle(markerBounds),
                    point,
                    point.series.Name,
                    pointIndex);
            }
        }
Exemplo n.º 2
0
        /// <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();
        }
Exemplo n.º 3
0
        /// <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();
        }