public VmsViewportAdornment(IWpfTextView view, SVsServiceProvider serviceProvider)
        {
            var service = (DTE)serviceProvider.GetService(typeof(DTE));
            var properties = service.Properties["Visual Method Separators", "Global"];

            var colorProperty = properties.Item("Color");
            var color = UIntToColor(colorProperty.Value);

            var dashStyleProperty = properties.Item("PenDashStyle");
            var dashStyle = DashStyleFromInt(dashStyleProperty.Value);

            var thicknessProperty = properties.Item("Thickness");
            var thickness = (double) thicknessProperty.Value;

            _view = view;
            _view.LayoutChanged += OnLayoutChanged;

            _layer = view.GetAdornmentLayer("VmsViewportAdornment");

            _pen = new Pen(new SolidColorBrush(color), thickness)
                {
                    DashStyle = dashStyle,
                    DashCap = PenLineCap.Flat,
                };

            _pen.Freeze();
        }
Beispiel #2
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            var dashPen = new Pen(Brushes.Red, 1) { DashStyle = new DashStyle(new double[] { 1, 6 }, 0) };
            dashPen.Freeze();

            if( _grid  != null )
            {
                if (_grid.ColumnDefinitions != null)
                {
                    double xPos = 0;
                    foreach (var column in _grid.ColumnDefinitions)
                    {
                        xPos += column.ActualWidth;
                        drawingContext.DrawLine(dashPen, new Point(xPos, 0), new Point(xPos,ActualHeight));
                    }
                }
                if (_grid.RowDefinitions != null)
                {
                    double yPos = 0;
                    foreach (var column in _grid.RowDefinitions)
                    {
                        yPos += column.ActualHeight;
                        drawingContext.DrawLine(dashPen, new Point(0, yPos), new Point(ActualWidth, yPos));
                    }
                }
            }
            base.OnRender(drawingContext);
        }
        public AchievementAdornments(IWpfTextView view)
        {
            this.view = view;
            this.layer = view.GetAdornmentLayer("AchievementAdornments");
            this.descriptionLayer = view.GetAdornmentLayer("AchievementAdornmentsDescription");

            view.LayoutChanged += OnLayoutChanged;

            Brush brush = new SolidColorBrush(Color.FromArgb(0x20, 0x00, 0x00, 0xff));
            brush.Freeze();

            Brush penBrush = new SolidColorBrush(Colors.Red);
            penBrush.Freeze();

            Pen pen = new Pen(penBrush, 0.5);
            pen.Freeze();

            this.brush = brush;
            this.pen = pen;

            AchievementUIContext.AchievementClicked += (sender, e) =>
            {
                Reset();

                var filePath = GetFilePath(view);
                if (e.AchievementDescriptor.CodeOrigin.FileName != filePath)
                    return;

                codeOrigin = e.AchievementDescriptor.CodeOrigin;
                achievementUiElement = (UIElement)e.UIElement;

                CreateAdornment();
            };
        }
        /// <summary>
        /// Draw reference points on the image
        /// </summary>
        /// <param name="image">Image to draw</param>
        /// <param name="whiteAreas">White rectangles for white margin areas</param>
        /// <param name="refPoints">Black rectangles - actual reference points</param>
        /// <returns>Image with drawn reference points</returns>
        public static BitmapImage DrawReferencePoints(BitmapImage image, Rect[] whiteAreas, Rect[] refPoints)
        {
            // prepare resources
            SolidColorBrush whiteBrush = new SolidColorBrush(Colors.White);
            var             blackBrush = new SolidColorBrush(Colors.Black);
            var             whitePen   = new System.Windows.Media.Pen(whiteBrush, 1);
            var             blackPen   = new System.Windows.Media.Pen(blackBrush, 1);

            whiteBrush.Freeze();
            blackBrush.Freeze();
            whitePen.Freeze();
            blackPen.Freeze();

            var target = new RenderTargetBitmap(image.PixelWidth, image.PixelHeight, image.DpiX, image.DpiY, PixelFormats.Pbgra32);
            var visual = new DrawingVisual();

            using (DrawingContext r = visual.RenderOpen())
            {
                r.DrawImage(image, new Rect(0, 0, image.Width, image.Height));

                for (int i = 0; i < whiteAreas.Length; i++)
                {
                    r.DrawRectangle(whiteBrush, whitePen, whiteAreas[i]);
                    r.DrawRectangle(blackBrush, blackPen, refPoints[i]);
                }
            }

            // call render to render all changes on the image
            target.Render(visual);

            return(ConvertRenderTargetToBitmapImage(target));
        }
 public AreaVisual(Pen pen1)
 {
     // pen = new Pen(Brushes.SpringGreen, 10);
     pen = pen1;
     pen.Freeze();
     Redraw();
 }
 public void Draw(TextView textView, DrawingContext drawingContext)
 {
     foreach (TextSegment current in this.SearchHitsSegments)
     {
         foreach (Rect current2 in BackgroundGeometryBuilder.GetRectsForSegment(textView, current))
         {
             Point bottomLeft = current2.BottomLeft;
             Point bottomRight = current2.BottomRight;
             Pen pen = new Pen(new SolidColorBrush(Colors.OrangeRed), 1);
             pen.Freeze();
             double num = 2.5;
             int count = System.Math.Max((int)((bottomRight.X - bottomLeft.X) / num) + 1, 4);
             StreamGeometry streamGeometry = new StreamGeometry();
             using (StreamGeometryContext streamGeometryContext = streamGeometry.Open())
             {
                 streamGeometryContext.BeginFigure(bottomLeft, true, true);
                 streamGeometryContext.LineTo(current2.TopLeft, true, false);
                 streamGeometryContext.LineTo(current2.TopRight, true, false);
                 streamGeometryContext.LineTo(current2.BottomRight, true, false);
             }
             streamGeometry.Freeze();
             drawingContext.DrawGeometry(Brushes.Transparent, pen, streamGeometry);
         }
     }
 }
