예제 #1
0
 protected override void OnRender(DrawingContext dc)
 {
     base.OnRender(dc);
     dc.DrawGeometry(null, drawingPen, this.pathGeometry);
 }
예제 #2
0
            //
            // Render
            //
            protected override void OnRender(DrawingContext context)
            {
                PathFigure   path;
                PathGeometry geometry;

                // Pressure bars
                rectInputPressure.Width  = PressureInput * rectInputPressureBorder.Width;
                rectOutputPressure.Width = PressureOutput * rectInputPressureBorder.Width;
                context.DrawRectangle(brushInput, null, rectInputPressure);
                context.DrawRectangle(brushOutput, null, rectOutputPressure);
                context.DrawRectangle(null, penInputPressure, rectInputPressureBorder);
                context.DrawRectangle(null, penOutputPressure, rectOutputPressureBorder);

                //
                // Drawing line
                //
                if (DrawPositions.Length > 0)
                {
                    path = new PathFigure
                    {
                        StartPoint = DrawPositions[0]
                    };
                    for (int i = 1; i < DrawPositions.Length; i++)
                    {
                        // Last empty
                        if (DrawPositions[i].X >= 0 && DrawPositions[i - 1].X <= 0)
                        {
                            path.Segments.Add(new LineSegment(DrawPositions[i], false));
                            path.Segments.Add(new LineSegment(DrawPositions[i], true));
                        }
                        // Current and last OK
                        else if (DrawPositions[i].X >= 0 && DrawPositions[i - 1].X >= 0)
                        {
                            path.Segments.Add(new LineSegment(DrawPositions[i], true));
                        }

                        // Current and last empty
                        else
                        {
                            path.Segments.Add(new LineSegment(DrawPositions[i], false));
                        }
                    }
                    path.Freeze();
                    geometry = new PathGeometry();
                    geometry.Figures.Add(path);
                    geometry.Freeze();
                    context.DrawGeometry(null, penDrawLine, geometry);
                }

                //
                // Input line
                //
                if (LastPositionsInput.Length > 0)
                {
                    path = new PathFigure
                    {
                        StartPoint = LastPositionsInput[0]
                    };
                    for (int i = 1; i < LastPositionsInput.Length; i++)
                    {
                        path.Segments.Add(new LineSegment(LastPositionsInput[i], true));
                    }
                    path.Freeze();
                    geometry = new PathGeometry();
                    geometry.Figures.Add(path);
                    geometry.Freeze();
                    context.DrawGeometry(null, penInputLine, geometry);
                }


                //
                // Output line
                //
                if (LastPositionsOutput.Length > 0)
                {
                    path = new PathFigure
                    {
                        IsClosed   = false,
                        IsFilled   = false,
                        StartPoint = LastPositionsOutput[0]
                    };
                    for (int i = 1; i < LastPositionsOutput.Length; i++)
                    {
                        path.Segments.Add(new LineSegment(LastPositionsOutput[i], true));
                    }
                    path.Freeze();
                    geometry = new PathGeometry();
                    geometry.Figures.Add(path);
                    geometry.Freeze();
                    context.DrawGeometry(null, penOutputLine, geometry);
                }

                // Input circle
                context.DrawEllipse(null, penInputCircle, PositionInput, 12, 12);

                // Output circle
                context.DrawEllipse(null, penOutputCircle, PositionOutput, 12, 12);
            }
 protected override void OnRender(DrawingContext drawingContext)
 {
     base.OnRender(drawingContext);
     drawingContext.DrawGeometry(BackgroundBrush, Pen, geometry);
 }
예제 #4
0
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (textView == null)
            {
                throw new ArgumentNullException("textView");
            }
            if (drawingContext == null)
            {
                throw new ArgumentNullException("drawingContext");
            }
            if (markers == null || !textView.VisualLinesValid)
            {
                return;
            }
            var visualLines = textView.VisualLines;

            if (visualLines.Count == 0)
            {
                return;
            }
            int viewStart = visualLines.First().FirstDocumentLine.Offset;
            int viewEnd   = visualLines.Last().LastDocumentLine.EndOffset;

            foreach (TextMarker marker in markers.FindOverlappingSegments(viewStart, viewEnd - viewStart))
            {
                if (marker.BackgroundColor != null)
                {
                    BackgroundGeometryBuilder geoBuilder = new BackgroundGeometryBuilder();
                    geoBuilder.AlignToWholePixels = true;
                    geoBuilder.CornerRadius       = 3;
                    geoBuilder.AddSegment(textView, marker);
                    Geometry geometry = geoBuilder.CreateGeometry();
                    if (geometry != null)
                    {
                        Color           color = marker.BackgroundColor.Value;
                        SolidColorBrush brush = new SolidColorBrush(color);
                        brush.Freeze();
                        drawingContext.DrawGeometry(brush, null, geometry);
                    }
                }
                var underlineMarkerTypes = TextMarkerTypes.SquigglyUnderline | TextMarkerTypes.NormalUnderline | TextMarkerTypes.DottedUnderline;
                if ((marker.MarkerTypes & underlineMarkerTypes) != 0)
                {
                    foreach (Rect r in BackgroundGeometryBuilder.GetRectsForSegment(textView, marker))
                    {
                        Point startPoint = r.BottomLeft;
                        Point endPoint   = r.BottomRight;

                        Brush usedBrush = new SolidColorBrush(marker.MarkerColor);
                        usedBrush.Freeze();
                        if ((marker.MarkerTypes & TextMarkerTypes.SquigglyUnderline) != 0)
                        {
                            double offset = 2.5;

                            int count = Math.Max((int)((endPoint.X - startPoint.X) / offset) + 1, 4);

                            StreamGeometry geometry = new StreamGeometry();

                            using (StreamGeometryContext ctx = geometry.Open())
                            {
                                ctx.BeginFigure(startPoint, false, false);
                                ctx.PolyLineTo(CreatePoints(startPoint, endPoint, offset, count).ToArray(), true, false);
                            }

                            geometry.Freeze();

                            Pen usedPen = new Pen(usedBrush, 1);
                            usedPen.Freeze();
                            drawingContext.DrawGeometry(Brushes.Transparent, usedPen, geometry);
                        }
                        if ((marker.MarkerTypes & TextMarkerTypes.NormalUnderline) != 0)
                        {
                            Pen usedPen = new Pen(usedBrush, 1);
                            usedPen.Freeze();
                            drawingContext.DrawLine(usedPen, startPoint, endPoint);
                        }
                        if ((marker.MarkerTypes & TextMarkerTypes.DottedUnderline) != 0)
                        {
                            Pen usedPen = new Pen(usedBrush, 1);
                            usedPen.DashStyle = DashStyles.Dot;
                            usedPen.Freeze();
                            drawingContext.DrawLine(usedPen, startPoint, endPoint);
                        }
                    }
                }
            }
        }
예제 #5
0
        public void zRender(DrawingContext context, Size size, Thickness depth, Thickness extent, CornerRadius radii, Color bg)
        {
            /*context.FillRectangle(new SolidColorBrush(Colors.LightSkyBlue), new Rect(size));
             * var blue = new SolidColorBrush(Colors.GreenYellow);
             * //double totalInset = depth;
             * context.FillRectangle(blue, new Rect(0, 0, , totalInset));
             * totalInset = radii.TopRight + depth;
             * context.FillRectangle(blue, new Rect(size.Width - totalInset, 0, totalInset, totalInset));*/
            var   backgroundGeometry = _middleCenterGeometryCache;
            Color bgTrans            = new Color(0, bg.R, bg.G, bg.B);

            GradientStops stops = new GradientStops()
            {
                new GradientStop(bg, 0),
                new GradientStop(bgTrans, 1)
            };

            if (backgroundGeometry != null)
            {
                context.DrawGeometry(new SolidColorBrush(bg), null, backgroundGeometry);
            }
            ;

            RelativePoint tlOrigin = new RelativePoint(extent.Left /* + radii.TopLeft*/, extent.Top /* + radii.TopLeft*//*radii.TopLeft + depth.Left, radii.TopLeft + depth.Top*/, RelativeUnit.Absolute);
            //double innerStopPos = radii.TopLeft / (depth.Left + radii.TopLeft);
            double radius = ((depth.Left - radii.TopLeft) + (depth.Top - radii.TopLeft)) / 2;

            context.DrawGeometry(new RadialGradientBrush()
            {
                Center         = tlOrigin,
                GradientOrigin = tlOrigin,
                Radius         = (depth.Top / (extent.Top + radii.TopLeft)),

                GradientStops = new GradientStops()
                {
                    new GradientStop(bg, 0),
                    new GradientStop(bgTrans, 1 /*2.0 / 3.0*/)
                }
            }, null, _topLeftGeometryCache);

            context.DrawGeometry(new LinearGradientBrush()
            {
                GradientStops = stops,
                StartPoint    = new RelativePoint(0, 1, RelativeUnit.Relative),
                EndPoint      = new RelativePoint(0, 0, RelativeUnit.Relative)
            }, null, _topCenterGeometryCache);

            tlOrigin = new RelativePoint(depth.Right, depth.Top /*size.Width - (radii.TopRight + depth.Right), radii.TopRight + depth.Top*/, RelativeUnit.Absolute);
            //innerStopPos = 0; //radii.TopRight / (depth + radii.TopRight);
            context.DrawGeometry(new RadialGradientBrush()
            {
                Center         = tlOrigin,
                GradientOrigin = tlOrigin,
                Radius         = 1,
                GradientStops  = new GradientStops()
                {
                    new GradientStop(bg, 0),
                    new GradientStop(bgTrans, 1)
                }
            }, null, _topRightGeometryCache);


            context.DrawGeometry(new LinearGradientBrush()
            {
                GradientStops = stops,
                StartPoint    = new RelativePoint(0, 0, RelativeUnit.Relative),
                EndPoint      = new RelativePoint(0, 1, RelativeUnit.Relative)
            }, null, _bottomCenterGeometryCache);
        }
예제 #6
0
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (markers == null)
            {
                return;
            }

            var visualLines = textView.VisualLines;

            if (visualLines.Count == 0)
            {
                return;
            }

            int viewStart = visualLines.First().FirstDocumentLine.Offset;
            int viewEnd   = visualLines.Last().LastDocumentLine.EndOffset;

            int start = Math.Min(viewStart, viewEnd);
            int end   = Math.Max(viewStart, viewEnd);

            foreach (TextMarker marker in markers.FindOverlappingSegments(start, end - start))
            {
                if (marker.Diagnostic.Level != DiagnosticLevel.Hidden && marker.Length > 0)
                {
                    if (marker.EndOffset < textView.Document.TextLength)
                    {
                        foreach (var r in BackgroundGeometryBuilder.GetRectsForSegment(textView, marker))
                        {
                            if (marker.Diagnostic.Category == DiagnosticCategory.Style)
                            {
                                var usedPen = new Pen(marker.Brush, 1);
                                drawingContext.DrawLine(usedPen, r.BottomLeft, r.BottomLeft.WithX(r.BottomLeft.X + 15));
                            }
                            else
                            {
                                var startPoint = r.BottomLeft;
                                var endPoint   = r.BottomRight;

                                var usedPen = new Pen(marker.Brush, 1);

                                const double offset = 2.5;

                                var count = Math.Max((int)((endPoint.X - startPoint.X) / offset) + 1, 4);

                                var geometry = new StreamGeometry();

                                using (var ctx = geometry.Open())
                                {
                                    ctx.BeginFigure(startPoint, false);

                                    foreach (var point in CreatePoints(startPoint, endPoint, offset, count))
                                    {
                                        ctx.LineTo(point);
                                    }

                                    ctx.EndFigure(false);
                                }

                                drawingContext.DrawGeometry(Brushes.Transparent, usedPen, geometry);
                                break;
                            }
                        }
                    }
                }
            }
        }
