/// <summary> Builds a path figure for a point array. </summary>
        /// <param name="coordinates"> The list of points. </param>
        /// <returns> The path figure. </returns>
        public static PathFigure BuildPathFigure(Point[] coordinates)
        {
            var figure = new PathFigure
            {
                IsFilled   = true,
                IsClosed   = true,
                StartPoint = new Point {
                    X = coordinates[0].X, Y = coordinates[0].Y
                }
            };

            var segments = new PathSegmentCollection {
                new PolyLineSegment {
                    Points = ToSegments(coordinates)
                }
            };

            segments.Freeze();
            figure.Segments = segments;
            figure.Freeze();
            return(figure);
        }
        // Token: 0x060077BC RID: 30652 RVA: 0x00222C78 File Offset: 0x00220E78
        private void DrawBackgound(DrawingContext drawingContext)
        {
            PathGeometry pathGeometry = null;
            int          count        = this._elementsBounds.Count;
            Geometry     geometry;

            if (count != 0)
            {
                for (int i = 0; i < count; i++)
                {
                    Rect rect = this._elementsBounds[i];
                    if (!rect.IsEmpty)
                    {
                        rect.Inflate(3.0, 3.0);
                        if (pathGeometry == null)
                        {
                            PathFigure pathFigure = new PathFigure();
                            pathFigure.StartPoint = new Point(rect.Left, rect.Top);
                            PathSegmentCollection pathSegmentCollection = new PathSegmentCollection();
                            PathSegment           pathSegment           = new LineSegment(new Point(rect.Right, rect.Top), true);
                            pathSegment.Freeze();
                            pathSegmentCollection.Add(pathSegment);
                            pathSegment = new LineSegment(new Point(rect.Right, rect.Bottom), true);
                            pathSegment.Freeze();
                            pathSegmentCollection.Add(pathSegment);
                            pathSegment = new LineSegment(new Point(rect.Left, rect.Bottom), true);
                            pathSegment.Freeze();
                            pathSegmentCollection.Add(pathSegment);
                            pathSegment = new LineSegment(new Point(rect.Left, rect.Top), true);
                            pathSegment.Freeze();
                            pathSegmentCollection.Add(pathSegment);
                            pathSegmentCollection.Freeze();
                            pathFigure.Segments = pathSegmentCollection;
                            pathFigure.IsClosed = true;
                            pathFigure.Freeze();
                            pathGeometry = new PathGeometry();
                            pathGeometry.Figures.Add(pathFigure);
                        }
                        else
                        {
                            geometry = new RectangleGeometry(rect);
                            geometry.Freeze();
                            pathGeometry = Geometry.Combine(pathGeometry, geometry, GeometryCombineMode.Union, null);
                        }
                    }
                }
            }
            GeometryGroup      geometryGroup      = new GeometryGroup();
            GeometryCollection geometryCollection = new GeometryCollection();

            geometry = new RectangleGeometry(new Rect(0.0, 0.0, base.RenderSize.Width, base.RenderSize.Height));
            geometry.Freeze();
            geometryCollection.Add(geometry);
            Geometry geometry2 = null;

            if (pathGeometry != null)
            {
                pathGeometry.Freeze();
                geometry2 = pathGeometry.GetOutlinedPathGeometry();
                geometry2.Freeze();
                if (count == 1 && ((InkCanvasInnerCanvas)base.AdornedElement).InkCanvas.GetSelectedStrokes().Count == 0)
                {
                    geometryCollection.Add(geometry2);
                }
            }
            geometryCollection.Freeze();
            geometryGroup.Children = geometryCollection;
            geometryGroup.Freeze();
            drawingContext.DrawGeometry(Brushes.Transparent, null, geometryGroup);
            if (geometry2 != null)
            {
                drawingContext.DrawGeometry(null, this._hatchPen, geometry2);
            }
        }
        /// <summary>
        /// Draw the hatches and the transparent area where isn't covering the elements.
        /// </summary>
        /// <param name="drawingContext"></param>
        private void DrawBackgound(DrawingContext drawingContext)
        {
            PathGeometry hatchGeometry = null;
            Geometry rectGeometry = null;

            int count = _elementsBounds.Count;
            if ( count != 0 )
            {
                // Create a union collection of the element regions.
                for ( int i = 0; i < count; i++ )
                {
                    Rect hatchRect = _elementsBounds[i];

                    if ( hatchRect.IsEmpty )
                    {
                        continue;
                    }

                    hatchRect.Inflate(HatchBorderMargin / 2, HatchBorderMargin / 2);

                    if ( hatchGeometry == null )
                    {
                        PathFigure path = new PathFigure();
                        path.StartPoint = new Point(hatchRect.Left, hatchRect.Top);

                        PathSegmentCollection segments = new PathSegmentCollection();
                        
                        PathSegment line = new LineSegment(new Point(hatchRect.Right, hatchRect.Top), true); 
                        line.Freeze();
                        segments.Add(line);
                        
                        line = new LineSegment(new Point(hatchRect.Right, hatchRect.Bottom), true); 
                        line.Freeze();
                        segments.Add(line);

                        line = new LineSegment(new Point(hatchRect.Left, hatchRect.Bottom), true);
                        line.Freeze();
                        segments.Add(line);

                        line = new LineSegment(new Point(hatchRect.Left, hatchRect.Top), true);
                        line.Freeze();
                        segments.Add(line);

                        segments.Freeze();
                        path.Segments = segments;

                        path.IsClosed = true;
                        path.Freeze();

                        hatchGeometry = new PathGeometry();
                        hatchGeometry.Figures.Add(path);
                    }
                    else
                    {
                        rectGeometry = new RectangleGeometry(hatchRect);
                        rectGeometry.Freeze();

                        hatchGeometry = Geometry.Combine(hatchGeometry, rectGeometry, GeometryCombineMode.Union, null);
                    }
                }
            }

            // Then, create a region which equals to "SelectionFrame - element1 bounds - element2 bounds - ..."
            GeometryGroup backgroundGeometry = new GeometryGroup( );
            GeometryCollection geometryCollection = new GeometryCollection();

            // Add the entile rectanlge to the group.
            rectGeometry = new RectangleGeometry(new Rect(0, 0, RenderSize.Width, RenderSize.Height));
            rectGeometry.Freeze();
            geometryCollection.Add(rectGeometry);

            // Add the union of the element rectangles. Then the group will do oddeven operation.
            Geometry outlineGeometry = null;

            if ( hatchGeometry != null )
            {
                hatchGeometry.Freeze();

                outlineGeometry = hatchGeometry.GetOutlinedPathGeometry();
                outlineGeometry.Freeze();
                if ( count == 1 && ((InkCanvasInnerCanvas)AdornedElement).InkCanvas.GetSelectedStrokes().Count == 0 )
                {
                    geometryCollection.Add(outlineGeometry);
                }
            }

            geometryCollection.Freeze();
            backgroundGeometry.Children = geometryCollection;
            backgroundGeometry.Freeze();

            // Then, draw the region which may contain holes so that the elements cannot be covered.
            // After that, the underneath elements can receive the messages.
#if DEBUG_OUTPUT
            // Draw the debug feedback
            drawingContext.DrawGeometry(new SolidColorBrush(Color.FromArgb(128, 255, 255, 0)), null, backgroundGeometry);
#else
            drawingContext.DrawGeometry(Brushes.Transparent, null, backgroundGeometry);
#endif

            // At last, draw the hatch borders
            if ( outlineGeometry != null )
            {
                drawingContext.DrawGeometry(null, _hatchPen, outlineGeometry);
            }
        }