Beispiel #7
0
        //为图片画一个正方形边框
        private void DrawLine(DrawingVisual visual)
        {
            DrawingVisual newvis = new DrawingVisual();

            biankuang = newvis;

            var visualwidth  = (visual.ContentBounds.TopRight - visual.ContentBounds.TopLeft).X;
            var visualheight = (visual.ContentBounds.BottomLeft - visual.ContentBounds.TopLeft).Y;
            var topleft      = new System.Windows.Point(visual.Offset.X + visual.ContentBounds.TopLeft.X, visual.Offset.Y + visual.ContentBounds.TopLeft.Y);
            var topright     = new System.Windows.Point(visual.Offset.X + visual.ContentBounds.TopLeft.X + visualwidth, visual.Offset.Y + visual.ContentBounds.TopLeft.Y);
            var bottomleft   = new System.Windows.Point(visual.Offset.X + visual.ContentBounds.TopLeft.X, visual.Offset.Y + visualheight + visual.ContentBounds.TopLeft.Y);
            var bottomright  = new System.Windows.Point(visual.Offset.X + visualwidth + visual.ContentBounds.TopLeft.X, visual.Offset.Y + visualheight + visual.ContentBounds.TopLeft.Y);

            using (var dc = newvis.RenderOpen())
            {
                System.Windows.Media.Brush brush = System.Windows.Media.Brushes.Blue;
                System.Windows.Media.Pen   pen   = new System.Windows.Media.Pen(System.Windows.Media.Brushes.Blue, 2);
                dc.DrawLine(pen, topleft, topright);
                dc.DrawLine(pen, topleft, bottomleft);
                dc.DrawLine(pen, topright, bottomright);
                dc.DrawLine(pen, bottomleft, bottomright);
                pen.Freeze();
            }
            this.AddVisual(newvis);
        }
        // Create the pen and triangle in a static constructor and freeze them to improve performance.
        static InsertionAdorner()
        {
            pen = new Pen
            {
                Brush = Brushes.Gray,
                Thickness = 2
            };
            pen.Freeze();

            LineSegment firstLine = new LineSegment(new Point(0, -5), false);
            firstLine.Freeze();
            LineSegment secondLine = new LineSegment(new Point(0, 5), false);
            secondLine.Freeze();

            PathFigure figure = new PathFigure
            {
                StartPoint = new Point(5, 0)
            };
            figure.Segments.Add(firstLine);
            figure.Segments.Add(secondLine);
            figure.Freeze();

            triangle = new PathGeometry();
            triangle.Figures.Add(figure);
            triangle.Freeze();
        }
 protected override void OnRender(DrawingContext dc)
 {
     var pen = new Pen(this.Fill, this.PenWidth);
     pen.Freeze();
     var line = new Line(this.ActualWidth, this.ActualHeight, this.ReservedSpace, this.Placement, this.IsDirectionReversed);
     Vector offset = new Vector(0, 0);
     switch (this.Placement)
     {
         case TickBarPlacement.Left:
             offset = new Vector(this.ActualWidth, 0);
             break;
         case TickBarPlacement.Right:
             offset = new Vector(-1 * this.ActualWidth, 0);
             break;
         case TickBarPlacement.Top:
             offset = new Vector(0, this.ActualHeight);
             break;
         case TickBarPlacement.Bottom:
             offset = new Vector(0, -1 * this.ActualHeight);
             break;
     }
     foreach (var tick in this.AllTicks)
     {
         var p = TickHelper.ToPos(tick, this.Minimum, this.Maximum, line).Round(0);
         var l = new Line(p, p + offset);
         dc.DrawLine(pen, l);
     }
 }