예제 #7
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);
            if (this.curvePen == null)
            {
                this.curvePen = new Pen(this.Foreground, 1.0);
                this.curvePen.Freeze();
            }
            if (this.ControlPointBrush != null && this.linePen == null)
            {
                this.linePen = new Pen(this.ControlPointBrush, 1.0);
                this.linePen.Freeze();
            }
            double actualWidth  = this.ActualWidth;
            double actualHeight = this.ActualHeight;

            if (this.Background != null)
            {
                drawingContext.DrawRectangle(this.Background, (Pen)null, new Rect(0.0, 0.0, actualWidth, actualHeight));
            }
            if (this.GridBrush != null)
            {
                if (this.brushOne == null)
                {
                    this.brushOne         = this.GridBrush.Clone();
                    this.brushOne.Opacity = 0.1;
                    this.brushOne.Freeze();
                }
                if (this.brushFive == null)
                {
                    this.brushFive         = this.GridBrush.Clone();
                    this.brushFive.Opacity = 0.25;
                    this.brushFive.Freeze();
                }
                if (this.brushTen == null)
                {
                    this.brushTen         = this.GridBrush.Clone();
                    this.brushTen.Opacity = 0.5;
                    this.brushTen.Freeze();
                }
                Size   size  = new Size(actualWidth, actualHeight);
                double num1  = size.Width / 10.0;
                Point  point = new Point(-1.0, -1.0);
                int    num2  = (int)Math.Floor((0.0 - point.X) / num1);
                int    num3  = (int)Math.Ceiling((size.Width - point.X) / num1);
                for (int index = num2; index <= num3; ++index)
                {
                    Brush  brush = index % 10 == 0 ? this.brushTen : (index % 5 == 0 ? this.brushFive : this.brushOne);
                    double x     = point.X + (double)index * num1;
                    drawingContext.DrawRectangle(brush, (Pen)null, new Rect(x, 0.0, 1.0, size.Height));
                }
                double num4 = size.Height / 10.0;
                int    num5 = (int)Math.Floor((0.0 - point.Y) / num4);
                int    num6 = (int)Math.Ceiling((size.Height - point.Y) / num4);
                for (int index = num5; index <= num6; ++index)
                {
                    Brush  brush = index % 10 == 0 ? this.brushTen : (index % 5 == 0 ? this.brushFive : this.brushOne);
                    double y     = point.Y + (double)index * num4;
                    drawingContext.DrawRectangle(brush, (Pen)null, new Rect(0.0, y, size.Width, 1.0));
                }
            }
            if (this.pointPositionsInvalid)
            {
                this.controlPoint1Editor.CenterX = this.NormalizedXToX(this.X1, actualWidth);
                this.controlPoint1Editor.CenterY = this.NormalizedYToY(this.Y1, actualHeight);
                this.controlPoint2Editor.CenterX = this.NormalizedXToX(this.X2, actualWidth);
                this.controlPoint2Editor.CenterY = this.NormalizedYToY(this.Y2, actualHeight);
                this.pathGeometry = new StreamGeometry();
                StreamGeometryContext streamGeometryContext = this.pathGeometry.Open();
                streamGeometryContext.BeginFigure(new Point(-0.5, actualHeight - 0.5), false, false);
                streamGeometryContext.BezierTo(new Point(this.controlPoint1Editor.CenterX - 0.5, this.controlPoint1Editor.CenterY - 0.5), new Point(this.controlPoint2Editor.CenterX - 0.5, this.controlPoint2Editor.CenterY - 0.5), new Point(actualWidth - 0.5, -0.5), true, false);
                streamGeometryContext.Close();
                this.pathGeometry.Freeze();
                this.pointPositionsInvalid = false;
            }
            if (!this.X1IsNinched && !this.Y1IsNinched && (!this.X2IsNinched && !this.Y2IsNinched))
            {
                drawingContext.DrawGeometry((Brush)null, this.curvePen, (Geometry)this.pathGeometry);
            }
            if (this.linePen != null)
            {
                drawingContext.DrawLine(this.linePen, new Point(-0.5, actualHeight - 0.5), new Point(this.controlPoint1Editor.CenterX - 0.5, this.controlPoint1Editor.CenterY - 0.5));
                drawingContext.DrawLine(this.linePen, new Point(actualWidth - 0.5, -0.5), new Point(this.controlPoint2Editor.CenterX - 0.5, this.controlPoint2Editor.CenterY - 0.5));
            }
            this.controlPoint1Editor.OnRender(drawingContext, this);
            this.controlPoint2Editor.OnRender(drawingContext, this);
        }
예제 #8
0
        protected override void OnRender(DrawingContext dc)
        {
            base.OnRender(dc);

            var scales = new List <double> {
                1, 10, 100, 1000
            };

            // Eliminate blurring caused by rounding
            dc.PushTransform(new TranslateTransform(0.5, 0.5));

            dc.PushTransform(new TranslateTransform(30, 0));

            // Vertical references lines; 10px apart
            dc.PushTransform(new TranslateTransform(40, 0));
            var gridPen = new Pen(Brushes.LightGray, 1);

            for (int x = 0; x <= LineLength; x += 10)
            {
                dc.DrawGeometry(null, gridPen, new LineGeometry(new Point(x, 0), new Point(x, this.Height)));
            }
            dc.Pop();

            dc.PushTransform(new TranslateTransform(0, 30));
            dc.DrawText(
                new FormattedText(
                    "Dash length\nbefore scaling",
                    CultureInfo.GetCultureInfo("en-us"),
                    FlowDirection.LeftToRight,
                    new Typeface("Verdana"),
                    8.0,
                    Brushes.Black,
                    1.0),
                new Point(-10, -5));

            dc.PushTransform(new TranslateTransform(0, 30));

            double cursorY = 0.0;

            void DrawLineGroup(double dashValue)
            {
                var dashStyle = dashValue == 0 ? null : new DashStyle(new List <double> {
                    dashValue, dashValue
                }, 0);

                dc.PushTransform(new TranslateTransform(0, cursorY));

                for (int row = 0; row < scales.Count; ++row)
                {
                    var scale = scales[row];
                    var dashLengthBeforeScale = dashValue / scale;
                    var brush = dashLengthBeforeScale < MagicDashLimit ? Brushes.Red : Brushes.DarkGreen;

                    dc.PushTransform(new TranslateTransform(0, 10 * row));

                    dc.DrawText(
                        new FormattedText(
                            $"{dashLengthBeforeScale:F5}",
                            CultureInfo.GetCultureInfo("en-us"),
                            FlowDirection.LeftToRight,
                            new Typeface("Verdana"),
                            8.0,
                            brush,
                            1.0),
                        new Point(-10, -5));

                    dc.PushTransform(new TranslateTransform(40, 0));
                    dc.PushTransform(new ScaleTransform(scale, scale));

                    var pen = new Pen(brush, 1 / scale);
                    pen.DashStyle = dashStyle;
                    dc.DrawGeometry(null, pen, new LineGeometry(new Point(0, 0), new Point(LineLength / scale, 0)));

                    dc.Pop();
                    dc.Pop();
                    dc.Pop();
                }

                dc.Pop();

                cursorY += SpaceBetweenLineGroups;
            }

            DrawLineGroup(0.1);
            DrawLineGroup(0.2);
            DrawLineGroup(0.45);
            DrawLineGroup(0.5);

            cursorY += SpaceBetweenScaleGroups;

            DrawLineGroup(1);
            DrawLineGroup(2);
            DrawLineGroup(4.5);
            DrawLineGroup(5);

            cursorY += SpaceBetweenScaleGroups;

            DrawLineGroup(10);
            DrawLineGroup(20);
            DrawLineGroup(45);
            DrawLineGroup(50);

            cursorY += SpaceBetweenScaleGroups;

            DrawLineGroup(100);
            DrawLineGroup(200);
            DrawLineGroup(450);
            DrawLineGroup(500);

            dc.Pop();
            dc.Pop();
            dc.Pop();

            this.Height = cursorY + 100;
            this.Width  = LineLength + 100;
        }
예제 #9
0
        public static BitmapSource RenderToPNGImageSource(Gesture target, bool highlightstrokes = false, bool highlightparts = false, Dictionary <int, List <int> > parts = null, bool drawPoints = false)
        {
            BitmapImage        src = new BitmapImage();
            RenderTargetBitmap rtb;

            System.Drawing.Pen pen    = null;
            RecPoint[]         points = target.PointsRaw;

            if (parts == null)
            {
                parts = target.Partition_Indexes;
            }
            if (parts.Count == 0)
            {
                highlightparts = false;
            }
            if (highlightparts == true)
            {
                highlightstrokes = true;
            }

            if (target.Name == "exceeded max number of strokes")
            {
                rtb = new RenderTargetBitmap(canvasWidth, canvasHeight, defaultDpi, defaultDpi, PixelFormats.Pbgra32);
                return(rtb);
            }

            // CUSTOM
            DrawingImage dtp = new DrawingImage();
            DrawingGroup dwg = new DrawingGroup();

            GeometryGroup myGeometryGroup = new GeometryGroup();

            Graphics graphics         = null;
            double   stroke_thickness = 1;
            Bitmap   bitmp            = new Bitmap(canvasWidth + (int)stroke_thickness, canvasHeight + (int)stroke_thickness);

            try
            {
                pen = new System.Drawing.Pen(System.Drawing.Color.OrangeRed, 3);


                graphics = Graphics.FromImage(bitmp);
                graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                graphics.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                graphics.Clear(System.Drawing.Color.White);

                double left  = points[0].X;
                double right = points[0].X;
                double up    = points[0].Y;
                double down  = points[0].Y;

                foreach (var p in points)
                {
                    if (p.X > right)
                    {
                        right = p.X;
                    }
                    if (p.X < left)
                    {
                        left = p.X;
                    }
                    if (p.Y > up)
                    {
                        up = p.Y;
                    }
                    if (p.Y < down)
                    {
                        down = p.Y;
                    }
                }

                double c_width  = right - left;
                double c_height = up - down;

                double p_width = 0, p_height = 0;

                if (c_width >= c_height)
                {
                    p_width = canvasWidth / c_width;
                }
                if (c_height >= c_width)
                {
                    p_height = canvasHeight / c_height;
                }

                ;
                if (p_width != p_height)
                {
                    if (p_height == 0)
                    {
                        p_height = p_width;
                        down    -= ((canvasHeight - c_height * p_height) / 2) / p_height;
                    }
                    else
                    {
                        p_width = p_height;
                        left   -= ((canvasWidth - c_width * p_width) / 2) / p_width;
                    }
                }

                DrawingVisual dv = new DrawingVisual();
                System.Windows.Media.SolidColorBrush[] BrushesArray = new System.Windows.Media.SolidColorBrush[] {
                    System.Windows.Media.Brushes.Green,
                    System.Windows.Media.Brushes.Red,
                    System.Windows.Media.Brushes.Blue,
                    System.Windows.Media.Brushes.Magenta,
                    System.Windows.Media.Brushes.DarkOrange
                };

                System.Drawing.Color[] ColorsArray = new System.Drawing.Color[] {
                    System.Drawing.Color.Green,
                    System.Drawing.Color.Red,
                    System.Drawing.Color.Blue,
                    System.Drawing.Color.Magenta,
                    System.Drawing.Color.DarkOrange
                };
                int g = 0;

                using (DrawingContext dc = dv.RenderOpen())
                {
                    int i = 0;
                    while (i < points.Length)
                    {
                        System.Windows.Media.Pen myPen = new System.Windows.Media.Pen(BrushesArray[g], stroke_thickness);
                        var geometry = new StreamGeometry();
                        using (StreamGeometryContext ctx = geometry.Open())
                        {
                            double startX = ((points[i].X - left) * p_width);
                            double startY = ((points[i].Y - down) * p_height);
                            ctx.BeginFigure(new System.Windows.Point(startX, startY),
                                            true,                     // is filled
                                            false                     // is closed
                                            );
                            if (drawPoints)
                            {
                                dc.DrawEllipse(BrushesArray[g], myPen, new System.Windows.Point(startX, startY), 1, 1);
                            }
                            i++;
                            while (i < points.Length && points[i].StrokeID == points[i - 1].StrokeID && (!highlightparts || !parts[points[i].StrokeID].Contains(i - 1)))
                            {
                                double endX = ((points[i].X - left) * p_width);
                                double endY = ((points[i].Y - down) * p_height);

                                ctx.LineTo(new System.Windows.Point(endX, endY),
                                           true                      // is stroked
                                           , false                   // is smooth join
                                           );

                                if (drawPoints)
                                {
                                    dc.DrawEllipse(BrushesArray[g], myPen, new System.Windows.Point(endX, endY), 1, 1);
                                }

                                i++;
                            }
                        }
                        geometry.Freeze();

                        dc.DrawGeometry(null, myPen, geometry);


                        if (highlightstrokes || highlightparts)
                        {
                            g = (g + 1) % BrushesArray.Length;
                        }
                    }
                }
                rtb = new RenderTargetBitmap(canvasWidth, canvasHeight, defaultDpi, defaultDpi, PixelFormats.Pbgra32);
                rtb.Render(dv);
            }
            finally
            {
                if (pen != null)
                {
                    pen.Dispose();
                }

                if (graphics != null)
                {
                    graphics.Dispose();
                }
            }
            return(rtb);
        }