Exemple #4
0
        /// <summary>
        /// Draw the hatches and the transparent area where isn't covering the elements.
        /// </summary>
        /// <param name="drawingContext"></param>
        private void DrawBackgound(DrawingContext drawingContext)
        {
            PathGeometry hatchGeometry = null;
            Geometry     rectGeometry  = null;

            int count = _elementsBounds.Count;

            if (count != 0)
            {
                // Create a union collection of the element regions.
                for (int i = 0; i < count; i++)
                {
                    Rect hatchRect = _elementsBounds[i];

                    if (hatchRect.IsEmpty)
                    {
                        continue;
                    }

                    hatchRect.Inflate(HatchBorderMargin / 2, HatchBorderMargin / 2);

                    if (hatchGeometry == null)
                    {
                        PathFigure path = new PathFigure();
                        path.StartPoint = new Point(hatchRect.Left, hatchRect.Top);

                        PathSegmentCollection segments = new PathSegmentCollection();

                        PathSegment line = new LineSegment(new Point(hatchRect.Right, hatchRect.Top), true);
                        line.Freeze();
                        segments.Add(line);

                        line = new LineSegment(new Point(hatchRect.Right, hatchRect.Bottom), true);
                        line.Freeze();
                        segments.Add(line);

                        line = new LineSegment(new Point(hatchRect.Left, hatchRect.Bottom), true);
                        line.Freeze();
                        segments.Add(line);

                        line = new LineSegment(new Point(hatchRect.Left, hatchRect.Top), true);
                        line.Freeze();
                        segments.Add(line);

                        segments.Freeze();
                        path.Segments = segments;

                        path.IsClosed = true;
                        path.Freeze();

                        hatchGeometry = new PathGeometry();
                        hatchGeometry.Figures.Add(path);
                    }
                    else
                    {
                        rectGeometry = new RectangleGeometry(hatchRect);
                        rectGeometry.Freeze();

                        hatchGeometry = Geometry.Combine(hatchGeometry, rectGeometry, GeometryCombineMode.Union, null);
                    }
                }
            }

            // Then, create a region which equals to "SelectionFrame - element1 bounds - element2 bounds - ..."
            GeometryGroup      backgroundGeometry = new GeometryGroup();
            GeometryCollection geometryCollection = new GeometryCollection();

            // Add the entile rectanlge to the group.
            rectGeometry = new RectangleGeometry(new Rect(0, 0, RenderSize.Width, RenderSize.Height));
            rectGeometry.Freeze();
            geometryCollection.Add(rectGeometry);

            // Add the union of the element rectangles. Then the group will do oddeven operation.
            Geometry outlineGeometry = null;

            if (hatchGeometry != null)
            {
                hatchGeometry.Freeze();

                outlineGeometry = hatchGeometry.GetOutlinedPathGeometry();
                outlineGeometry.Freeze();
                if (count == 1 && ((InkCanvasInnerCanvas)AdornedElement).InkCanvas.GetSelectedStrokes().Count == 0)
                {
                    geometryCollection.Add(outlineGeometry);
                }
            }

            geometryCollection.Freeze();
            backgroundGeometry.Children = geometryCollection;
            backgroundGeometry.Freeze();

            // Then, draw the region which may contain holes so that the elements cannot be covered.
            // After that, the underneath elements can receive the messages.
#if DEBUG_OUTPUT
            // Draw the debug feedback
            drawingContext.DrawGeometry(new SolidColorBrush(Color.FromArgb(128, 255, 255, 0)), null, backgroundGeometry);
#else
            drawingContext.DrawGeometry(Brushes.Transparent, null, backgroundGeometry);
#endif

            // At last, draw the hatch borders
            if (outlineGeometry != null)
            {
                drawingContext.DrawGeometry(null, _hatchPen, outlineGeometry);
            }
        }
