public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (_textEditor.SelectionLength == 0 && _textEditor.CaretOffset != -1 &&
                _textEditor.CaretOffset <= textView.Document.TextLength)
            {
                var currentLine = textView.Document.GetLocation(_textEditor.CaretOffset).Line;

                var visualLine = textView.GetVisualLine(currentLine);
                if (visualLine == null)
                {
                    return;
                }

                BackgroundGeometryBuilder builder = new BackgroundGeometryBuilder();

                var linePosY   = visualLine.VisualTop - textView.ScrollOffset.Y;
                var lineBottom = linePosY + visualLine.Height;

                Size pixelSize = PixelSnapHelpers.GetPixelSize(textView);


                double x  = PixelSnapHelpers.PixelAlign(0, pixelSize.Width);
                double y  = PixelSnapHelpers.PixelAlign(linePosY, pixelSize.Height);
                var    x2 = PixelSnapHelpers.PixelAlign(textView.Bounds.Width, pixelSize.Width);
                var    y2 = PixelSnapHelpers.PixelAlign(lineBottom, pixelSize.Height);

                builder.AddRectangle(textView, new Rect(new Point(x, y), new Point(x2, y2)));

                Geometry geometry = builder.CreateGeometry();
                if (geometry != null)
                {
                    drawingContext.DrawGeometry(BackgroundBrush, BorderPen, geometry);
                }
            }
        }
Exemplo n.º 2
0
            public void Draw(TextView textView, DrawingContext drawingContext)
            {
                if (textView.Document == null)
                {
                    return;
                }

                textView.EnsureVisualLines();

                Color backColor;

                foreach (var visLine in textView.VisualLines)
                {
                    backColor = default(Color);
                    switch (GetDiffType(visLine.FirstDocumentLine.LineNumber))
                    {
                    case DiffType.Add:
                        backColor = this.AddColor;
                        break;

                    case DiffType.Change:
                        backColor = Color.FromRgb(0xcc, 0xcc, 0xff);
                        break;
                    }

                    if (backColor != default(Color))
                    {
                        var backgroundGeometryBuilder = new BackgroundGeometryBuilder();
                        var y = visLine.VisualTop - textView.ScrollOffset.Y;
                        backgroundGeometryBuilder.AddRectangle(textView, new Rect(0.0, y, textView.ActualWidth, visLine.Height));
                        var geometry = backgroundGeometryBuilder.CreateGeometry();
                        if (geometry != null)
                        {
                            drawingContext.DrawGeometry(new SolidColorBrush(backColor), null, geometry);
                        }
                    }
                }
            }
Exemplo n.º 3
0
            public void Draw(TextView textView, DrawingContext drawingContext)
            {
                if (textView.Document == null)
                {
                    return;
                }

                textView.EnsureVisualLines();

                var            firstLine     = textView.VisualLines.First().FirstDocumentLine.LineNumber;
                int            nextBlockLine = int.MaxValue;
                int            blockIndex;
                Color          backColor;
                MergeAlternate alt;
                MergeLocation  colorLocation;

                for (blockIndex = 1; blockIndex < _view._starts.Count; blockIndex++)
                {
                    if (_view._starts[blockIndex].LineNumber > firstLine)
                    {
                        nextBlockLine = _view._starts[blockIndex].LineNumber;
                        blockIndex--;
                        break;
                    }
                }
                if (blockIndex >= _view._starts.Count)
                {
                    blockIndex = _view._starts.Count - 1;
                }

                foreach (var visLine in textView.VisualLines)
                {
                    if (visLine.FirstDocumentLine.LineNumber >= nextBlockLine)
                    {
                        blockIndex++;
                        nextBlockLine = (blockIndex < (_view._starts.Count - 1) ? _view._starts[blockIndex + 1].LineNumber : int.MaxValue);
                    }

                    alt = _view._starts[blockIndex].Alternate;
                    if (_view._starts[blockIndex].Alternate.Parent.Alternates.Count > 1 &&
                        (_view.Location == MergeLocation.Output ||
                         _view.Location == MergeLocation.Parent ||
                         (alt.Location & MergeLocation.Parent) == 0))
                    {
                        colorLocation = alt.Location & ~MergeLocation.Output;
                        if (_view.Location == MergeLocation.Output)
                        {
                            if ((colorLocation & MergeLocation.Right) != 0)
                            {
                                backColor = GetColor(MergeLocation.Right);
                            }
                            else if ((colorLocation & MergeLocation.Parent) != 0)
                            {
                                backColor = GetColor(MergeLocation.Parent);
                            }
                            else
                            {
                                backColor = GetColor(MergeLocation.Left);
                            }
                        }
                        else
                        {
                            backColor = GetColor(_view.Location);
                            if (colorLocation == (MergeLocation.Left | MergeLocation.Right))
                            {
                                backColor = GetColor(MergeLocation.Right);
                            }
                        }

                        var backgroundGeometryBuilder = new BackgroundGeometryBuilder();
                        var y = visLine.VisualTop - textView.ScrollOffset.Y;
                        backgroundGeometryBuilder.AddRectangle(textView, new Rect(0.0, y, textView.ActualWidth, visLine.Height));
                        var geometry = backgroundGeometryBuilder.CreateGeometry();
                        if (geometry != null)
                        {
                            drawingContext.DrawGeometry(new SolidColorBrush(backColor), null, geometry);
                        }
                    }
                }
            }