Beispiel #10
0
        //画箭头
        protected Visual DrawArrow(System.Windows.Point startpoint, System.Windows.Point endpoint, System.Windows.Media.Brush brush, double thick)
        {
            var    matx = new Matrix();
            Vector vect = startPoint - endpoint;

            //获取单位向量
            vect.Normalize();
            vect *= 15;
            //旋转夹角的一半
            matx.Rotate(60 / 2);
            //计算上半段箭头的点
            System.Windows.Point point1 = endpoint + vect * matx;
            matx.Rotate(-60);
            //计算下半段箭头的点
            System.Windows.Point point2 = endpoint + vect * matx;
            DrawingVisual        visual = new DrawingVisual();

            System.Windows.Media.Pen pen = new System.Windows.Media.Pen(brush, thick);
            using (var dc = visual.RenderOpen())
            {
                dc.DrawLine(pen, startPoint, endpoint);
                dc.DrawLine(pen, endpoint, point1);
                dc.DrawLine(pen, endpoint, point2);
                pen.Freeze();  //冻结画笔,这样能加快绘图速度
            }

            this.AddVisual(visual);
            return(visual);
        }
        /// <summary>
        /// Creates a square image and attaches an event handler to the layout changed event that
        /// adds the the square in the upper right-hand corner of the TextView via the adornment layer
        /// </summary>
        /// <param name="view">The <see cref="IWpfTextView"/> upon which the adornment will be drawn</param>
        public TranslationAdornment(IWpfTextView view)
        {
            _view = view;

            Brush brush = new SolidColorBrush(Colors.BlueViolet);
            brush.Freeze();
            Brush penBrush = new SolidColorBrush(Colors.Red);
            penBrush.Freeze();
            Pen pen = new Pen(penBrush, 0.5);
            pen.Freeze();

            //draw a square with the created brush and pen
            System.Windows.Rect r = new System.Windows.Rect(0, 0, 30, 30);
            Geometry g = new RectangleGeometry(r);
            GeometryDrawing drawing = new GeometryDrawing(brush, pen, g);
            drawing.Freeze();

            DrawingImage drawingImage = new DrawingImage(drawing);
            drawingImage.Freeze();

            _image = new Image();
            _image.Source = drawingImage;

            //Grab a reference to the adornment layer that this adornment should be added to
            _adornmentLayer = view.GetAdornmentLayer("TranslationAdornment");

            _view.ViewportHeightChanged += delegate { this.onSizeChange(); };
            _view.ViewportWidthChanged += delegate { this.onSizeChange(); };
        }
Beispiel #12
0
        /// <summary>
        /// 从笔转化为系统笔;
        /// </summary>
        /// <param name="pen"></param>
        /// <returns></returns>
        public static SystemMedia.Pen ConverterToSystemPen(Pen pen)
        {
            if (pen == null)
            {
                throw new ArgumentNullException(nameof(pen));
            }

            if (_frozenPenDict.TryGetValue(pen, out var sysPen))
            {
                return(sysPen);
            }

            sysPen = new SystemMedia.Pen(BrushAdapter.ConvertToSystemBrush(pen.Brush), pen.Thickness);
            if (pen.DashStyle != null)
            {
                sysPen.DashStyle = DashStyleAdapter.ConvertToSystemDashStyle(pen.DashStyle);
            }

            if (pen.IsFrozen)
            {
                sysPen.Freeze();
                _frozenPenDict.Add(pen, sysPen);
            }

            return(sysPen);
        }
Beispiel #13
0
 public FloatExpElement()
 {
     pen3 = new Pen(ThemeManager.NoteFillBrushes[0], 3);
     pen2 = new Pen(ThemeManager.NoteFillBrushes[0], 2);
     pen3.Freeze();
     pen2.Freeze();
 }