예제 #10
0
        private void RenderTheme(DrawingContext dc)
        {
            Size size        = RenderSize;
            bool horizontal  = Orientation == Orientation.Horizontal;
            bool isClickable = IsClickable && IsEnabled;
            bool isHovered   = isClickable && IsHovered;
            bool isPressed   = isClickable && IsPressed;
            ListSortDirection?sortDirection = SortDirection;
            bool isSorted   = sortDirection != null;
            bool isSelected = IsSelected;
            bool hasBevel   = (!isHovered && !isPressed && !isSorted && !isSelected);

            EnsureCache((int)AeroFreezables.NumFreezables);

            if (horizontal)
            {
                // When horizontal, rotate the rendering by -90 degrees
                var m1 = new Matrix();
                m1.RotateAt(-90.0, 0.0, 0.0);
                var m2 = new Matrix();
                m2.Translate(0.0, size.Height);

                var horizontalRotate = new MatrixTransform(m1 * m2);
                horizontalRotate.Freeze();
                dc.PushTransform(horizontalRotate);

                double temp = size.Width;
                size.Width  = size.Height;
                size.Height = temp;
            }

            if (hasBevel)
            {
                // This is a highlight that can be drawn by just filling the background with the color.
                // It will be seen through the gab between the border and the background.
                var bevel = (LinearGradientBrush)GetCachedFreezable((int)AeroFreezables.NormalBevel);
                if (bevel == null)
                {
                    bevel            = new LinearGradientBrush();
                    bevel.StartPoint = new Point();
                    bevel.EndPoint   = new Point(0.0, 1.0);
                    bevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF), 0.0));
                    bevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF), 0.4));
                    bevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFC, 0xFC, 0xFD), 0.4));
                    bevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFB, 0xFC, 0xFC), 1.0));
                    bevel.Freeze();

                    CacheFreezable(bevel, (int)AeroFreezables.NormalBevel);
                }

                dc.DrawRectangle(bevel, null, new Rect(0.0, 0.0, size.Width, size.Height));
            }

            // Fill the background
            var backgroundType = AeroFreezables.NormalBackground;

            if (isPressed)
            {
                backgroundType = AeroFreezables.PressedBackground;
            }
            else if (isHovered)
            {
                backgroundType = AeroFreezables.HoveredBackground;
            }
            else if (isSorted || isSelected)
            {
                backgroundType = AeroFreezables.SortedBackground;
            }

            var background = (LinearGradientBrush)GetCachedFreezable((int)backgroundType);

            if (background == null)
            {
                background            = new LinearGradientBrush();
                background.StartPoint = new Point();
                background.EndPoint   = new Point(0.0, 1.0);

                switch (backgroundType)
                {
                case AeroFreezables.NormalBackground:
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF), 0.0));
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF), 0.4));
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF7, 0xF8, 0xFA), 0.4));
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF1, 0xF2, 0xF4), 1.0));
                    break;

                case AeroFreezables.PressedBackground:
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xBC, 0xE4, 0xF9), 0.0));
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xBC, 0xE4, 0xF9), 0.4));
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x8D, 0xD6, 0xF7), 0.4));
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x8A, 0xD1, 0xF5), 1.0));
                    break;

                case AeroFreezables.HoveredBackground:
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xE3, 0xF7, 0xFF), 0.0));
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xE3, 0xF7, 0xFF), 0.4));
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xBD, 0xED, 0xFF), 0.4));
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xB7, 0xE7, 0xFB), 1.0));
                    break;

                case AeroFreezables.SortedBackground:
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF2, 0xF9, 0xFC), 0.0));
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF2, 0xF9, 0xFC), 0.4));
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xE1, 0xF1, 0xF9), 0.4));
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xD8, 0xEC, 0xF6), 1.0));
                    break;
                }

                background.Freeze();

                CacheFreezable(background, (int)backgroundType);
            }

            dc.DrawRectangle(background, null, new Rect(0.0, 0.0, size.Width, size.Height));

            if (size.Width >= 2.0)
            {
                // Draw the borders on the sides
                var sideType = AeroFreezables.NormalSides;
                if (isPressed)
                {
                    sideType = AeroFreezables.PressedSides;
                }
                else if (isHovered)
                {
                    sideType = AeroFreezables.HoveredSides;
                }
                else if (isSorted || isSelected)
                {
                    sideType = AeroFreezables.SortedSides;
                }

                if (SeparatorVisibility == Visibility.Visible)
                {
                    Brush sideBrush;
                    if (SeparatorBrush != null)
                    {
                        sideBrush = SeparatorBrush;
                    }
                    else
                    {
                        sideBrush = (Brush)GetCachedFreezable((int)sideType);
                        if (sideBrush == null)
                        {
                            LinearGradientBrush lgBrush = null;
                            if (sideType != AeroFreezables.SortedSides)
                            {
                                lgBrush            = new LinearGradientBrush();
                                lgBrush.StartPoint = new Point();
                                lgBrush.EndPoint   = new Point(0.0, 1.0);
                                sideBrush          = lgBrush;
                            }

                            switch (sideType)
                            {
                            case AeroFreezables.NormalSides:
                                lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF2, 0xF2, 0xF2), 0.0));
                                lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xEF, 0xEF, 0xEF), 0.4));
                                lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xE7, 0xE8, 0xEA), 0.4));
                                lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xDE, 0xDF, 0xE1), 1.0));
                                break;

                            case AeroFreezables.PressedSides:
                                lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x7A, 0x9E, 0xB1), 0.0));
                                lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x7A, 0x9E, 0xB1), 0.4));
                                lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x50, 0x91, 0xAF), 0.4));
                                lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x4D, 0x8D, 0xAD), 1.0));
                                break;

                            case AeroFreezables.HoveredSides:
                                lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x88, 0xCB, 0xEB), 0.0));
                                lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x88, 0xCB, 0xEB), 0.4));
                                lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x69, 0xBB, 0xE3), 0.4));
                                lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x69, 0xBB, 0xE3), 1.0));
                                break;

                            case AeroFreezables.SortedSides:
                                sideBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0x96, 0xD9, 0xF9));
                                break;
                            }

                            sideBrush.Freeze();

                            CacheFreezable(sideBrush, (int)sideType);
                        }
                    }

                    dc.DrawRectangle(sideBrush, null, new Rect(0.0, 0.0, 1.0, Max0(size.Height - 0.95)));
                    dc.DrawRectangle(sideBrush, null, new Rect(size.Width - 1.0, 0.0, 1.0, Max0(size.Height - 0.95)));
                }
            }

            if (isPressed && (size.Width >= 4.0) && (size.Height >= 4.0))
            {
                // When pressed, there are added borders on the left and top
                var topBrush = (LinearGradientBrush)GetCachedFreezable((int)AeroFreezables.PressedTop);
                if (topBrush == null)
                {
                    topBrush            = new LinearGradientBrush();
                    topBrush.StartPoint = new Point();
                    topBrush.EndPoint   = new Point(0.0, 1.0);
                    topBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x86, 0xA3, 0xB2), 0.0));
                    topBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x86, 0xA3, 0xB2), 0.1));
                    topBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xAA, 0xCE, 0xE1), 0.9));
                    topBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xAA, 0xCE, 0xE1), 1.0));
                    topBrush.Freeze();

                    CacheFreezable(topBrush, (int)AeroFreezables.PressedTop);
                }

                dc.DrawRectangle(topBrush, null, new Rect(0.0, 0.0, size.Width, 2.0));

                var pressedBevel = (LinearGradientBrush)GetCachedFreezable((int)AeroFreezables.PressedBevel);
                if (pressedBevel == null)
                {
                    pressedBevel            = new LinearGradientBrush();
                    pressedBevel.StartPoint = new Point();
                    pressedBevel.EndPoint   = new Point(0.0, 1.0);
                    pressedBevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xA2, 0xCB, 0xE0), 0.0));
                    pressedBevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xA2, 0xCB, 0xE0), 0.4));
                    pressedBevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x72, 0xBC, 0xDF), 0.4));
                    pressedBevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x6E, 0xB8, 0xDC), 1.0));
                    pressedBevel.Freeze();

                    CacheFreezable(pressedBevel, (int)AeroFreezables.PressedBevel);
                }

                dc.DrawRectangle(pressedBevel, null, new Rect(1.0, 0.0, 1.0, size.Height - 0.95));
                dc.DrawRectangle(pressedBevel, null, new Rect(size.Width - 2.0, 0.0, 1.0, size.Height - 0.95));
            }

            if (size.Height >= 2.0)
            {
                // Draw the bottom border
                AeroFreezables bottomType = AeroFreezables.NormalBottom;
                if (isPressed)
                {
                    bottomType = AeroFreezables.PressedOrHoveredBottom;
                }
                else if (isHovered)
                {
                    bottomType = AeroFreezables.PressedOrHoveredBottom;
                }
                else if (isSorted || isSelected)
                {
                    bottomType = AeroFreezables.SortedBottom;
                }

                var bottomBrush = (SolidColorBrush)GetCachedFreezable((int)bottomType);
                if (bottomBrush == null)
                {
                    switch (bottomType)
                    {
                    case AeroFreezables.NormalBottom:
                        bottomBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0xD5, 0xD5, 0xD5));
                        break;

                    case AeroFreezables.PressedOrHoveredBottom:
                        bottomBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0x93, 0xC9, 0xE3));
                        break;

                    case AeroFreezables.SortedBottom:
                        bottomBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0x96, 0xD9, 0xF9));
                        break;
                    }

                    bottomBrush.Freeze();

                    CacheFreezable(bottomBrush, (int)bottomType);
                }

                dc.DrawRectangle(bottomBrush, null, new Rect(0.0, size.Height - 1.0, size.Width, 1.0));
            }

            if (isSorted && (size.Width > 14.0) && (size.Height > 10.0))
            {
                // Draw the sort arrow
                var positionTransform = new TranslateTransform((size.Width - 10.0), Math.Round(size.Height / 2) - 4.0);
                positionTransform.Freeze();
                dc.PushTransform(positionTransform);

                bool ascending     = (sortDirection == ListSortDirection.Ascending);
                var  arrowGeometry =
                    (PathGeometry)
                    GetCachedFreezable(ascending ? (int)AeroFreezables.ArrowUpGeometry : (int)AeroFreezables.ArrowDownGeometry);
                if (arrowGeometry == null)
                {
                    arrowGeometry = new PathGeometry();
                    var arrowFigure = new PathFigure();

                    if (ascending)
                    {
                        arrowFigure.StartPoint = new Point(0.0, 4.0);

                        var line = new LineSegment(new Point(4.0, 0.0), false);
                        line.Freeze();
                        arrowFigure.Segments.Add(line);

                        line = new LineSegment(new Point(8.0, 4.0), false);
                        line.Freeze();
                        arrowFigure.Segments.Add(line);
                    }
                    else
                    {
                        arrowFigure.StartPoint = new Point(0.0, 0.0);

                        var line = new LineSegment(new Point(8.0, 0.0), false);
                        line.Freeze();
                        arrowFigure.Segments.Add(line);

                        line = new LineSegment(new Point(4.0, 4.0), false);
                        line.Freeze();
                        arrowFigure.Segments.Add(line);
                    }

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

                    arrowGeometry.Figures.Add(arrowFigure);
                    arrowGeometry.Freeze();

                    CacheFreezable(arrowGeometry,
                                   ascending ? (int)AeroFreezables.ArrowUpGeometry : (int)AeroFreezables.ArrowDownGeometry);
                }

                // Draw two arrows, one inset in the other. This is to achieve a double gradient over both the border and the fill.
                var arrowBorder = (LinearGradientBrush)GetCachedFreezable((int)AeroFreezables.ArrowBorder);
                if (arrowBorder == null)
                {
                    arrowBorder            = new LinearGradientBrush();
                    arrowBorder.StartPoint = new Point();
                    arrowBorder.EndPoint   = new Point(1.0, 1.0);
                    arrowBorder.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x3C, 0x5E, 0x72), 0.0));
                    arrowBorder.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x3C, 0x5E, 0x72), 0.1));
                    arrowBorder.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xC3, 0xE4, 0xF5), 1.0));
                    arrowBorder.Freeze();
                    CacheFreezable(arrowBorder, (int)AeroFreezables.ArrowBorder);
                }

                dc.DrawGeometry(arrowBorder, null, arrowGeometry);

                var arrowFill = (LinearGradientBrush)GetCachedFreezable((int)AeroFreezables.ArrowFill);
                if (arrowFill == null)
                {
                    arrowFill            = new LinearGradientBrush();
                    arrowFill.StartPoint = new Point();
                    arrowFill.EndPoint   = new Point(1.0, 1.0);
                    arrowFill.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x61, 0x96, 0xB6), 0.0));
                    arrowFill.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x61, 0x96, 0xB6), 0.1));
                    arrowFill.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xCA, 0xE6, 0xF5), 1.0));
                    arrowFill.Freeze();
                    CacheFreezable(arrowFill, (int)AeroFreezables.ArrowFill);
                }

                // Inset the fill arrow inside the border arrow
                var arrowScale = (ScaleTransform)GetCachedFreezable((int)AeroFreezables.ArrowFillScale);
                if (arrowScale == null)
                {
                    arrowScale = new ScaleTransform(0.75, 0.75, 3.5, 4.0);
                    arrowScale.Freeze();
                    CacheFreezable(arrowScale, (int)AeroFreezables.ArrowFillScale);
                }

                dc.PushTransform(arrowScale);

                dc.DrawGeometry(arrowFill, null, arrowGeometry);

                dc.Pop();                 // Scale Transform
                dc.Pop();                 // Position Transform
            }

            if (horizontal)
            {
                dc.Pop();                 // Horizontal Rotate
            }
        }
