示例#1
0
        internal void CreateAndSetPainter(string category, ref ISelectionPainter painter, SKColor defaultColor)
        {
            if (painter != null)
            {
                painter.Dispose();
            }

            painter = BrushSelectionPainter.CreatePainter(this, _selectionAdornmentLayer, _editorFormatMap.GetProperties(category), defaultColor);
        }
示例#2
0
        private void DrawSelectionOnLines(IList <ITextViewLine> lines, SnapshotSpan streamSelection)
        {
            bool isVirtualSpaceEnabled = base._textSelection.TextView.Options.IsVirtualSpaceEnabled();
            bool boxSelection          = base._textSelection.Mode == TextSelectionMode.Box;

            double viewportLeft  = base._textSelection.TextView.ViewportLeft;
            double viewportRight = base._textSelection.TextView.ViewportRight;

            double leftClip  = viewportLeft - BrushSelectionPainter.ClipPadding;
            double rightClip = viewportRight + BrushSelectionPainter.ClipPadding;

            SnapshotPoint end = base._textSelection.End.Position;

            //Go through each of the text view lines and see whether the selection on that line has changed. If it hasn't, don't do anything to the adornment for that line.
            foreach (var line in lines)
            {
                SelectionData oldData;
                bool          hadOldSpan = _lineSpans.TryGetValue(line.IdentityTag, out oldData);

                double lineTop;
                double lineBottom;
                BrushSelectionPainter.LineTopAndBottom(line, streamSelection, out lineTop, out lineBottom);

                VirtualSnapshotSpan?newSpan = base._textSelection.GetSelectionOnTextViewLine(line);

                if (hadOldSpan)
                {
                    if (newSpan.HasValue && !oldData.ShouldRedraw(newSpan.Value, viewportLeft, viewportRight, lineTop == line.Top, lineBottom == line.Bottom))
                    {
                        //The span on this line has not changed ... do nothing for this line
                        continue;
                    }

                    //Either there is no new span or the old and new spans disagreed. Remove the data
                    //and adorment for the old span.
                    base._adornmentLayer.RemoveAdornmentsByTag(line.IdentityTag);
                }

                if (newSpan.HasValue)
                {
                    var bounds = BrushSelectionPainter.CalculateVisualOverlapsForLine(line, newSpan.Value, end, boxSelection, isVirtualSpaceEnabled);
                    if (bounds.Count > 0)
                    {
                        double leftEdgeOfAdornment  = bounds [0].Item1;
                        double rightEdgeOfAdornment = bounds [bounds.Count - 1].Item2;

                        //Only bother to compute the geometries is there is some overlap between the adornment and the rendering region.
                        if ((leftEdgeOfAdornment < rightClip) && (rightEdgeOfAdornment > leftClip))
                        {
                            var path = new SKPath();
                            //path.FillRule = FillRule.Nonzero;
                            foreach (var bound in bounds)
                            {
                                BrushSelectionPainter.AddRectangleToPath(bound.Item1, lineTop, bound.Item2, lineBottom, leftClip, rightClip, path);
                            }

                            if (!path.IsEmpty)
                            {
                                //TODO:
                                var adornment = new SelectionAdornment(null, this.Brush, path);

                                _lineSpans.Add(line.IdentityTag, new SelectionData(newSpan.Value, leftEdgeOfAdornment, rightEdgeOfAdornment, leftClip, rightClip, lineTop == line.Top, lineBottom == line.Bottom));
                                _adornmentLayer.AddAdornment(AdornmentPositioningBehavior.TextRelative, line.Extent, line.IdentityTag, adornment, RemovedCallback);
                            }
                        }
                    }
                }
            }
        }