/// <summary>
        /// Returns the area of the intersection of the two specified <see cref="SKRect"/>.
        /// </summary>
        /// <returns>The area of the intersection.</returns>
        /// <param name="rect1">The first <see cref="SKRect"/>.</param>
        /// <param name="rect2">The second <see cref="SKRect"/>.</param>
        public static float Intersection(SKRect rect1, SKRect rect2)
        {
            var rect = new SKRect(rect1.Left, rect1.Top, rect1.Right, rect1.Bottom);

            rect.Intersect(rect2);
            return(rect.GetArea());
        }
示例#2
0
        public override bool PushClipAreaRect(int width, int height, ref Rectangle updateArea)
        {
            this.clipRectStack.Push(currentClipRect);
            //System.Drawing.Rectangle intersectResult =
            //      System.Drawing.Rectangle.Intersect(
            //      System.Drawing.Rectangle.FromLTRB(updateArea.Left, updateArea.Top, updateArea.Right, updateArea.Bottom),
            //      new System.Drawing.Rectangle(0, 0, width, height));
            SKRect intersectResult = SKRect.Intersect(
                new SKRect(updateArea.Left, updateArea.Top, updateArea.Right, updateArea.Bottom),
                new SKRect(0, 0, width, height));

            currentClipRect = intersectResult;
            if (intersectResult.Width <= 0 || intersectResult.Height <= 0)
            {
                //not intersec?
                return(false);
            }
            else
            {
                updateArea = Conv.ToRect(intersectResult);
                //skCanvas.ClipRect(intersectResult);
                return(true);
            }
        }
示例#3
0
        /// <summary>
        /// Draws chart area cursor and selection.
        /// </summary>
        /// <param name="graph">Reference to the ChartGraphics object.</param>
        internal void Paint(ChartGraphics graph)
        {
            //***************************************************
            //** Prepare for drawing
            //***************************************************

            // Do not proceed with painting if cursor is not attached to the axis
            if (GetAxis() == null ||
                _chartArea == null ||
                _chartArea.Common == null ||
                _chartArea.Common.ChartPicture == null ||
                _chartArea.Common.ChartPicture.isPrinting)
            {
                return;
            }

            // Get plot area position
            SKRect plotAreaPosition = _chartArea.PlotAreaPosition.ToSKRect();

            // Detect if cursor is horizontal or vertical
            bool horizontal = true;

            if (GetAxis().AxisPosition == AxisPosition.Bottom || GetAxis().AxisPosition == AxisPosition.Top)
            {
                horizontal = false;
            }

            //***************************************************
            //** Draw selection
            //***************************************************

            // Check if selection need to be drawn
            if (_drawSelection &&
                !double.IsNaN(SelectionStart) &&
                !double.IsNaN(SelectionEnd) &&
                SelectionColor != SKColor.Empty)
            {
                // Calculate selection rectangle
                SKRect rectSelection = GetSelectionRect(plotAreaPosition);
                rectSelection.Intersect(plotAreaPosition);

                // Get opposite axis selection rectangle
                SKRect rectOppositeSelection = GetOppositeSelectionRect(plotAreaPosition);

                // Draw selection if rectangle is not empty
                if (!rectSelection.IsEmpty && rectSelection.Width > 0 && rectSelection.Height > 0)
                {
                    // Limit selection rectangle to the area of the opposite selection
                    if (!rectOppositeSelection.IsEmpty && rectOppositeSelection.Width > 0 && rectOppositeSelection.Height > 0)
                    {
                        rectSelection.Intersect(rectOppositeSelection);

                        // We do not need to draw selection in the opposite axis
                        Cursor oppositeCursor =
                            (_attachedToXAxis == AxisName.X || _attachedToXAxis == AxisName.X2) ?
                            _chartArea.CursorY : _chartArea.CursorX;
                        oppositeCursor._drawSelection = false;
                    }

                    // Make sure selection is inside plotting area
                    rectSelection.Intersect(plotAreaPosition);

                    // If selection rectangle is not empty
                    if (rectSelection.Width > 0 && rectSelection.Height > 0)
                    {
                        // Add transparency to solid colors
                        var rangeSelectionColor = SelectionColor;
                        if (rangeSelectionColor.Alpha == 255)
                        {
                            rangeSelectionColor = new(rangeSelectionColor.Red, rangeSelectionColor.Green, rangeSelectionColor.Blue, 120);
                        }

                        // Draw selection
                        graph.FillRectangleRel(rectSelection,
                                               rangeSelectionColor,
                                               ChartHatchStyle.None,
                                               "",
                                               ChartImageWrapMode.Tile,
                                               SKColor.Empty,
                                               ChartImageAlignmentStyle.Center,
                                               GradientStyle.None,
                                               SKColor.Empty,
                                               SKColor.Empty,
                                               0,
                                               ChartDashStyle.NotSet,
                                               SKColor.Empty,
                                               0,
                                               PenAlignment.Inset);
                    }
                }
            }

            //***************************************************
            //** Draw cursor
            //***************************************************

            // Check if cursor need to be drawn
            if (!double.IsNaN(Position) &&
                LineColor != SKColor.Empty &&
                LineWidth > 0 &&
                LineDashStyle != ChartDashStyle.NotSet)
            {
                // Calculate line position
                bool    insideArea = false;
                SKPoint point1     = SKPoint.Empty;
                SKPoint point2     = SKPoint.Empty;
                if (horizontal)
                {
                    // Set cursor coordinates
                    point1.X = plotAreaPosition.Left;
                    point1.Y = (float)GetAxis().GetLinearPosition(Position);
                    point2.X = plotAreaPosition.Right;
                    point2.Y = point1.Y;

                    // Check if cursor is inside plotting rect
                    if (point1.Y >= plotAreaPosition.Top && point1.Y <= plotAreaPosition.Bottom)
                    {
                        insideArea = true;
                    }
                }
                else
                {
                    // Set cursor coordinates
                    point1.X = (float)GetAxis().GetLinearPosition(Position);
                    point1.Y = plotAreaPosition.Top;
                    point2.X = point1.X;
                    point2.Y = plotAreaPosition.Bottom;

                    // Check if cursor is inside plotting rect
                    if (point1.X >= plotAreaPosition.Left && point1.X <= plotAreaPosition.Right)
                    {
                        insideArea = true;
                    }
                }

                // Draw cursor if it's inside the chart area plotting rectangle
                if (insideArea)
                {
                    graph.DrawLineRel(LineColor, LineWidth, LineDashStyle, point1, point2);
                }
            }
            // Reset draw selection flag
            _drawSelection = true;
        }