예제 #11
0
 internal void DrawGeometry(StreamGeometry geo, int gen)
 {
     m_context.DrawGeometry(gen >= 3 ? m_Palettes[gen - 3].inducedGcBrush : m_Palettes[gen].gcBrush, null, geo);
 }
예제 #12
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            //base.OnRender(drawingContext);
            if (AxisPanel == null)
            {
                return;
            }

            //计算每个点之间的间距是多少
            var cellWidth  = GetCellInterval();
            var xTransform = GetXTransform(cellWidth);

            _startIndex = GetStartIndex(xTransform);
            //没有点,或是只有一个都不能画线,在平面中过一点可以画无数条线
            if (Datas == null || Datas.Count <= 1 || _startIndex >= Datas.Count)
            {
                return;
            }
            //实际圆的半径(线宽+半径)
            //var realRadius = GetRealRadius();

            var displayCount = (int)Math.Min(ActualWidth / cellWidth + 2, Datas.Count);
            //每次动态产生对效能有影响,可以放到Arrange或是赋值之后计算一遍,此为偷懒写法
            //或可以说时间换空间?
            var pointList = new List <Point>(displayCount);

            for (int i = 0, j = _startIndex; j < Datas.Count && i < displayCount; i++, j++)
            {
                var y = GetY(Datas[j]);
                //if (realRadius == y)
                //    y = 0;
                //注意横坐标有加realRadius
                //var x = i * cellWidth + realRadius - Radius;
                var x     = i * cellWidth;
                var point = new Point(x, y); // orginal : var point = new Point(i * cellWidth + realRadius, y);
                pointList.Add(point);
            }

            drawingContext.PushTransform(new TranslateTransform(xTransform, 0));

            //因为没有动画效果,并为了追求更好的效能,所以使用StreamGeometry
            var geometry = new StreamGeometry();

            using (var context = geometry.Open())
            {
                context.BeginFigure(pointList[0], true, false);
                context.PolyLineTo(pointList, true, true);
                context.Close();
            }
            geometry.Freeze();

            //这些画笔也可以理解为时间换空间
            var dashStyle = new DashStyle(LineDashArray, LineDashOffset);

            dashStyle.Freeze();

            #region shadow drawing
            //Pen shadowPen = new Pen(ShadowColor, LineThickness);
            //shadowPen.StartLineCap = PenLineCap.Round;
            //shadowPen.EndLineCap = PenLineCap.Round;
            //shadowPen.DashStyle = dashStyle;
            //shadowPen.DashCap = LineDashCap;
            //shadowPen.Freeze();

            //if (IsShowShadow)
            //{
            //    //draw offset line shadow
            //    drawingContext.PushTransform(new TranslateTransform(LineThickness * 0.312, -LineThickness * 0.681));
            //    drawingContext.DrawGeometry(null, shadowPen, geometry);
            //    drawingContext.Pop();
            //}
            #endregion

            //draw line
            var linePen = new Pen(LineColor, LineThickness)
            {
                DashCap = LineDashCap, DashStyle = dashStyle
            };
            linePen.Freeze();
            drawingContext.DrawGeometry(null, linePen, geometry);

            if (0 < Radius)
            {
                var ellipseLinePen = new Pen(LineColor, LineThickness / 2);
                ellipseLinePen.Freeze();
                //draw ellipse
                foreach (var point in pointList)
                {
                    drawingContext.DrawEllipse(PointColor, ellipseLinePen, point, Radius, Radius);
                }
            }
            drawingContext.Pop();
        }
예제 #13
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            if (valuesList.Count == 0)
            {
                return;
            }

            double oldX = offsetFromTop, oldY = RenderSize.Height;

            StreamGeometry geometry = new StreamGeometry();

            using (StreamGeometryContext ctx = geometry.Open())
            {
                ctx.BeginFigure(new Point(0, RenderSize.Height), true, true);

                List <Point> points = new List <Point>();

                double maxHeight = RenderSize.Height - offsetFromTop;

                for (int i = 0; i < valuesList.Count; i++)
                {
                    double x = pieceWidth / 2.0 + pieceWidth * i;
                    // TODO : support MinValues other than 0
                    double y = offsetFromTop + (maxHeight - maxHeight * (valuesList[i].Value / MaxValue));

                    points.Add(new Point(x, y));

                    oldX = x;
                    oldY = y;
                }

                points.Add(new Point(oldX, offsetFromTop + RenderSize.Height));

                ctx.PolyLineTo(points, true, true);
            }

            geometry.Freeze();

            Brush b = new LinearGradientBrush(Colors.Red, Colors.Orange, 90);

            drawingContext.DrawRectangle(Brushes.White, new Pen(Brushes.White, 1), new Rect(new Point(0, 0), RenderSize));

            var p = new Pen(Brushes.DarkRed, 2);

            drawingContext.DrawGeometry(b, new Pen(b, 1), geometry);

            DateTime time = new DateTime(1, 1, 1, 0, 0, 0, 0);

            for (int i = 0; i < valuesList.Count; i++)
            {
                if (valuesList[i].DisplayMarker)
                {
                    drawingContext.DrawLine(p, new Point(pieceWidth * i, offsetFromTop),
                                            new Point(pieceWidth * i, RenderSize.Height));
                }

                if (i % 3 == 0)
                {
                    FormattedText textFormat = new FormattedText(
                        time.ToString("mm:ss.fff"),
                        CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
                        new Typeface("Segoe UI"), 12, Brushes.Black
                        );

                    drawingContext.DrawText(textFormat, new Point(pieceWidth * i, 0));
                }

                var events = valuesList[i].Events;

                if (events != null && events.Length > 0)
                {
                    foreach (EventDataEntry @event in events)
                    {
                        drawingContext.DrawRectangle(
                            Brushes.Red,
                            new Pen(Brushes.Red, 1),
                            new Rect(
                                new Point(@event.DataSetId * pieceWidth, 25),
                                new Point(@event.DataSetId * pieceWidth + pieceWidth, 35)
                                )
                            );
                    }
                }

                time = time.AddMilliseconds(500);
            }

            drawingContext.DrawRectangle(
                new SolidColorBrush(Color.FromArgb(64, Colors.Blue.R, Colors.Blue.G, Colors.Blue.B)),
                new Pen(Brushes.Blue, 1),
                new Rect(
                    new Point(Math.Min(selectedStartIndex, selectedEndIndex) * pieceWidth + offset, offsetFromTop),
                    new Point(Math.Max(selectedStartIndex, selectedEndIndex) * pieceWidth + offset + pieceWidth, RenderSize.Height)
                    )
                );
        }