Beispiel #14
0
 public static Pen CreateErrorPen(Color color)
 {
     var geometry = new StreamGeometry();
     using (var context = geometry.Open())
     {
         context.BeginFigure(new Point(-1, 0), false, false);
         context.PolyLineTo(new[] {
                 new Point(-0.5, 0.4),
                 new Point(0, 0),
                 new Point(0.5, -0.4),
                 new Point(1, 0),
             }, true, true);
     }
     var brushPattern = new GeometryDrawing
     {
         Pen = new Pen(new SolidColorBrush(color), 0.4),
         Geometry = geometry
     };
     var brush = new DrawingBrush(brushPattern)
     {
         TileMode = TileMode.Tile,
         Viewport = new Rect(-1, -1, 2, 2),
         ViewportUnits = BrushMappingMode.Absolute,
         Viewbox = new Rect(-1, -1, 2, 2),
         ViewboxUnits = BrushMappingMode.Absolute,
     };
     var pen = new Pen(brush, 3.0);
     pen.Freeze();
     return pen;
 }
        public PostInfoDisplay(double textRightEdge,
            double viewRightEdge,
            Geometry newTextGeometry,
            string body)
        {
            if (brush == null)
            {
                brush = new SolidColorBrush(Color.FromArgb(0x20, 0x48, 0x3d, 0x8b));
                brush.Freeze();
                Brush penBrush = new SolidColorBrush(Colors.DarkSlateBlue);
                penBrush.Freeze();
                solidPen = new Pen(penBrush, 0.5);
                solidPen.Freeze();
                dashPen = new Pen(penBrush, 0.5);
                dashPen.DashStyle = DashStyles.Dash;
                dashPen.Freeze();
            }

            this.textGeometry = newTextGeometry;

            TextBlock tb = new TextBlock();
            tb.Text = "Blog Entry: " + body;

            const int MarginWidth = 8;
            this.postGrid = new Grid();
            this.postGrid.RowDefinitions.Add(new RowDefinition());
            this.postGrid.RowDefinitions.Add(new RowDefinition());
            ColumnDefinition cEdge = new ColumnDefinition();
            cEdge.Width = new GridLength(MarginWidth);
            ColumnDefinition cEdge2 = new ColumnDefinition();
            cEdge2.Width = new GridLength(MarginWidth);
            this.postGrid.ColumnDefinitions.Add(cEdge);
            this.postGrid.ColumnDefinitions.Add(new ColumnDefinition());
            this.postGrid.ColumnDefinitions.Add(cEdge2);

            System.Windows.Shapes.Rectangle rect = new System.Windows.Shapes.Rectangle();
            rect.RadiusX = 6;
            rect.RadiusY = 3;
            rect.Fill = brush;
            rect.Stroke = Brushes.DarkSlateBlue;

            Size inf = new Size(double.PositiveInfinity, double.PositiveInfinity);
            tb.Measure(inf);
            this.postGrid.Width = tb.DesiredSize.Width + 2 * MarginWidth;

            Grid.SetColumn(rect, 0);
            Grid.SetRow(rect, 0);
            Grid.SetRowSpan(rect, 1);
            Grid.SetColumnSpan(rect, 3);
            Grid.SetRow(tb, 0);
            Grid.SetColumn(tb, 1);
            this.postGrid.Children.Add(rect);
            this.postGrid.Children.Add(tb);

            Canvas.SetLeft(this.postGrid, Math.Max(viewRightEdge - this.postGrid.Width - 20.0, textRightEdge + 20.0));
            Canvas.SetTop(this.postGrid, textGeometry.GetRenderBounds(solidPen).Top);

            this.Children.Add(this.postGrid);
        }
        protected override void OnRender(DrawingContext drawingContext)
        {
            var fe = AdornedElement as FrameworkElement;
            if (fe == null)
            {
                return;
            }

            var rect = new Rect(1, 1, Math.Max(0, fe.ActualWidth - 2), Math.Max(0, fe.ActualHeight - 2));
            var color = Colors.Red;
            var brush = new SolidColorBrush(color);
            var pen = new Pen(brush, 1);
            pen.Freeze();

            var dashPen = new Pen(brush, 1) { DashStyle = new DashStyle(new double[] { 1, 6 }, 0) };
            dashPen.Freeze();

            var guidelineSet = new GuidelineSet();
            guidelineSet.GuidelinesX.Add(0.5);
            guidelineSet.GuidelinesY.Add(0.5);

            //var outlinePen = new Pen(new SolidColorBrush(Color.FromArgb(0x70, 0xFF, 0xFF, 0xFF)), 5);
            //outlinePen.Freeze();

            drawingContext.PushGuidelineSet(guidelineSet);

            //drawingContext.DrawRectangle(null, outlinePen, rect);
            drawingContext.DrawRectangle(null, pen, rect);

            //var parent = VisualTreeHelper.GetParent(fe) as FrameworkElement;
            //if (parent != null)
            //{
            //    var thisLeft = new Point(0, fe.ActualHeight / 2);
            //    var thisRight = new Point(fe.ActualWidth, fe.ActualHeight / 2);
            //    var thisTop = new Point(fe.ActualWidth / 2, 0);
            //    var thisBottom = new Point(fe.ActualWidth / 2, fe.ActualHeight);
            //    var ancestorLeft = new Point(parent.TranslatePoint(thisLeft, fe).X, thisLeft.Y);
            //    var ancestorRight = ancestorLeft + new Vector(parent.ActualWidth, 0);
            //    var ancestorTop = new Point(thisTop.X, parent.TranslatePoint(new Point(), fe).Y);
            //    var ancestorBottom = new Point(thisBottom.X, parent.TranslatePoint(new Point(), fe).Y + parent.ActualHeight);

            //    var leftPen = fe.HorizontalAlignment == HorizontalAlignment.Left || fe.HorizontalAlignment == HorizontalAlignment.Stretch ? pen : dashPen;
            //    var rightPen = fe.HorizontalAlignment == HorizontalAlignment.Right || fe.HorizontalAlignment == HorizontalAlignment.Stretch ? pen : dashPen;
            //    var topPen = fe.VerticalAlignment == VerticalAlignment.Top || fe.VerticalAlignment == VerticalAlignment.Stretch ? pen : dashPen;
            //    var bottomPen = fe.VerticalAlignment == VerticalAlignment.Bottom || fe.VerticalAlignment == VerticalAlignment.Stretch ? pen : dashPen;

            //    drawingContext.DrawLine(leftPen, thisLeft, ancestorLeft);
            //    drawingContext.DrawLine(rightPen, thisRight, ancestorRight);
            //    drawingContext.DrawLine(topPen, thisTop, ancestorTop);
            //    drawingContext.DrawLine(bottomPen, thisBottom, ancestorBottom);
            //}

            var formattedHeight = new FormattedText(string.Format("{0:0}", fe.ActualHeight), CultureInfo.InvariantCulture, FlowDirection.LeftToRight, TypeFace, 10, brush);
            var formattedWidth = new FormattedText(string.Format("{0:0}", fe.ActualWidth), CultureInfo.InvariantCulture, FlowDirection.LeftToRight, TypeFace, 10, brush);
            drawingContext.DrawText(formattedHeight, new Point(rect.Width + 5, (rect.Height / 2) - (formattedHeight.Height / 2)));
            drawingContext.DrawText(formattedWidth, new Point(rect.Width / 2 - formattedWidth.Width / 2, rect.Height + 5));

            drawingContext.Pop();
        }
Beispiel #17
0
        /// <summary>
        /// Initializes static members of the <see cref="ZigzagMarker"/> class.
        /// </summary>
        static ZigzagMarker()
        {
            var brush = new SolidColorBrush(Colors.Red);
            brush.Freeze();

            DefaultPen = new Pen(brush, 0.75);
            DefaultPen.Freeze();
        }
 public static Pen GetDashPen(this FrameworkElement element, Brush brush, double thickness)
 {
     var pen = new Pen(brush, thickness) { DashStyle = new DashStyle() };
     pen.DashStyle.Dashes.Add(1);
     pen.DashStyle.Dashes.Add(3);
     pen.Freeze();
     return pen;
 }
 public PhonemesElement()
     : base()
 {
     penEnv = new Pen( ThemeManager.NoteFillBrushes[0] , 1);
     penEnv.Freeze();
     penEnvSel = new Pen(ThemeManager.NoteFillSelectedBrush, 1);
     penEnvSel.Freeze();
 }