Exemple #5
0
        private void BuildPathSegments()
        {
            if (SessionItem.PlanItemCollection.LastSampleTime == null)
            {
                return;
            }

            var cpuSegments     = new PathSegmentCollection();
            var waitingSegments = new PathSegmentCollection();
            var idleSegments    = new PathSegmentCollection();

            var executionStart          = SessionItem.PlanItemCollection.ExecutionStart;
            var totalSeconds            = (SessionItem.PlanItemCollection.LastSampleTime.Value - executionStart).TotalSeconds + 1;
            var oneSecondRelativeOffset = 1 / totalSeconds;

            var diagnosticsTooltipBuilder = new StringBuilder();
            var sampleRangeSeconds        = (SessionItem.ActiveSessionHistoryItems.LastOrDefault()?.SampleTime - SessionItem.ActiveSessionHistoryItems.FirstOrDefault()?.SampleTime)?.TotalSeconds;

            diagnosticsTooltipBuilder.AppendLine($"Instance: {SessionItem.SessionIdentifier.Instance}; SID: {SessionItem.SessionIdentifier.SessionId}; execution start: {executionStart}; last sample: {SessionItem.PlanItemCollection.LastSampleTime.Value}; samples: {SessionItem.ActiveSessionHistoryItems.Count}; idle: {(sampleRangeSeconds ?? 0) - SessionItem.ActiveSessionHistoryItems.Count} s");

            var lastCpuActivity     = 1;
            var lastWaitingActivity = 1;
            var x = 0d;
            var lastOffsetSeconds = 0d;
            var index             = 0;

            foreach (var historyItem in SessionItem.ActiveSessionHistoryItems)
            {
                var offsetSeconds = (historyItem.SampleTime - executionStart).TotalSeconds + 1;
                var newX          = offsetSeconds / totalSeconds;
                var hasBeenIdle   = offsetSeconds - lastOffsetSeconds >= 2;
                if (hasBeenIdle)
                {
                    TerminateLastActivity(x, ref lastCpuActivity, cpuSegments);
                    TerminateLastActivity(x, ref lastWaitingActivity, waitingSegments);

                    idleSegments.Add(new LineSegment(new Point(x, 1), false));
                    idleSegments.Add(new LineSegment(new Point(x, 0), false));
                    idleSegments.Add(new LineSegment(new Point(newX - oneSecondRelativeOffset, 0), false));
                    idleSegments.Add(new LineSegment(new Point(newX - oneSecondRelativeOffset, 1), false));
                }

                var cpuActivity     = String.Equals(historyItem.SessionState, "ON CPU") ? 0 : 1;
                var waitingActivity = cpuActivity == 0 ? 1 : 0;
                if (lastCpuActivity != cpuActivity)
                {
                    cpuSegments.Add(new LineSegment(new Point(newX - oneSecondRelativeOffset, lastCpuActivity), false));
                    cpuSegments.Add(new LineSegment(new Point(newX - oneSecondRelativeOffset, cpuActivity), false));
                }

                if (lastWaitingActivity != waitingActivity)
                {
                    waitingSegments.Add(new LineSegment(new Point(newX - oneSecondRelativeOffset, lastWaitingActivity), false));
                    waitingSegments.Add(new LineSegment(new Point(newX - oneSecondRelativeOffset, waitingActivity), false));
                }

                if (hasBeenIdle)
                {
                    diagnosticsTooltipBuilder.AppendLine($"Idle {offsetSeconds - lastOffsetSeconds} s");
                }

                diagnosticsTooltipBuilder.Append($"{++index}. {historyItem.SampleTime} - {historyItem.SessionState}");
                if (cpuActivity == 1)
                {
                    diagnosticsTooltipBuilder.Append($"; event: {historyItem.Event}");
                }

                diagnosticsTooltipBuilder.AppendLine();

                lastCpuActivity     = cpuActivity;
                lastWaitingActivity = waitingActivity;
                lastOffsetSeconds   = offsetSeconds;
                x = newX;
            }

            Diagnostics = diagnosticsTooltipBuilder.ToString();

            TerminateLastActivity(x, ref lastCpuActivity, cpuSegments);
            TerminateLastActivity(x, ref lastWaitingActivity, waitingSegments);

            cpuSegments.Freeze();
            waitingSegments.Freeze();
            idleSegments.Freeze();

            CpuSegments     = cpuSegments;
            WaitingSegments = waitingSegments;
            IdleSegments    = idleSegments;
        }