예제 #14
0
        /// <summary>
        /// Translates origin of coordinate space to a box of size 220pp x 140pp.
        /// </summary>
        protected void BeginBox(DrawingContext dc, int n, BoxOptions options, string description)
        {
            double dx = (WidthInPU - 2 * BoxWidth) / 3;
            double dy = (HeightInPU - 4 * BoxHeight) / 5;
            double x  = (1 - n % 2) * BoxWidth + (2 - n % 2) * dx;
            double y  = ((n + 1) / 2 - 1) * BoxHeight + ((n + 1) / 2) * dy;

            dc.PushTransform(new TranslateTransform(x, y));

            Brush tileBrush = new SolidColorBrush(Color.FromRgb(204, 204, 204));

            //if (options != BoxOptions.None)
            //{
            //  double strokeWidth = 0.75;
            //  double adjust = strokeWidth / 2;
            //  Pen pen = new Pen(tileBrush, 0.75);
            //  //pen.DashStyle = DashStyles.DashDot;
            //  dc.DrawRectangle(null, pen, new Rect(0 + adjust, 0 + adjust, BoxWidth - strokeWidth, BoxHeight - strokeWidth));
            //}
            switch (options)
            {
            case BoxOptions.None:
                break;

            case BoxOptions.Box:
            {
                Pen pen = new Pen(tileBrush, 3);
                dc.DrawLine(pen, new Point(0, 0), new Point(BoxWidth, 0));
                dc.DrawLine(pen, new Point(BoxWidth, 0), new Point(BoxWidth, BoxHeight));
                dc.DrawLine(pen, new Point(BoxWidth, BoxHeight), new Point(0, BoxHeight));
                dc.DrawLine(pen, new Point(0, BoxHeight), new Point(0, 0));
            }
            break;

            case BoxOptions.DrawX:
            {
                Pen pen = new Pen(tileBrush, 3);
                dc.DrawLine(pen, new Point(0, 0), new Point(BoxWidth, BoxHeight));
                dc.DrawLine(pen, new Point(0, BoxHeight), new Point(BoxWidth, 0));
            }
            break;

            case BoxOptions.Fill:
            {
                dc.DrawRectangle(tileBrush, null, new Rect(0, 0, BoxWidth, BoxHeight));
            }
            break;

            case BoxOptions.Tile:
            {
#if true
                double       delta = 8;
                PathGeometry path  = new PathGeometry();
                for (double xx = 0; xx < BoxWidth; xx += 2 * delta)
                {
                    path.AddGeometry(new RectangleGeometry(new Rect(xx, 0, delta, BoxHeight)));
                }
                for (double yy = 0; yy < BoxHeight; yy += 2 * delta)
                {
                    path.AddGeometry(new RectangleGeometry(new Rect(0, yy, BoxWidth, delta)));
                }
                dc.DrawGeometry(tileBrush, null, path);
#else
                double delta = 5;
                bool   draw1 = true;
                for (double yy = 0; yy < BoxHeight; yy += delta, draw1 = !draw1)
                {
                    bool draw2 = true;
                    for (double xx = 0; xx < BoxWidth; xx += delta, draw2 = !draw2)
                    {
                        if ((draw1 && draw2) || (!draw1 && !draw2))
                        {
                            dc.DrawRectangle(tileBrush, null, new Rect(xx, yy, delta, delta));
                        }
                    }
                }
#endif
            }
            break;
            }
            if (options != BoxOptions.None && !String.IsNullOrEmpty(description))
            {
                dc.DrawText(new FormattedText(description, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, new Typeface("Arial"), 7.5, Brushes.Black), new Point(0, BoxHeight + 0));
            }
        }
        protected override void OnRender(DrawingContext drawingContext)
        {
            if (this.IsInitialized == false || this.Height <= 0)
            {
                return;
            }

            this.SnapsToDevicePixels = true;
            // Background

            Rect background = new Rect(0, 0, this.ActualWidth, this.ActualHeight);

            // Transparent hit rectangle

            if (this.Background == null)
            {
                drawingContext.DrawRectangle(Brushes.Transparent, null, background);
            }
            else
            {
                drawingContext.DrawRoundedRectangle(this.Background, null, background, 4.0, 4.0);
            }

            // Push border clipping region
            drawingContext.PushClip(new RectangleGeometry(background, 4.0, 4.0));

            // Dimensions of graphing region
            double left   = GraphPadding.Left + 0.5,
                   right  = ActualWidth - GraphPadding.Right + 0.5,
                   top    = GraphPadding.Top + 0.5,
                   bottom = ActualHeight - GraphPadding.Bottom + 0.5;

            // Initialise data bounds
            int leftDataBound  = 0;
            int rightDataBound = 255;

            // Draw histogram data
            drawingContext.PushClip(new RectangleGeometry(new Rect(left + 1, top - 1, right - left - 1, bottom - top + 1), 0.0, 0.0));
            top += 6;
            if (this.histogramData != null)
            {
                // Find true data bounds
                rightDataBound = histogramData.Length;
                if (this.ScaleXAxis)
                {
                    for (int i = 0; i < this.histogramData.Length; i++)
                    {
                        if (this.histogramData[i] > 0)
                        {
                            leftDataBound = i;
                            break;
                        }
                    }

                    for (int i = this.histogramData.Length - 1; i >= 0; i--)
                    {
                        if (this.histogramData[i] > 0)
                        {
                            rightDataBound = i;
                            break;
                        }
                    }

                    if (this.mixtureModel != null && this.mixtureModel.K != this.mixtureModel.ThresholdK)
                    {
                        int    rightDataBoundGMM = 0;
                        int    k   = this.MixtureModel.K - 1;
                        double max = this.mixtureModel.SingleGaussianProbability(this.mixtureModel.Mean[k], k);

                        for (int i = this.histogramData.Length - 1; i >= 0; i--)
                        {
                            double p = (this.mixtureModel.SingleGaussianProbability(i, k) / max);

                            if (this.weightedComponents)
                            {
                                p *= this.mixtureModel.MixingWeight[k];
                            }

                            if (p > 0.001)
                            {
                                rightDataBoundGMM = i;
                                break;
                            }
                        }

                        rightDataBound = Math.Max(rightDataBound, rightDataBoundGMM);
                    }
                }

                StreamGeometry histogramGeometry = new StreamGeometry();
                using (StreamGeometryContext sgc = histogramGeometry.Open())
                {
                    int length = this.histogramData.Length;

                    double currentOffset = left;
                    double columnWidth   = (right - left) / (rightDataBound - leftDataBound);

                    for (int i = leftDataBound; i < rightDataBound; i++)
                    {
                        if (this.stretchedData[i] == 0)
                        {
                            currentOffset += columnWidth;
                            continue;
                        }
                        double columnTop = bottom - ((bottom - top) * this.stretchedData[i]);

                        sgc.BeginFigure(new Point(currentOffset + 0.5, columnTop + 0.5), true, true);
                        sgc.LineTo(new Point(currentOffset + columnWidth + 0.5, columnTop + 0.5), false, false);
                        sgc.LineTo(new Point(currentOffset + columnWidth + 0.5, bottom + 0.5), false, false);
                        sgc.LineTo(new Point(currentOffset + 0.5, bottom + 0.5), false, false);

                        currentOffset += columnWidth;
                    }
                }

                histogramGeometry.Freeze();

                drawingContext.DrawGeometry(Brushes.LightGray, null, histogramGeometry);

                if (this.mixtureModel != null && this.mixtureModel.K != this.mixtureModel.ThresholdK)
                {
                    int histogramLength = this.histogramData.Length;
                    for (int k = 0; k <= this.mixtureModel.K; k++)
                    {
                        Pen mixturePen = GetMixturePen(k, this.mixtureModel.K, this.mixtureModel.ThresholdK);

                        StreamGeometry distribution = new StreamGeometry();
                        using (StreamGeometryContext sgc = distribution.Open())
                        {
                            if (k < this.mixtureModel.K)
                            {
                                if (this.Normalised)
                                {
                                    double currentOffset = left;
                                    double columnWidth   = (right - left) / (rightDataBound - leftDataBound);
                                    for (int i = leftDataBound; i < rightDataBound; i++)
                                    {
                                        double p = this.mixtureModel.NormalisedProbability(i, k);

                                        if (i == leftDataBound)
                                        {
                                            sgc.BeginFigure(new Point(currentOffset + 0.5, bottom - ((bottom - top) * p) + 0.5), true, false);
                                        }
                                        else
                                        {
                                            sgc.LineTo(new Point(currentOffset + 0.5, bottom - ((bottom - top) * p) + 0.5), true, false);
                                        }

                                        currentOffset += columnWidth;
                                    }
                                }
                                else
                                {
                                    double max = this.mixtureModel.SingleGaussianProbability(this.mixtureModel.Mean[k], k);

                                    double currentOffset = left;
                                    double columnWidth   = (right - left) / (rightDataBound - leftDataBound);
                                    for (int i = leftDataBound; i < rightDataBound; i++)
                                    {
                                        double p = (this.mixtureModel.SingleGaussianProbability(i, k) / max);

                                        if (this.weightedComponents)
                                        {
                                            p *= this.mixtureModel.MixingWeight[k];
                                        }

                                        if (i == leftDataBound)
                                        {
                                            sgc.BeginFigure(new Point(currentOffset + 0.5, bottom - ((bottom - top) * p) + 0.5), true, false);
                                        }
                                        else
                                        {
                                            sgc.LineTo(new Point(currentOffset + 0.5, bottom - ((bottom - top) * p) + 0.5), true, false);
                                        }

                                        currentOffset += columnWidth;
                                    }
                                }
                            }
                            else if (k == this.mixtureModel.K && this.ShowMixtureDistribution)
                            {
                                int    maxk = 0;
                                double max  = this.mixtureModel.MixtureMaximum(out maxk);

                                double currentOffset = left;
                                double columnWidth   = (right - left) / (rightDataBound - leftDataBound);
                                for (int i = leftDataBound; i < rightDataBound; i++)
                                {
                                    double p = (this.mixtureModel.MixingProbability(i) / max);

                                    if (this.weightedComponents)
                                    {
                                        p *= this.mixtureModel.MixingWeight[maxk];
                                    }

                                    if (i == leftDataBound)
                                    {
                                        sgc.BeginFigure(new Point(currentOffset + 0.5, bottom - ((bottom - top) * p) + 0.5), true, false);
                                    }
                                    else
                                    {
                                        sgc.LineTo(new Point(currentOffset + 0.5, bottom - ((bottom - top) * p) + 0.5), true, false);
                                    }

                                    currentOffset += columnWidth;
                                }
                            }
                        }
                        distribution.Freeze();
                        drawingContext.DrawGeometry(null, mixturePen, distribution);
                    }
                }
            }

            // Pop content clipping region
            drawingContext.Pop();

            // Draw axis
            top -= 6;
            StreamGeometry axisGeometry = new StreamGeometry();

            using (StreamGeometryContext sgc = axisGeometry.Open())
            {
                // Arrowhead
                sgc.BeginFigure(new Point(left - tickLength, top + tickLength), true, false);
                sgc.LineTo(new Point(left, top), true, true);
                sgc.LineTo(new Point(left + tickLength, top + tickLength), true, false);

                // Main Vertical Axis
                sgc.BeginFigure(new Point(left, top), false, false);
                sgc.LineTo(new Point(left, bottom), true, false);
                sgc.LineTo(new Point(left - tickLength, bottom), true, false);

                // Main Horizontal Axis
                sgc.BeginFigure(new Point(left, bottom + tickLength), false, false);
                sgc.LineTo(new Point(left, bottom), true, false);
                sgc.LineTo(new Point(right, bottom), true, false);
                sgc.LineTo(new Point(right, bottom + tickLength), true, false);

                // Index drawing
                if (this.indexLocation >= 0)
                {
                    double xposition = (int)(this.indexLocation * (right - left) + left) + 0.5;
                    sgc.BeginFigure(new Point(xposition, top + 5.0), false, false);
                    sgc.LineTo(new Point(xposition, bottom), true, false);
                }
            }

            SolidColorBrush uiColor = Brushes.DarkGray;

            Pen axisPen = new Pen(uiColor, 1.0);

            axisGeometry.Freeze();
            drawingContext.DrawGeometry(uiColor, axisPen, axisGeometry);

            // Axis numbering - Vertical
            FormattedText verticalNumbering = new FormattedText("0", System.Globalization.CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight, new Typeface("Arial"), fontSize, uiColor);

            drawingContext.DrawText(verticalNumbering, new Point(left - verticalNumbering.Width - fontPadding, bottom - (verticalNumbering.Height / 2)));
            verticalNumbering = new FormattedText("p", System.Globalization.CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight, new Typeface("Arial"), fontSize, uiColor);
            drawingContext.DrawText(verticalNumbering, new Point(left - verticalNumbering.Width - fontPadding, top - (verticalNumbering.Height / 3)));

            // Axis numbering - Horizontal
            verticalNumbering = new FormattedText(leftDataBound.ToString(), System.Globalization.CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight, new Typeface("Arial"), fontSize, uiColor);
            drawingContext.DrawText(verticalNumbering, new Point(left - verticalNumbering.Width / 2, bottom + fontPadding));
            verticalNumbering = new FormattedText(rightDataBound.ToString(), System.Globalization.CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight, new Typeface("Arial"), fontSize, uiColor);
            drawingContext.DrawText(verticalNumbering, new Point(right - verticalNumbering.Width / 2, bottom + fontPadding));

            // Index drawing
            if (this.indexLocation >= 0)
            {
                this.highlightedIndex = (int)((rightDataBound - leftDataBound) * this.indexLocation + leftDataBound);
                double xposition = (int)(this.indexLocation * (right - left) + left) + 0.5;
                verticalNumbering = new FormattedText(highlightedIndex.ToString(), System.Globalization.CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight, new Typeface("Arial"), fontSize, uiColor);
                if (this.indexLocation > 0.9)
                {
                    drawingContext.DrawText(verticalNumbering, new Point(xposition - 5 - verticalNumbering.Width, top + 10));
                }
                else
                {
                    drawingContext.DrawText(verticalNumbering, new Point(xposition + 5, top + 10));
                }
            }

            // Pop border clipping region
            drawingContext.Pop();

            base.OnRender(drawingContext);
        }