Beispiel #20
0
        protected BlockBar()
        {
            _thePen = new Pen(this._rectBrush, 4);
            _thePen.Freeze();

            _rectBrush.Freeze();
            _disabledBrush.Freeze();
        }
        public void drawEraserPoint(Point p, int thickness, int time)
        {
            prepareDraw(time);

            Pen pen = new Pen(new SolidColorBrush(Colors.Red), thickness);
            pen.Freeze();
            staticTactics[time].map.drawEraser(p, pen);
        }
        public void UpdateColors(Color background, Color foreground)
        {
            _borderPen = new Pen(new SolidColorBrush(foreground), 1);
            _borderPen.Freeze();

            _backgroundBrush = new SolidColorBrush(background);
            _backgroundBrush.Freeze();
        }
Beispiel #23
0
 public static Pen CreateRainbowPen(DashStyle style = null)
 {
     var pen = new Pen();
     pen.Brush = new LinearGradientBrush(Colors.Yellow, Colors.Red, new Point(0, 0.5), new Point(1, 0.5));
     pen.Brush.Opacity = 0.5;
     pen.Thickness = 1.5;
     pen.DashStyle = (style != null ? style : DashStyles.Dash);
     pen.Freeze();
     return pen;
 }
    public DropTargetHighlightAdorner(UIElement adornedElement)
      : base(adornedElement)
    {
      _pen = new Pen(Brushes.Tomato, 2);
      _pen.Freeze();
      _brush = new SolidColorBrush(Colors.Coral) {Opacity = 0.2};
      this._brush.Freeze();

      this.SetValue(SnapsToDevicePixelsProperty, true);
    }
        public void drawLine(Point from, Point to, Color color, int thickness, DashStyle dash, int time)
        {
            prepareDraw(time);
            removeSamples();

            Pen pen = new Pen(new SolidColorBrush(color), thickness);
            pen.DashStyle = dash;
            pen.Freeze();
            staticTactics[time].map.drawLine(from, to, pen, color);
        }
Beispiel #26
0
 public WPFCanvasAdapter()
 {
     _pen = new Pen()
     {
         Brush = new SolidColorBrush(Colors.Black),
         Thickness = 1,
         StartLineCap = PenLineCap.Round,
         EndLineCap = PenLineCap.Round,
     };
     _pen.Freeze();
 }
Beispiel #27
0
        private void CreateDrawingObjects()
        {
            // this gets the color settings configured by the
             // user in Fonts and Colors (or the default in out
             // classification type).
             TextFormattingRunProperties format =
            formatMap.GetTextProperties(formatType);

             fillBrush = format.BackgroundBrush;
             Brush penBrush = format.ForegroundBrush;
             borderPen = new Pen(penBrush, 0.5);
             borderPen.Freeze();
             RedrawAdornments();
        }
Beispiel #28
0
        /// <summary>
        /// 直接根据视图位置,绘制WPF封闭区域;
        /// </summary>
        /// <param name="screenPoints"></param>
        /// <param name="brush"></param>
        /// <param name="pen"></param>
        private void NativeDrawFill(IEnumerable <Point> screenPoints, SystemMedia.Brush brush, SystemMedia.Pen pen)
        {
            if (screenPoints == null)
            {
                throw new ArgumentNullException(nameof(screenPoints));
            }
            if (pen == null)
            {
                throw new ArgumentNullException(nameof(pen));
            }

            ValidateDrawingContext();

            pen.Freeze();



            //操作SystemMedia.PathGeometry中的Figures以绘制(封闭)区域
            var paths = new SystemMedia.PathGeometry();

            var pfc = new SystemMedia.PathFigureCollection();
            var pf  = new SystemMedia.PathFigure();

            pfc.Add(pf);

            //存储一个点表示当前的PathFigure的StartPoint是否被指定;
            var startPointSet = false;

            foreach (var p in screenPoints)
            {
                //若StartPoint未被设定(第一个节点),设定后继续下一次循环;
                if (!startPointSet)
                {
                    pf.StartPoint = p;
                    startPointSet = true;
                    continue;
                }

                //若若StartPoint被设定,则加入线段;
                var ps = new SystemMedia.LineSegment();
                ps.Point = p;
                pf.Segments.Add(ps);
            }


            pf.IsClosed   = true;
            paths.Figures = pfc;
            DrawingContext.DrawGeometry(brush, pen, paths);
        }
        protected override void OnRender(DrawingContext dc)
        {
            var cellWidth = Height;

            {
                const double radius = 4;
                var cx = Height*0.5 + CommitGraphNode.NodeIndex*cellWidth;
                var cy = Height*0.5;

                dc.DrawEllipse(Brushes.MistyRose, EdgePen, new Point(cx, cy), radius, radius);
            }

            // 確認用
            {
                // http://www.wpftutorial.net/DrawOnPhysicalDevicePixels.html
                if (_gridPen == null)
                {
                    var presentationSource = PresentationSource.FromVisual(this);
                    if (presentationSource?.CompositionTarget != null)
                    {
                        var gridBrush = new SolidColorBrush(Color.FromArgb(0x30, 0x30, 0x30, 0x30));
                        gridBrush.Freeze();

                        var m = presentationSource.CompositionTarget.TransformToDevice;
                        _gridPen = new Pen(gridBrush, 1/m.M11); // 物理ピクセルで1
                        _gridPen.Freeze();
                    }

                    Debug.Assert(_gridPen != null);
                }

                const int lineCount = 20;
                var p0 = new Point(0, 0);
                var p1 = new Point(0, Height);

                using (new GuidelineSetBlock(
                    dc,
                    xGuides: Enumerable.Range(0, lineCount).Select(x => x*cellWidth + _gridPen.Thickness*0.5),
                    yGuides: new[] {0, Height}))
                {
                    for (var x = 0; x != lineCount; ++x)
                    {
                        p0.X = x*cellWidth;
                        p1.X = x*cellWidth;
                        dc.DrawLine(_gridPen, p0, p1);
                    }
                }
            }
        }