예제 #16
0
 protected override void OnRender(DrawingContext drawingContext)
 {
     drawingContext.DrawGeometry(null, pen, geometry);
 }
    protected override void OnRender(DrawingContext drawingContext)
    {
        this.EnsureGeometry();

        drawingContext.DrawGeometry(this.Fill, new Pen(this.Stroke, this.StrokeThickness), this.textGeometry);
    }
        protected override void OnRender(DrawingContext drawingContext)
        {
            var   cornerRadius = this.CornerRadius;
            var   rect         = new Rect(new Point(ShadowDepth, ShadowDepth), new Size(base.RenderSize.Width, base.RenderSize.Height));
            Color c            = this.Color;

            if ((rect.Width <= 0.0 || rect.Height <= 0.0) || c.A <= 0)
            {
                return;
            }

            var width   = (rect.Right - rect.Left) - 10.0;
            var height  = (rect.Bottom - rect.Top) - 10.0;
            var minSide = Math.Min(width * ShadowDepth, height * ShadowDepth);

            cornerRadius.TopLeft     = Math.Min(cornerRadius.TopLeft, minSide);
            cornerRadius.TopRight    = Math.Min(cornerRadius.TopRight, minSide);
            cornerRadius.BottomLeft  = Math.Min(cornerRadius.BottomLeft, minSide);
            cornerRadius.BottomRight = Math.Min(cornerRadius.BottomRight, minSide);

            Brush[] brushes = this.GetBrushes(c, cornerRadius);

            var topMargin    = rect.Top + ShadowDepth;
            var leftMargin   = rect.Left + ShadowDepth;
            var rightMargin  = rect.Right - ShadowDepth;
            var bottomMargin = rect.Bottom - ShadowDepth;

            var guidelinesX = new[]
            {
                leftMargin,
                leftMargin + cornerRadius.TopLeft,
                rightMargin - cornerRadius.TopRight,
                leftMargin + cornerRadius.BottomLeft,
                rightMargin - cornerRadius.BottomRight,
                rightMargin
            };

            var guidelinesY = new[]
            {
                topMargin,
                topMargin + cornerRadius.TopLeft,
                topMargin + cornerRadius.TopRight,
                bottomMargin - cornerRadius.BottomLeft,
                bottomMargin - cornerRadius.BottomRight,
                bottomMargin
            };

            drawingContext.PushGuidelineSet(new GuidelineSet(guidelinesX, guidelinesY));

            cornerRadius.TopLeft     += ShadowDepth;
            cornerRadius.TopRight    += ShadowDepth;
            cornerRadius.BottomLeft  += ShadowDepth;
            cornerRadius.BottomRight += ShadowDepth;

            var shadowRect = new Rect(rect.Left, rect.Top, cornerRadius.TopLeft, cornerRadius.TopLeft);

            drawingContext.DrawRectangle(brushes[0], null, shadowRect);

            double firstX = guidelinesX[2] - guidelinesX[1];

            if (firstX > 0.0)
            {
                drawingContext.DrawRectangle(brushes[1], null, new Rect(guidelinesX[1], rect.Top, firstX, 5.0));
            }

            drawingContext.DrawRectangle(brushes[2], null, new Rect(guidelinesX[2], rect.Top, cornerRadius.TopRight, cornerRadius.TopRight));

            double firstY = guidelinesY[3] - guidelinesY[1];

            if (firstY > 0.0)
            {
                drawingContext.DrawRectangle(brushes[3], null, new Rect(rect.Left, guidelinesY[1], 5.0, firstY));
            }

            double middleY = guidelinesY[4] - guidelinesY[2];

            if (middleY > 0.0)
            {
                drawingContext.DrawRectangle(brushes[5], null, new Rect(guidelinesX[5], guidelinesY[2], 5.0, middleY));
            }

            drawingContext.DrawRectangle(brushes[6], null, new Rect(rect.Left, guidelinesY[3], cornerRadius.BottomLeft, cornerRadius.BottomLeft));

            double middleX = guidelinesX[4] - guidelinesX[3];

            if (middleX > 0.0)
            {
                drawingContext.DrawRectangle(brushes[7], null, new Rect(guidelinesX[3], guidelinesY[5], middleX, 5.0));
            }

            drawingContext.DrawRectangle(brushes[8], null, new Rect(guidelinesX[4], guidelinesY[4], cornerRadius.BottomRight, cornerRadius.BottomRight));

            if (cornerRadius.TopLeft == ShadowDepth &&
                cornerRadius.TopLeft == cornerRadius.TopRight &&
                cornerRadius.TopLeft == cornerRadius.BottomLeft &&
                cornerRadius.TopLeft == cornerRadius.BottomRight)
            {
                drawingContext.DrawRectangle(brushes[4], null, new Rect(guidelinesX[0], guidelinesY[0], width, height));
            }
            else
            {
                var figure = new PathFigure();

                if (cornerRadius.TopLeft > ShadowDepth)
                {
                    figure.StartPoint = new Point(guidelinesX[1], guidelinesY[0]);
                    figure.Segments.Add(new LineSegment(new Point(guidelinesX[1], guidelinesY[1]), true));
                    figure.Segments.Add(new LineSegment(new Point(guidelinesX[0], guidelinesY[1]), true));
                }
                else
                {
                    figure.StartPoint = new Point(guidelinesX[0], guidelinesY[0]);
                }

                if (cornerRadius.BottomLeft > ShadowDepth)
                {
                    figure.Segments.Add(new LineSegment(new Point(guidelinesX[0], guidelinesY[3]), true));
                    figure.Segments.Add(new LineSegment(new Point(guidelinesX[3], guidelinesY[3]), true));
                    figure.Segments.Add(new LineSegment(new Point(guidelinesX[3], guidelinesY[5]), true));
                }
                else
                {
                    figure.Segments.Add(new LineSegment(new Point(guidelinesX[0], guidelinesY[5]), true));
                }

                if (cornerRadius.BottomRight > ShadowDepth)
                {
                    figure.Segments.Add(new LineSegment(new Point(guidelinesX[4], guidelinesY[5]), true));
                    figure.Segments.Add(new LineSegment(new Point(guidelinesX[4], guidelinesY[4]), true));
                    figure.Segments.Add(new LineSegment(new Point(guidelinesX[5], guidelinesY[4]), true));
                }
                else
                {
                    figure.Segments.Add(new LineSegment(new Point(guidelinesX[5], guidelinesY[5]), true));
                }

                if (cornerRadius.TopRight > ShadowDepth)
                {
                    figure.Segments.Add(new LineSegment(new Point(guidelinesX[5], guidelinesY[2]), true));
                    figure.Segments.Add(new LineSegment(new Point(guidelinesX[2], guidelinesY[2]), true));
                    figure.Segments.Add(new LineSegment(new Point(guidelinesX[2], guidelinesY[0]), true));
                }
                else
                {
                    figure.Segments.Add(new LineSegment(new Point(guidelinesX[5], guidelinesY[0]), true));
                }

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

                var geometry = new PathGeometry();
                geometry.Figures.Add(figure);
                geometry.Freeze();

                drawingContext.DrawGeometry(brushes[4], null, geometry);
            }

            drawingContext.Pop();
        }
예제 #19
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            drawingContext.DrawGeometry(Background, CreatePen(), _pathGeometry);
        }
예제 #20
0
 protected override void OnRender(DrawingContext dc)
 {
     base.OnRender(dc);
     dc.DrawGeometry(null, this._drawingPen, this._pathGeometry);
     dc.DrawRectangle(Brushes.Transparent, null, new Rect(RenderSize));
 }
예제 #21
0
 protected virtual void Render(DrawingContext dc)
 {
     dc.DrawGeometry(_BGBrush, _Outline, _BGGeometry);
     dc.DrawGeometry(_IconBrush, new Pen(Brushes.Transparent, 1), _IconGeometry);
 }
예제 #22
0
        void drawMacd(DrawingContext dc, double left, double top, double width, double height)
        {
            double highest = priceFile.getHighestMacdDiff(drawItemStartIndex, drawItemStartIndex + drawItemCount);
            double lowest  = priceFile.getLowestMacdDiff(drawItemStartIndex, drawItemStartIndex + drawItemCount);

            if (highest < -lowest)
            {
                highest = -lowest;
            }
            //draw histo
            var pen = getPen(0, 0, 255, 1);

            dc.DrawLine(pen, new Point(left, top + height / 2 + 0.5), new Point(left + width, top + height / 2 + 0.5));

            var macdDiff = priceFile.macdDiff;

            for (var i = 0; i < drawItemCount; ++i)
            {
                var itemIndex = drawItemStartIndex + i;
                var xoffset   = (int)(i * (itemWidth + itemSpace)) + 0.5 + left;
                var yoffset   = height - (int)((macdDiff[itemIndex] + highest) / (2 * highest) * height) + 0.5 + top;
                if (itemIndex > 0)
                {
                    if (macdDiff[itemIndex] * macdDiff[itemIndex - 1] < 0)
                    {
                        if (macdDiff[itemIndex - 1] < 0)
                        {
                            dc.DrawLine(getPen(255, 0, 0, 2.5), new Point(xoffset, top + height / 2 - 4), new Point(xoffset, top + height / 2 + 4));
                        }
                        if (macdDiff[itemIndex - 1] > 0)
                        {
                            dc.DrawLine(getPen(0, 128, 0, 2.5), new Point(xoffset, top + height / 2 - 4), new Point(xoffset, top + height / 2 + 4));
                        }

                        continue;
                    }
                }

                pen.Thickness = 1;
                dc.DrawLine(pen, new Point(xoffset, top + height / 2 + 0.5), new Point(xoffset, yoffset));
            }



            double diffHigh = priceFile.getHighestEmaDiff(drawItemStartIndex, drawItemStartIndex + drawItemCount);

            highest = priceFile.getHighestDea(drawItemStartIndex, drawItemStartIndex + drawItemCount);
            if (diffHigh > highest)
            {
                highest = diffHigh;
            }
            var diffLow = priceFile.getLowestEmaDiff(drawItemStartIndex, drawItemStartIndex + drawItemCount);

            lowest = priceFile.getLowestDea(drawItemStartIndex, drawItemStartIndex + drawItemCount);
            if (lowest > diffLow)
            {
                lowest = diffLow;
            }

            // fast line
            pen = getPen(255, 0, 0, 1);
            var emaDiff = priceFile.emaDiff;

            PathFigure   pfFast = new PathFigure();
            PathGeometry pgFast = new PathGeometry();

            pgFast.Figures.Add(pfFast);


            for (var i = 0; i < drawItemCount; ++i)
            {
                var itemIndex = drawItemStartIndex + i;
                var xoffset   = (int)(i * (itemWidth + itemSpace)) + 0.5 + left;
                var yoffset   = (int)((highest - emaDiff[itemIndex]) / (highest - lowest) * height) + 0.5 + top;

                if (i == 0)
                {
                    pfFast.StartPoint = new Point(xoffset, yoffset);
                }
                else
                {
                    pfFast.Segments.Add(new LineSegment(new Point(xoffset, yoffset), true));
                }
            }
            dc.DrawGeometry(Brushes.Transparent, pen, pgFast);

            //slow line
            pen = getPen(0, 128, 0, 1);
            PathFigure   pfSlow = new PathFigure();
            PathGeometry pgSlow = new PathGeometry();

            pgSlow.Figures.Add(pfSlow);

            var dea = priceFile.dea;

            for (var i = 0; i < drawItemCount; ++i)
            {
                var itemIndex = drawItemStartIndex + i;
                var xoffset   = (int)(i * (itemWidth + itemSpace)) + 0.5 + left;
                var yoffset   = (int)((highest - dea[itemIndex]) / (highest - lowest) * height) + 0.5 + top;

                if (i == 0)
                {
                    pfSlow.StartPoint = new Point(xoffset, yoffset);
                }
                else
                {
                    pfSlow.Segments.Add(new LineSegment(new Point(xoffset, yoffset), true));
                }
            }
            dc.DrawGeometry(Brushes.Transparent, pen, pgSlow);
        }
예제 #23
0
        /// <summary>
        /// Renders a bond to the display
        /// </summary>
        public override void Render()
        {
            Atom startAtom = ParentBond.StartAtom;
            Atom endAtom   = ParentBond.EndAtom;

            //set up the shared variables first
            Point startPoint = startAtom.Position;
            Point endPoint   = endAtom.Position;

            double bondLength = ParentBond.Model.XamlBondLength;

            // Only continue if bond length is not zero
            if (startPoint != endPoint)
            {
                //now get the geometry of start and end atoms
                AtomVisual startVisual = (AtomVisual)ChemicalVisuals[startAtom];
                AtomVisual endVisual   = (AtomVisual)ChemicalVisuals[endAtom];

                //first grab the main descriptor
                BondDescriptor = GetBondDescriptor(ParentBond, startVisual, endVisual, bondLength, Standoff);

                _enclosingPoly = BondDescriptor.Boundary;
                //set up the default pens for rendering
                _mainBondPen = new Pen(Brushes.Black, BondThickness)
                {
                    StartLineCap = PenLineCap.Round,
                    EndLineCap   = PenLineCap.Round,
                    LineJoin     = PenLineJoin.Miter
                };

                _subsidiaryBondPen = _mainBondPen.Clone();

                switch (ParentBond.Order)
                {
                case Globals.OrderZero:
                case Globals.OrderOther:
                case "unknown":
                    // Handle Zero Bond
                    _mainBondPen.DashStyle = DashStyles.Dot;

                    using (DrawingContext dc = RenderOpen())
                    {
                        dc.DrawGeometry(Brushes.Black, _mainBondPen, BondDescriptor.DefiningGeometry);
                        //we need to draw another transparent rectangle to expand the bounding box
                        DrawHitTestOverlay(dc);
                        dc.Close();
                    }

                    DoubleBondLayout dbd = new DoubleBondLayout
                    {
                        Start     = startPoint,
                        End       = endPoint,
                        Placement = ParentBond.Placement
                    };

                    BondGeometry.GetDoubleBondPoints(dbd, bondLength);
                    _enclosingPoly = dbd.Boundary;
                    break;

                case Globals.OrderPartial01:
                    _mainBondPen.DashStyle = DashStyles.Dash;

                    using (DrawingContext dc = RenderOpen())
                    {
                        dc.DrawGeometry(Brushes.Black, _mainBondPen, BondDescriptor.DefiningGeometry);
                        //we need to draw another transparent thicker line on top of the existing one
                        DrawHitTestOverlay(dc);
                        dc.Close();
                    }

                    //grab the enclosing polygon as for a double ParentBond - this overcomes a hit testing bug
                    DoubleBondLayout dbd2 = new DoubleBondLayout
                    {
                        Start     = startPoint,
                        End       = endPoint,
                        Placement = ParentBond.Placement
                    };

                    BondGeometry.GetDoubleBondPoints(dbd2, bondLength);
                    _enclosingPoly = dbd2.Boundary;

                    break;

                case "1":
                case Globals.OrderSingle:
                    // Handle Single bond
                    switch (ParentBond.Stereo)
                    {
                    case Globals.BondStereo.Indeterminate:
                    case Globals.BondStereo.None:
                    case Globals.BondStereo.Wedge:
                        using (DrawingContext dc = RenderOpen())
                        {
                            dc.DrawGeometry(Brushes.Black, _mainBondPen, BondDescriptor.DefiningGeometry);
                            //we need to draw another transparent rectangle to expand the bounding box
                            DrawHitTestOverlay(dc);
                            dc.Close();
                        }

                        break;

                    case Globals.BondStereo.Hatch:
                        using (DrawingContext dc = RenderOpen())
                        {
                            dc.DrawGeometry(GetHatchBrush(ParentBond.Angle), _mainBondPen,
                                            BondDescriptor.DefiningGeometry);
                            //we need to draw another transparent rectangle to expand the bounding box
                            DrawHitTestOverlay(dc);
                            dc.Close();
                        }

                        break;
                    }

                    break;

                case Globals.OrderPartial12:
                case Globals.OrderAromatic:
                case "2":
                case Globals.OrderDouble:
                    DoubleBondLayout dbd3     = (DoubleBondLayout)BondDescriptor;
                    Point?           centroid = ParentBond.Centroid;
                    dbd3.PrimaryCentroid = centroid;

                    if (ParentBond.Order == Globals.OrderPartial12 || ParentBond.Order == Globals.OrderAromatic
                        ) // Handle 1.5 bond
                    {
                        _subsidiaryBondPen.DashStyle = DashStyles.Dash;
                    }

                    _enclosingPoly = dbd3.Boundary;

                    if (ParentBond.Stereo != Globals.BondStereo.Indeterminate)
                    {
                        using (DrawingContext dc = RenderOpen())
                        {
                            dc.DrawLine(_mainBondPen, BondDescriptor.Start, BondDescriptor.End);
                            dc.DrawLine(_subsidiaryBondPen,
                                        dbd3.SecondaryStart,
                                        dbd3.SecondaryEnd);
                            dc.Close();
                        }
                    }
                    else
                    {
                        using (DrawingContext dc = RenderOpen())
                        {
                            dc.DrawGeometry(_mainBondPen.Brush, _mainBondPen, BondDescriptor.DefiningGeometry);

                            dc.Close();
                        }
                    }

                    break;

                case Globals.OrderPartial23:
                case "3":
                case Globals.OrderTriple:
                    if (ParentBond.Order == Globals.OrderPartial23)     // Handle 2.5 bond
                    {
                        _subsidiaryBondPen.DashStyle = DashStyles.Dash;
                    }

                    var tbd = (BondDescriptor as TripleBondLayout);
                    using (DrawingContext dc = RenderOpen())
                    {
                        if (ParentBond.Placement == Globals.BondDirection.Clockwise)
                        {
                            dc.DrawLine(_mainBondPen, tbd.SecondaryStart, tbd.SecondaryEnd);
                            dc.DrawLine(_mainBondPen, tbd.Start, tbd.End);
                            dc.DrawLine(_subsidiaryBondPen, tbd.TertiaryStart, tbd.TertiaryEnd);
                        }
                        else
                        {
                            dc.DrawLine(_subsidiaryBondPen, tbd.SecondaryStart, tbd.SecondaryEnd);
                            dc.DrawLine(_mainBondPen, tbd.Start, tbd.End);
                            dc.DrawLine(_mainBondPen, tbd.TertiaryStart, tbd.TertiaryEnd);
                        }

                        dc.Close();
                    }

                    break;
                }
            }

            //local function
            void DrawHitTestOverlay(DrawingContext dc)
            {
                SolidColorBrush outliner = new SolidColorBrush(Colors.Salmon);

#if SHOWBOUNDS
                outliner.Opacity = 0.2d;
#else
                outliner.Opacity = 0d;
#endif

                Pen outlinePen = new Pen(outliner, BondThickness * 5);
                dc.DrawGeometry(outliner, outlinePen, BondDescriptor.DefiningGeometry);
            }
        }
예제 #24
0
        //draw stock curve.
        void drawTimeLine(DrawingContext dc, double left, double top, double width, double height)
        {
            if (priceFile == null)
            {
                return;
            }

            var itemOffset = this.width / totalItemCount;

            //draw time line
            var yearLast = 0;

            for (var i = 0; i < totalItemCount; i++)
            {
                var xoffset = (int)(i * itemOffset) + left + 0.5;
                var year    = (int)(priceFile.Dates[i] / 10000);
                if (year > yearLast)
                {
                    FormattedText txt = new FormattedText(year.ToString(),
                                                          System.Globalization.CultureInfo.CurrentCulture,
                                                          FlowDirection.LeftToRight, new Typeface("Verdana"),
                                                          12, new SolidColorBrush(Color.FromRgb(64, 64, 64)));
                    dc.DrawText(txt, new Point(xoffset, top + height - 16));
                }
                yearLast = year;
            }

            //draw curve line
            var highest = priceFile.getHighest(0, totalItemCount);
            var lowest  = priceFile.getLowest(0, totalItemCount);

            var pixelcount = 3;
            var inc        = (int)(totalItemCount * pixelcount / this.width);

            if (inc == 0)
            {
                inc = 1;
            }

            //var color = "#30b8f3";
            var pen = getPen(48, 184, 243, 1);


            //draw line curve.
            PathFigure   pf = new PathFigure();
            PathGeometry pg = new PathGeometry();

            pg.Figures.Add(pf);


            for (var i = 0; i < totalItemCount; i += inc)
            {
                var xoffset = (int)(i * itemOffset) + 0.5 + left;
                var yClose  = (int)((highest - priceFile.Closes[i]) / (highest - lowest) * (height - 12)) + 0.5 + top;

                if (i == 0)
                {
                    pf.StartPoint = new Point(xoffset, yClose);
                }
                else
                {
                    pf.Segments.Add(new LineSegment(new Point(xoffset, yClose), true));
                }
            }

            dc.DrawGeometry(Brushes.Transparent, pen, pg);

            //draw item time region button
            //this item offset is
            double x      = (int)(drawItemStartIndex * itemOffset) + left + 0.5;
            var    xwidth = (int)(drawItemCount * itemOffset);

            var brush = getBrush(224, 224, 255, 128);

            pen = getPen(224, 224, 255, 1, 128);
            dc.DrawRectangle(brush, pen, new Rect(x, top, xwidth, height));
        }
예제 #25
0
        //=============================================================================
        public override void Draw(DrawingContext dc, ICoordinateSystem cs, IGeomDisplaySettings geomDisplaySettings = null)
        {
            if (dc == null)
            {
                return;
            }

            if (cs == null)
            {
                return;
            }

            if (m_Sheet == null)
            {
                return;
            }

            IGeomDisplaySettings displaySettings = geomDisplaySettings;

            if (displaySettings == null)
            {
                displaySettings = new DefaultGeomDisplaySettings();
            }
            if (displaySettings == null)
            {
                return;
            }

            Pen pen = this.BorderPen;
            //
            // If fill with transparent color then circle fill area will act in HitTest.
            // Fill with null brush will disable circle HitTest on click in fill area.
            Color fillColor = displaySettings.GetFillColor(this);
            Brush fillBrush = new SolidColorBrush(fillColor);

            fillBrush.Opacity = displaySettings.FillBrushOpacity;

            // Draw shutter rectangle without SwingDoor
            Point TopLeft_ScreenPoint     = GetLocalPoint(cs, m_TopLeft_GlobalPoint);
            Point BottomRight_ScreenPoint = GetLocalPoint(cs, BottomRight_GlobalPoint);

            dc.DrawRectangle(fillBrush, pen, new Rect(TopLeft_ScreenPoint, BottomRight_ScreenPoint));

            // draw Swing Door
            if (m_SwingDoor)
            {
                double       doorLength         = SwingDoorLength;
                double       doorLengthInPixels = GetWidthInPixels(cs, doorLength);
                PathGeometry swingDoorGeom      = new PathGeometry();

                if (this.IsHorizontal)
                {
                    if (Utils.FLE(m_TopLeft_GlobalPoint.Y, 0.0))
                    {
                        // shutter is placed at top border
                        PathFigure leftDoorFigure = new PathFigure();
                        leftDoorFigure.StartPoint = GetLocalPoint(cs, BottomLeft_GlobalPoint);
                        leftDoorFigure.Segments.Add(new LineSegment(GetLocalPoint(cs, BottomLeft_GlobalPoint + doorLength * new Vector(0.0, 1.0)), true));
                        leftDoorFigure.Segments.Add(new ArcSegment(
                                                        GetLocalPoint(cs, BottomLeft_GlobalPoint + doorLength * new Vector(1.0, 0.0)),
                                                        new Size(doorLengthInPixels, doorLengthInPixels),
                                                        0.0,
                                                        false,
                                                        SweepDirection.Counterclockwise,
                                                        true)
                                                    );
                        swingDoorGeom.Figures.Add(leftDoorFigure);

                        PathFigure rightDoorFigure = new PathFigure();
                        rightDoorFigure.StartPoint = GetLocalPoint(cs, BottomRight_GlobalPoint);
                        rightDoorFigure.Segments.Add(new LineSegment(GetLocalPoint(cs, BottomRight_GlobalPoint + doorLength * new Vector(0.0, 1.0)), true));
                        rightDoorFigure.Segments.Add(new ArcSegment(
                                                         GetLocalPoint(cs, BottomRight_GlobalPoint + doorLength * new Vector(-1.0, 0.0)),
                                                         new Size(doorLengthInPixels, doorLengthInPixels),
                                                         0.0,
                                                         false,
                                                         SweepDirection.Clockwise,
                                                         true)
                                                     );
                        swingDoorGeom.Figures.Add(rightDoorFigure);
                    }
                    else
                    {
                        // shutter is placed at bot border
                        PathFigure leftDoorFigure = new PathFigure();
                        leftDoorFigure.StartPoint = GetLocalPoint(cs, m_TopLeft_GlobalPoint);
                        leftDoorFigure.Segments.Add(new LineSegment(GetLocalPoint(cs, m_TopLeft_GlobalPoint + doorLength * new Vector(0.0, -1.0)), true));
                        leftDoorFigure.Segments.Add(new ArcSegment(
                                                        GetLocalPoint(cs, m_TopLeft_GlobalPoint + doorLength * new Vector(1.0, 0.0)),
                                                        new Size(doorLengthInPixels, doorLengthInPixels),
                                                        0.0,
                                                        false,
                                                        SweepDirection.Clockwise,
                                                        true)
                                                    );
                        swingDoorGeom.Figures.Add(leftDoorFigure);

                        PathFigure rightDoorFigure = new PathFigure();
                        rightDoorFigure.StartPoint = GetLocalPoint(cs, TopRight_GlobalPoint);
                        rightDoorFigure.Segments.Add(new LineSegment(GetLocalPoint(cs, TopRight_GlobalPoint + doorLength * new Vector(0.0, -1.0)), true));
                        rightDoorFigure.Segments.Add(new ArcSegment(
                                                         GetLocalPoint(cs, TopRight_GlobalPoint + doorLength * new Vector(-1.0, 0.0)),
                                                         new Size(doorLengthInPixels, doorLengthInPixels),
                                                         0.0,
                                                         false,
                                                         SweepDirection.Counterclockwise,
                                                         true)
                                                     );
                        swingDoorGeom.Figures.Add(rightDoorFigure);
                    }
                }
                else
                {
                    if (Utils.FLE(m_TopLeft_GlobalPoint.X, 0.0))
                    {
                        // shutter is placed at left border
                        PathFigure topDoorFigure = new PathFigure();
                        topDoorFigure.StartPoint = GetLocalPoint(cs, TopRight_GlobalPoint);
                        topDoorFigure.Segments.Add(new LineSegment(GetLocalPoint(cs, TopRight_GlobalPoint + doorLength * new Vector(1.0, 0.0)), true));
                        topDoorFigure.Segments.Add(new ArcSegment(
                                                       GetLocalPoint(cs, TopRight_GlobalPoint + doorLength * new Vector(0.0, 1.0)),
                                                       new Size(doorLengthInPixels, doorLengthInPixels),
                                                       0.0,
                                                       false,
                                                       SweepDirection.Clockwise,
                                                       true)
                                                   );
                        swingDoorGeom.Figures.Add(topDoorFigure);

                        PathFigure botDoorFigure = new PathFigure();
                        botDoorFigure.StartPoint = GetLocalPoint(cs, BottomRight_GlobalPoint);
                        botDoorFigure.Segments.Add(new LineSegment(GetLocalPoint(cs, BottomRight_GlobalPoint + doorLength * new Vector(1.0, 0.0)), true));
                        botDoorFigure.Segments.Add(new ArcSegment(
                                                       GetLocalPoint(cs, BottomRight_GlobalPoint + doorLength * new Vector(0.0, -1.0)),
                                                       new Size(doorLengthInPixels, doorLengthInPixels),
                                                       0.0,
                                                       false,
                                                       SweepDirection.Counterclockwise,
                                                       true)
                                                   );
                        swingDoorGeom.Figures.Add(botDoorFigure);
                    }
                    else
                    {
                        // shutter is placed at right border
                        PathFigure topDoorFigure = new PathFigure();
                        topDoorFigure.StartPoint = GetLocalPoint(cs, m_TopLeft_GlobalPoint);
                        topDoorFigure.Segments.Add(new LineSegment(GetLocalPoint(cs, m_TopLeft_GlobalPoint + doorLength * new Vector(-1.0, 0.0)), true));
                        topDoorFigure.Segments.Add(new ArcSegment(
                                                       GetLocalPoint(cs, m_TopLeft_GlobalPoint + doorLength * new Vector(0.0, 1.0)),
                                                       new Size(doorLengthInPixels, doorLengthInPixels),
                                                       0.0,
                                                       false,
                                                       SweepDirection.Counterclockwise,
                                                       true)
                                                   );
                        swingDoorGeom.Figures.Add(topDoorFigure);

                        PathFigure botDoorFigure = new PathFigure();
                        botDoorFigure.StartPoint = GetLocalPoint(cs, BottomLeft_GlobalPoint);
                        botDoorFigure.Segments.Add(new LineSegment(GetLocalPoint(cs, BottomLeft_GlobalPoint + doorLength * new Vector(-1.0, 0.0)), true));
                        botDoorFigure.Segments.Add(new ArcSegment(
                                                       GetLocalPoint(cs, BottomLeft_GlobalPoint + doorLength * new Vector(0.0, -1.0)),
                                                       new Size(doorLengthInPixels, doorLengthInPixels),
                                                       0.0,
                                                       false,
                                                       SweepDirection.Clockwise,
                                                       true)
                                                   );
                        swingDoorGeom.Figures.Add(botDoorFigure);
                    }
                }

                // Draw transparent rectangle over all swing door.
                // Otherwise, user cant select shutter by click swing door.
                dc.DrawGeometry(Brushes.Transparent, null, swingDoorGeom);
                // Draw swing door with pen
                dc.DrawGeometry(null, pen, swingDoorGeom);
            }
        }