Beispiel #30
0
        static FormatMapWatcher()
        {
            Color highlight = SystemColors.HighlightColor;
            Color darkColor = Color.FromArgb(96, highlight.R, highlight.G, highlight.B);
            Color lightColor = Color.FromArgb(48, highlight.R, highlight.G, highlight.B);

            gradientBrush = new LinearGradientBrush(new GradientStopCollection() { new GradientStop(darkColor, 0.0),
                                                                                   new GradientStop(lightColor, 0.5),
                                                                                   new GradientStop(darkColor, 1.0) },
                                                    90.0);
            gradientBorder = new Pen(SystemColors.HighlightBrush, 1) { LineJoin = PenLineJoin.Round };

            gradientBrush.Freeze();
            gradientBorder.Freeze();
        }
        protected override void OnRender(DrawingContext dc)
        {
            var offX = 0;
            var offY = 0;
            var width = ActualWidth;
            var height = ActualHeight;

            var brush = BorderBackground;
            var pen = new Pen(brush, 1);
            pen.Freeze();
            var rect = new Rect(offX, offY, width, height);

            dc.DrawRoundedRectangle(brush, pen, rect, CornerRadius, CornerRadius);
            base.OnRender(dc);
        }
 protected override void OnRender(DrawingContext dc)
 {
     var pen = new Pen(this.Fill, this.PenWidth);
     pen.Freeze();
     var arc = Arc.Fill(this.RenderSize, this.MinAngle, this.MaxAngle, this.IsDirectionReversed);
     for (int i = 0; i < this.AllTicks.Count; i++)
     {
         var tick = this.AllTicks[i];
         var angle = TickHelper.ToAngle(tick, this.Minimum, this.Maximum, arc);
         var po = arc.GetPoint(angle, -this.ReservedSpace / 2);
         var pi = arc.GetPoint(angle, -this.ReservedSpace / 2 - this.TickLength);
         var line = new Line(po, pi);
         dc.DrawLine(pen, line);
     }
 }
Beispiel #33
0
 /// <summary>
 /// Create the pen and triangle in a static constructor and freeze them to improve performance.
 /// </summary>
 static InsertionAdorner()
 {
     Pen = new Pen { Brush = Brushes.SkyBlue, Thickness = LineThickness };
     Pen.Freeze();
     var firstLine = new LineSegment(new Point(0, -TriangleWidth), false);
     firstLine.Freeze();
     var secondLine = new LineSegment(new Point(0, TriangleWidth), false);
     secondLine.Freeze();
     var figure = new PathFigure {StartPoint = new Point(TriangleWidth, 0)};
     figure.Segments.Add(firstLine);
     figure.Segments.Add(secondLine);
     figure.Freeze();
     Triangle = new PathGeometry();
     Triangle.Figures.Add(figure);
     Triangle.Freeze();
 }
Beispiel #34
0
		internal DoorPicture()
		{
			_pen = new Pen(Brushes.Black, 2);
			_pen.Freeze();
			_geometry = new PathGeometry()
			{
				Figures = new PathFigureCollection()
				{
					new PathFigure()
					{
						IsClosed = true,
						IsFilled = true,
						Segments = new PathSegmentCollection()
						{
							new LineSegment(new Point(-40,0),true),
							new LineSegment(new Point(-40,100),true),
							new LineSegment(new Point(0,100),true),
						}
					}
				}
			};
			_geometry.Freeze();
			_geometryDrawing = new GeometryDrawing()
			{
				Brush = new SolidColorBrush(Colors.DarkOrange),
				Pen = _pen,
				Geometry = new PathGeometry()
				{
					Figures = new PathFigureCollection()
					{
						new PathFigure()
						{
							IsClosed = true,
							IsFilled = true,
							Segments = new PathSegmentCollection()
							{
								new LineSegment(new Point(20,40),true),
								new LineSegment(new Point(20,140),true),
								new LineSegment(new Point(0,100),true),
							}
						}
					}
				}
			};
			_geometryDrawing.Freeze();
			_brushes = new Dictionary<Brush, Brush>();
		}