예제 #26
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            if (this.ConnectionLinePen != null)
            {
                bool left   = false;
                bool top    = false;
                bool middle = false;

                switch (this.ConnectionLineAlignment)
                {
                case ConnectionLineAlignment.LeftToBottom:
                    left = true;
                    break;

                case ConnectionLineAlignment.RightToTop:
                    top = true;
                    break;

                case ConnectionLineAlignment.LeftToTop:
                    left = true;
                    top  = true;
                    break;

                case ConnectionLineAlignment.CenterToCenter:
                    middle = true;
                    break;

                case ConnectionLineAlignment.RightToBottom:
                default:
                    break;
                }

                //cycling with count -1 because we don't want to draw a ligne after last item
                for (int i = 0; i < this.InternalChildren.Count - 1; i++)
                {
                    UIElement startItem = this.InternalChildren[i];
                    UIElement endItem   = this.InternalChildren[i + 1];

                    Vector startOffset = VisualTreeHelper.GetOffset(startItem);
                    Vector endOffset   = VisualTreeHelper.GetOffset(endItem);

                    Size startSize = startItem.RenderSize;
                    Size endSize   = endItem.RenderSize;

                    double startPointX = 0.0d;
                    double startPointY = 0.0d;
                    double endPointX   = 0.0d;
                    double endPointY   = 0.0d;

                    List <PathSegment> myPathSegments = null;

                    GuidelineSet guidelineSet = new GuidelineSet();
                    drawingContext.PushGuidelineSet(guidelineSet);

                    if (middle == true)
                    {
                        startPointX = startOffset.X + startSize.Width + this.ConnectionLineOffset;

                        startPointY = startOffset.Y + (startSize.Height / 2);

                        endPointY = endOffset.Y + (endSize.Height / 2);

                        endPointX = endOffset.X - this.ConnectionLineOffset;

                        double deltaX = (endPointX - startPointX);

                        guidelineSet.GuidelinesX.Add(startPointX);
                        guidelineSet.GuidelinesX.Add(startPointX + (deltaX / 2) + 0.5d);
                        guidelineSet.GuidelinesX.Add(startPointX + deltaX);
                        guidelineSet.GuidelinesY.Add(startPointY);
                        guidelineSet.GuidelinesY.Add(endPointY);

                        myPathSegments = new List <PathSegment>(4); //we know there are going be only 4 segments
                        myPathSegments.Add(new LineSegment(new Point(startPointX, startPointY), true));
                        myPathSegments.Add(new LineSegment(new Point(startPointX + (deltaX / 2), startPointY), true));
                        myPathSegments.Add(new LineSegment(new Point(startPointX + (deltaX / 2), endPointY), true));
                        myPathSegments.Add(new LineSegment(new Point(startPointX + deltaX, endPointY), true));
                    }
                    else
                    {
                        if (left == true)
                        {
                            startPointX = startOffset.X + this.ConnectionLineOffset;
                        }
                        else
                        {
                            startPointX = startOffset.X + startSize.Width - this.ConnectionLineOffset;
                        }

                        startPointY = startOffset.Y + startSize.Height;

                        if (top == true)
                        {
                            endPointY = endOffset.Y + this.ConnectionLineOffset;
                        }
                        else
                        {
                            endPointY = endOffset.Y + endSize.Height - this.ConnectionLineOffset;
                        }

                        endPointX = endOffset.X;

                        guidelineSet.GuidelinesX.Add(startPointX);
                        guidelineSet.GuidelinesX.Add(endPointX);
                        guidelineSet.GuidelinesY.Add(startPointY);
                        guidelineSet.GuidelinesY.Add(endPointY);

                        myPathSegments = new List <PathSegment>(2); //we know there are going be only 2 segments
                        myPathSegments.Add(new LineSegment(new Point(startPointX, endPointY), true));
                        myPathSegments.Add(new LineSegment(new Point(endPointX, endPointY), true));
                    }

                    PathFigure myPathFigure = new PathFigure(new Point(startPointX, startPointY), myPathSegments, false);

                    PathGeometry myPathGeometry = new PathGeometry();
                    myPathGeometry.Figures.Add(myPathFigure);

                    drawingContext.DrawGeometry(null, this.ConnectionLinePen, myPathGeometry);

                    // pop the context to remove the GuidelineSet
                    drawingContext.Pop();
                }
            }

            base.OnRender(drawingContext);
        }
예제 #27
0
        /// <summary>
        /// Draws the background of line based on its <see cref="DiffContext"/>
        /// and whether it is imaginary or not.
        /// </summary>
        /// <param name="textView"></param>
        /// <param name="drawingContext"></param>
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (_DiffView == null)
            {
                return;
            }

            var srcLineDiffs = _DiffView.ItemsSource as IReadOnlyList <IDiffLineInfo>;

            if (srcLineDiffs == null)
            {
                return;
            }

            var toBeRequested = new List <int>();

            foreach (var v in textView.VisualLines)
            {
                var linenum = v.FirstDocumentLine.LineNumber - 1;

                // Find a diff context for a given line
                if (linenum >= srcLineDiffs.Count)
                {
                    continue;
                }

                // Determine change context (delete, insert, change) per line
                //  and color background according to bound brush
                var srcLineDiff = srcLineDiffs[linenum];
                var brush       = GetLineBackgroundDiffBrush(srcLineDiff.Context, srcLineDiff.ImaginaryLineNumber.HasValue == false);

                if (brush != default(SolidColorBrush))
                {
                    foreach (var rc in BackgroundGeometryBuilder.GetRectsFromVisualSegment(textView, v, 0, v.VisualLength))
                    {
                        drawingContext.DrawRectangle(brush, BorderlessPen,
                                                     new Rect(0, rc.Top, textView.ActualWidth, rc.Height));
                    }
                }

                if (srcLineDiff.LineEditScriptSegments != null)
                {
                    foreach (var item in srcLineDiff.LineEditScriptSegments)
                    {
                        // The main line background has already been drawn, so we just
                        // need to draw the deleted or inserted background segments.
                        if (srcLineDiff.FromA)
                        {
                            brush = _DiffView.ColorBackgroundDeleted;
                        }
                        else
                        {
                            brush = _DiffView.ColorBackgroundAdded;
                        }

                        BackgroundGeometryBuilder geoBuilder = new BackgroundGeometryBuilder();
                        geoBuilder.AlignToWholePixels = true;

                        var segment = new Segment(v.StartOffset + item.Offset, item.Length,
                                                  v.StartOffset + item.EndOffset);
                        geoBuilder.AddSegment(textView, segment);

                        Geometry geometry = geoBuilder.CreateGeometry();
                        if (geometry != null)
                        {
                            drawingContext.DrawGeometry(brush, null, geometry);
                        }
                    }
                }
                else
                {
                    // Has this line ever been computed before ?
                    if (srcLineDiff.LineEditScriptSegmentsIsDirty == true &&
                        _DiffView.LineDiffDataProvider != null)
                    {
                        toBeRequested.Add(linenum);
                    }
                }
            }

            // Request matching of additional lines if these appear to be dirty
            if (toBeRequested.Count > 0)
            {
                _DiffView.LineDiffDataProvider.RequestLineDiff(toBeRequested);
            }
        }
 public override void DrawPath(RPen pen, RGraphicsPath path)
 {
     _g.DrawGeometry(null, ((PenAdapter)pen).CreatePen(), ((GraphicsPathAdapter)path).GetClosedGeometry());
 }
예제 #29
0
 protected override void OnRender(DrawingContext drawingContext)
 {
     drawingContext.DrawGeometry(null, new Pen(Stroke, StrokeThickness), GetArcGeometry());
 }
예제 #30
0
 protected override void OnRender(DrawingContext drawingContext)
 {
     CreateTextGeometry();
     drawingContext.DrawGeometry(Fill, new Pen(Stroke, StrokeThickness), _textGeometry);
 }
예제 #31
0
        internal void Render(DrawingContext context, GradientBrush tabBackground, double offset)
        {
            // Do the horizontal offset first.
            (tabOuterPath.Transform as TranslateTransform).X = offset;
            (tabInnerPath.Transform as TranslateTransform).X = offset;

            Brush outerBrush = new SolidColorBrush(UIColors.CurvyTabOuterColor);
            context.DrawGeometry(Brushes.White, new Pen(outerBrush, 1), tabOuterPath);

            Brush innerBrush = new SolidColorBrush(UIColors.CurvyTabInnerColor);
            context.DrawGeometry(tabBackground, new Pen(innerBrush, 1), tabInnerPath);

            if (null == formattedText)
                RefreshFormattedText();

            // Finally, draw the display text on the tab.
            context.DrawText(formattedText, new Point(offset + (parentVisual.GapBetweenTabs + 8), 6));

            if (false != parentVisual.ShowCloseButton)
            {
                if (null == tabCloseButton)
                {
                    tabCloseButton = new PathGeometry();
                    tabCloseButton.Transform = new TranslateTransform(0, 0);
                    tabCloseButton.Figures = CreateButtonPathFigures();
                }

                Brush closeBrush = this.OverCloseButton ? Brushes.Black : Brushes.Gray;
                double closeOffset = parentVisual.TabWidth + parentVisual.GapBetweenTabs + 2;
                (tabCloseButton.Transform as TranslateTransform).X = offset + closeOffset;
                context.DrawGeometry(Brushes.Black, new Pen(closeBrush, 2), tabCloseButton);
            }
        }
예제 #32
0
 protected override void OnRender(DrawingContext drawingContext)
 {
     drawingContext.DrawGeometry(this.Brush, this.Pen, this.Geometry);
 }