Beispiel #35
0
      /// <summary/>
      protected override void OnInitialized(EventArgs e) {
         base.OnInitialized(e);

         // initialize colors
         var key = Namespace.Library.Name;
         if (!_brushes.ContainsKey(key)) key = String.Empty;
         _background = _brushes[key][0].ToBrush();
         _foreground = _brushes[key][1].ToBrush();
         _stroke = new Pen {
            Brush = _brushes[key][2].ToBrush(),
            Thickness = 2
         };
         _stroke.Freeze();

         // initialize texts
         _titleText = ToFormattedText(Namespace.Name, 24, _foreground);
      }
Beispiel #36
0
        public void Render()
        {
            try
            {
                double CanvasWidth  = (ActualWidth - 24) * Zoom;
                double CanvasHeight = Height - 14;

                CanvasPlot.Children.Clear();

                if (CanvasWidth <= 0 || CanvasHeight <= 0)
                {
                    return;
                }

                #region Determine axis range

                ValueMin = double.MaxValue;
                ValueMax = -double.MaxValue;

                if (!double.IsNaN(AxisMin))
                {
                    ValueMin = AxisMin;
                }
                else if (Points != null && Points.Count > 0)
                {
                    foreach (var point in Points)
                    {
                        if (!double.IsNaN(point.Value))
                        {
                            ValueMin = Math.Min(ValueMin, point.Value);
                        }
                    }
                }
                else
                {
                    ValueMin = 0;
                }

                if (!double.IsNaN(AxisMax))
                {
                    ValueMax = AxisMax;
                }
                else if (Points != null && Points.Count > 0 && Points.Any(v => !double.IsNaN(v.Value)))
                {
                    foreach (var point in Points)
                    {
                        if (!double.IsNaN(point.Value))
                        {
                            ValueMax = Math.Max(ValueMax, point.Value);
                        }
                    }
                }
                else
                {
                    ValueMax = 1;
                }

                double Range = ValueMax - ValueMin;

                if (ValueMin == ValueMax) // Range = 0, probably only one point
                {
                    ValueMax += 1;
                    ValueMin -= 1;
                }
                else // Make sure there are a few pixels left to draw the points at the extremes
                {
                    if (double.IsNaN(AxisMax))
                    {
                        ValueMax += Range / CanvasHeight * PointRadius;
                    }
                    if (double.IsNaN(AxisMin))
                    {
                        ValueMin -= Range / CanvasHeight * PointRadius;
                    }
                }

                Range = ValueMax - ValueMin;

                Dispatcher.Invoke(() =>
                {
                    string FloatFormat = "F0";
                    if (Math.Max(ValueMax, ValueMin) < 100)
                    {
                        FloatFormat = "F1";
                    }
                    if (Math.Max(ValueMax, ValueMin) < 10)
                    {
                        FloatFormat = "F2";
                    }

                    TextLineBottom.Text = ValueMin.ToString(FloatFormat, CultureInfo.InvariantCulture);
                    TextLineCenter.Text = ((ValueMin + ValueMax) * 0.5).ToString(FloatFormat, CultureInfo.InvariantCulture);
                    TextLineTop.Text    = ValueMax.ToString(FloatFormat, CultureInfo.InvariantCulture);
                });

                #endregion

                #region Adjust range highlight

                double RangeHighlightClampedMin = Math.Max(ValueMin, RangeHighlightMin);
                double RangeHighlightClampedMax = Math.Min(ValueMax, RangeHighlightMax);

                PanelRangeHighlight.Margin = new Thickness(0, 7 + (ValueMax - RangeHighlightClampedMax) / Range * CanvasHeight, 0, 0);
                PanelRangeHighlight.Height = Math.Max(0, RangeHighlightClampedMax - RangeHighlightClampedMin) / Range * CanvasHeight;

                #endregion

                if (Range < 0 || Points == null || Points.Count == 0)
                {
                    ImagePlot.Source = null;
                    return;
                }

                float[] HistogramBins = new float[50];

                DrawingGroup DGroup = new DrawingGroup();
                using (DrawingContext DContext = DGroup.Open())
                {
                    DContext.PushClip(new RectangleGeometry(new Rect(new Size(CanvasWidth, CanvasHeight))));

                    Pen OutlinePen = new Pen(Brushes.Transparent, 0);
                    OutlinePen.Freeze();

                    SolidColorBrush BackgroundBrush = new SolidColorBrush(Colors.Transparent);
                    BackgroundBrush.Freeze();
                    DContext.DrawRectangle(BackgroundBrush, OutlinePen, new Rect(new Size(CanvasWidth, CanvasHeight)));

                    SolidColorBrush[] ColorBrushes = PointColors.Count > 0
                                                         ? PointColors.Select(c =>
                    {
                        SolidColorBrush Brush = new SolidColorBrush(Color.FromArgb(255, c.R, c.G, c.B));
                        Brush.Freeze();
                        return(Brush);
                    }).ToArray()
                                                         : new[] { new SolidColorBrush(Color.FromArgb(150, Colors.DeepSkyBlue.R, Colors.DeepSkyBlue.G, Colors.DeepSkyBlue.B)) };

                    StepX   = (CanvasWidth - PointRadius * 2) / Points.Count;
                    OffsetX = StepX / 2 + PointRadius;
                    StepY   = CanvasHeight / Range;

                    PointCenters = new System.Windows.Point[Points.Count];

                    for (int i = 0; i < Points.Count; i++)
                    {
                        if (double.IsNaN(Points[i].Value))
                        {
                            continue;
                        }

                        double X = i * StepX + OffsetX;
                        double Y = (ValueMax - Points[i].Value) * StepY;

                        DContext.DrawEllipse(ColorBrushes[Points[i].ColorID], OutlinePen, new System.Windows.Point(X, Y), PointRadius, PointRadius);

                        PointCenters[i] = new System.Windows.Point(X, Y);

                        HistogramBins[Math.Max(0, Math.Min(HistogramBins.Length - 1, (int)((Points[i].Value - ValueMin) / Range * (HistogramBins.Length - 1) + 0.5)))]++;
                    }
                }

                DrawingImage Plot = new DrawingImage(DGroup);
                Plot.Freeze();
                Dispatcher.Invoke(() => ImagePlot.Source = Plot);

                Dispatcher.Invoke(() =>
                {
                    float[] HistogramConv = new float[HistogramBins.Length];
                    float[] ConvKernel    = { 0.11f, 0.37f, 0.78f, 1f, 0.78f, 0.37f, 0.11f };
                    for (int i = 0; i < HistogramBins.Length; i++)
                    {
                        float Sum     = 0;
                        float Samples = 0;
                        for (int j = 0; j < ConvKernel.Length; j++)
                        {
                            int ij = i - 3 + j;
                            if (ij < 0 || ij >= HistogramBins.Length)
                            {
                                continue;
                            }
                            Sum     += ConvKernel[j] * HistogramBins[ij];
                            Samples += ConvKernel[j];
                        }
                        HistogramConv[i] = Sum / Samples;
                    }

                    float HistogramMax = MathHelper.Max(HistogramConv);
                    if (HistogramMax > 0)
                    {
                        HistogramConv = HistogramConv.Select(v => v / HistogramMax * 16).ToArray();
                    }

                    Polygon HistogramPolygon = new Polygon()
                    {
                        Stroke  = Brushes.Transparent,
                        Fill    = Brushes.Gray,
                        Opacity = 0.15
                    };
                    PointCollection HistogramPoints = new PointCollection(HistogramConv.Length);

                    HistogramPoints.Add(new System.Windows.Point(16, 0));
                    HistogramPoints.Add(new System.Windows.Point(16, CanvasHeight));
                    for (int i = 0; i < HistogramConv.Length; i++)
                    {
                        double X = 15 - HistogramConv[i];
                        double Y = CanvasHeight - (i / (float)(HistogramConv.Length - 1) * CanvasHeight);
                        HistogramPoints.Add(new System.Windows.Point(X, Y));
                    }

                    HistogramPolygon.Points = HistogramPoints;

                    CanvasHistogram.Children.Clear();
                    CanvasHistogram.Children.Add(HistogramPolygon);
                    Canvas.SetRight(HistogramPolygon, 0);
                });
            }
            catch
            {
            }
        }
        public void Render()
        {
            try
            {
                double CanvasWidth  = ActualWidth;
                double CanvasHeight = ActualHeight;
                double FullRange    = AxisMax * 2;

                CanvasPlot.Children.Clear();

                if (double.IsNaN(AxisMax))
                {
                    return;
                }

                if (CanvasWidth <= 0 || CanvasHeight <= 0)
                {
                    return;
                }

                if (Points == null || Points.Count == 0)
                {
                    ImagePlot.Source = null;
                    return;
                }

                DrawingGroup DGroup = new DrawingGroup();
                using (DrawingContext DContext = DGroup.Open())
                {
                    DContext.PushClip(new RectangleGeometry(new Rect(new Size(CanvasWidth, CanvasHeight))));

                    Pen OutlinePen = new Pen(Brushes.Transparent, 0);
                    OutlinePen.Freeze();

                    SolidColorBrush BackgroundBrush = new SolidColorBrush(Colors.Transparent);
                    BackgroundBrush.Freeze();
                    DContext.DrawRectangle(BackgroundBrush, OutlinePen, new Rect(new Size(CanvasWidth, CanvasHeight)));

                    SolidColorBrush[] ColorBrushes = PointColors.Count > 0
                                                         ? PointColors.Select(c =>
                    {
                        SolidColorBrush Brush = new SolidColorBrush(Color.FromArgb(120, c.R, c.G, c.B));
                        Brush.Freeze();
                        return(Brush);
                    }).ToArray()
                                                         : new[] { new SolidColorBrush(Color.FromArgb(150, Colors.DeepSkyBlue.R, Colors.DeepSkyBlue.G, Colors.DeepSkyBlue.B)) };

                    PointCenters = new System.Windows.Point[Points.Count];

                    for (int i = 0; i < Points.Count; i++)
                    {
                        if (double.IsNaN(Points[i].X) || double.IsNaN(Points[i].Y))
                        {
                            continue;
                        }

                        //if (Math.Abs(Points[i].X) > AxisMax || Math.Abs(Points[i].Y) > AxisMax)
                        //    continue;

                        double X = Points[i].X / FullRange * CanvasWidth + CanvasWidth / 2;
                        double Y = Points[i].Y / FullRange * CanvasHeight + CanvasHeight / 2;

                        DContext.DrawEllipse(ColorBrushes[Points[i].ColorID], OutlinePen, new System.Windows.Point(X, Y), PointRadius, PointRadius);

                        PointCenters[i] = new System.Windows.Point(X, Y);
                    }
                }

                DrawingImage Plot = new DrawingImage(DGroup);
                Plot.Freeze();
                Dispatcher.Invoke(() => ImagePlot.Source = Plot);
            }
            catch
            {
            }
        }