Example #1
0
        public MdTextViewLineCollection(MonoTextEditor textEditor) : base(64)
        {
            this.textView = textEditor;
            this.version  = this.textView.Document.Version;

            int    startLine = textEditor.TextArea.YToLine(textEditor.VAdjustment.Value);
            double startY    = textEditor.TextArea.LineToY(startLine);
            double curY      = startY;
            double lastY     = textEditor.VAdjustment.Value + textEditor.Allocation.Height;

            for (int visualLineNumber = textEditor.GetTextEditorData().LogicalToVisualLine(startLine); ; visualLineNumber++)
            {
                int logicalLineNumber = textEditor.GetTextEditorData().VisualToLogicalLine(visualLineNumber);
                var line = textEditor.GetLine(logicalLineNumber);

                if (line == null)
                {
                    break;
                }

                Add(new MdTextViewLine(this, textEditor, line, textEditor.TextViewMargin.GetLayout(line)));

                curY += textEditor.TextArea.GetLineHeight(line);
                if (curY >= lastY)
                {
                    break;
                }
            }
        }
Example #2
0
        void IActionTextLineMarker.MouseHover(Mono.TextEditor.MonoTextEditor editor, MarginMouseEventArgs args, TextLineMarkerHoverResult result)
        {
            if (args.Button != 0)
            {
                return;
            }
            var line = editor.GetLine(loc.Line);

            if (line == null)
            {
                return;
            }
            var          x = editor.ColumnToX(line, loc.Column) - editor.HAdjustment.Value + editor.TextViewMargin.TextStartPosition;
            var          y = editor.LineToY(line.LineNumber + 1) - editor.VAdjustment.Value;
            const double xAdditionalSpace = tagMarkerWidth;

            if (args.X - x >= -xAdditionalSpace * editor.Options.Zoom &&
                args.X - x < (tagMarkerWidth + xAdditionalSpace) * editor.Options.Zoom /*&&
                                                                                        * args.Y - y < (editor.LineHeight / 2) * editor.Options.Zoom*/)
            {
                result.Cursor = null;
                ShowPopup?.Invoke(null, null);
            }
            else
            {
                CancelPopup?.Invoke(null, null);
            }
        }
Example #3
0
        void UpdateMarkers()
        {
            focusMarkers = new List <TextLineMarker> ();

            for (int lineNumber = 0; lineNumber <= editor.Document.LineCount; lineNumber++)
            {
                foreach (var marker in editor.Document.GetMarkersOrderedByInsertion(editor.GetLine(lineNumber)))
                {
                    focusMarkers.Add(marker);
                }
            }
        }
		public override void Draw (Mono.TextEditor.MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, int startOffset, int endOffset)
		{
			this.editor = editor;
			var line = editor.GetLine (loc.Line);
			if (line == null)
				return;
			var x = editor.ColumnToX (line, loc.Column) - editor.HAdjustment.Value + editor.TextViewMargin.XOffset + editor.TextViewMargin.TextStartPosition;

			cr.Rectangle (Math.Floor (x), Math.Floor (metrics.LineYRenderStartPosition) + (line == editor.GetLineByOffset (startOffset) ? editor.LineHeight - tagMarkerHeight : 0), tagMarkerWidth, tagMarkerHeight);
			cr.SetSourceColor ((HslColor.Brightness (editor.ColorStyle.PlainText.Background) < 0.5 ? Ide.Gui.Styles.Editor.SmartTagMarkerColorDark : Ide.Gui.Styles.Editor.SmartTagMarkerColorLight).ToCairoColor ());
			cr.Fill ();
		}
Example #5
0
        bool ISmartTagMarker.IsInsideSmartTag(double x, double y)
        {
            if (editor == null)
            {
                return(false);
            }
            var lin2 = editor.GetLine(loc.Line);
            var x2   = editor.ColumnToX(lin2, loc.Column) - editor.HAdjustment.Value + editor.TextViewMargin.TextStartPosition;
            var y2   = editor.LineToY(loc.Line + 1) - editor.VAdjustment.Value;

            return(x - x2 >= 0 * editor.Options.Zoom &&
                   x - x2 < tagMarkerWidth * editor.Options.Zoom &&
                   y - y2 < (editor.LineHeight / 2) * editor.Options.Zoom);
        }
Example #6
0
        public override void Draw(Mono.TextEditor.MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, int startOffset, int endOffset)
        {
            this.editor = editor;
            var line = editor.GetLine(loc.Line);

            if (line == null)
            {
                return;
            }
            var x = editor.ColumnToX(line, loc.Column) - editor.HAdjustment.Value + editor.TextViewMargin.XOffset + editor.TextViewMargin.TextStartPosition;

            cr.Rectangle(Math.Floor(x), Math.Floor(metrics.LineYRenderStartPosition) + editor.LineHeight - tagMarkerHeight, tagMarkerWidth, tagMarkerHeight);
            cr.SetSourceColor((HslColor.Brightness(SyntaxHighlightingService.GetColor(editor.EditorTheme, EditorThemeColors.Background)) < 0.5 ? Ide.Gui.Styles.Editor.SmartTagMarkerColorDark : Ide.Gui.Styles.Editor.SmartTagMarkerColorLight).ToCairoColor());
            cr.Fill();
        }
		public override void Draw (Mono.TextEditor.MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, int startOffset, int endOffset)
		{
			this.editor = editor;
			var line = editor.GetLine (loc.Line);
			if (line == null)
				return;
			var x = editor.ColumnToX (line, loc.Column) - editor.HAdjustment.Value + editor.TextViewMargin.XOffset + editor.TextViewMargin.TextStartPosition;

			cr.Rectangle (Math.Floor (x) + 0.5, Math.Floor (metrics.LineYRenderStartPosition) + 0.5 + (line == editor.GetLineByOffset (startOffset) ? editor.LineHeight - tagMarkerHeight - 1 : 0), tagMarkerWidth * cr.LineWidth, tagMarkerHeight * cr.LineWidth);

			if (HslColor.Brightness (editor.ColorStyle.PlainText.Background) < 0.5) {
				cr.SetSourceRGBA (0.8, 0.8, 1, 0.9);
			} else {
				cr.SetSourceRGBA (0.2, 0.2, 1, 0.9);
			}
			cr.Stroke ();
		}
        public override void Update(MonoTextEditor editor)
        {
            var startLine = editor.GetLine(start);

            if (start == end)
            {
                editor.TextViewMargin.RemoveCachedLine(startLine);
                editor.RedrawLine(start);
            }
            else
            {
                for (int i = 0; startLine != null && i < end - start; i++)
                {
                    editor.TextViewMargin.RemoveCachedLine(startLine);
                    startLine = startLine.NextLine;
                }
                editor.RedrawLines(start, end);
            }
        }
Example #9
0
        public override void Draw(Mono.TextEditor.MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, int startOffset, int endOffset)
        {
            this.editor = editor;
            var line = editor.GetLine(loc.Line);

            if (line == null)
            {
                return;
            }
            var x = editor.ColumnToX(line, loc.Column) - editor.HAdjustment.Value + editor.TextViewMargin.XOffset + editor.TextViewMargin.TextStartPosition;

            cr.Rectangle(Math.Floor(x) + 0.5, Math.Floor(metrics.LineYRenderStartPosition) + 0.5 + (line == editor.GetLineByOffset(startOffset) ? editor.LineHeight - tagMarkerHeight - 1 : 0), tagMarkerWidth * cr.LineWidth, tagMarkerHeight * cr.LineWidth);

            if (HslColor.Brightness(editor.ColorStyle.PlainText.Background) < 0.5)
            {
                cr.SetSourceRGBA(0.8, 0.8, 1, 0.9);
            }
            else
            {
                cr.SetSourceRGBA(0.2, 0.2, 1, 0.9);
            }
            cr.Stroke();
        }
Example #10
0
        public void Draw(Cairo.Context cr, Cairo.Rectangle area)
        {
            TextViewMargin textViewMargin = editor.TextViewMargin;
            ISyntaxMode    mode           = Document.SyntaxMode != null && editor.Options.EnableSyntaxHighlighting ? Document.SyntaxMode : new SyntaxMode(Document);

            TextViewMargin.LayoutWrapper lineLayout = null;
            double brightness = HslColor.Brightness(editor.ColorStyle.PlainText.Background);

            int colorCount = foldSegments.Count + 2;

            cr.SetSourceColor(GetColor(-1, brightness, colorCount));
            cr.Rectangle(area);
            cr.Fill();
            var       rectangles         = new Cairo.Rectangle[foldSegments.Count];
            const int xPadding           = 4;
            const int yPadding           = 2;
            const int rightMarginPadding = 16;

            for (int i = foldSegments.Count - 1; i >= 0; i--)
            {
                var segment = foldSegments [i];
                if (segment.IsInvalid)
                {
                    continue;
                }
                var segmentStartLine = segment.StartLine;
                var segmentEndLine   = segment.EndLine;

                int curWidth = 0;
                var endLine  = segmentEndLine.NextLine;
                var y        = editor.LineToY(segmentStartLine.LineNumber);
                if (y < editor.VAdjustment.Value)
                {
                    segmentStartLine = editor.GetLine(editor.YToLine(editor.VAdjustment.Value));
                    y = editor.LineToY(segmentStartLine.LineNumber);
                }

                for (var curLine = segmentStartLine; curLine != endLine && y < editor.VAdjustment.Value + editor.Allocation.Height; curLine = curLine.NextLine)
                {
                    var curLayout = textViewMargin.CreateLinePartLayout(mode, curLine, curLine.Offset, curLine.Length, -1, -1);
                    var width     = (int)(curLayout.Width);
                    curWidth = System.Math.Max(curWidth, width);
                    y       += editor.GetLineHeight(curLine);
                }

                double xPos = textViewMargin.XOffset;
                double rectangleWidth = 0, rectangleHeight = 0;

                lineLayout = textViewMargin.CreateLinePartLayout(mode, segmentStartLine, segmentStartLine.Offset, segmentStartLine.Length, -1, -1);
                var rectangleStart = lineLayout.Layout.IndexToPos(GetFirstNonWsIdx(lineLayout.Layout.Text));
                xPos = System.Math.Max(textViewMargin.XOffset, (textViewMargin.XOffset + textViewMargin.TextStartPosition + rectangleStart.X / Pango.Scale.PangoScale) - xPadding);

                lineLayout = textViewMargin.CreateLinePartLayout(mode, segmentEndLine, segmentEndLine.Offset, segmentEndLine.Length, -1, -1);

                var rectangleEnd = lineLayout.Layout.IndexToPos(GetFirstNonWsIdx(lineLayout.Layout.Text));
                xPos = System.Math.Min(xPos, System.Math.Max(textViewMargin.XOffset, (textViewMargin.XOffset + textViewMargin.TextStartPosition + rectangleEnd.X / Pango.Scale.PangoScale) - xPadding));

                rectangleWidth = textViewMargin.XOffset + textViewMargin.TextStartPosition + curWidth - xPos + xPadding * 2;

                if (i < foldSegments.Count - 1)
                {
                    rectangleWidth = System.Math.Max((rectangles [i + 1].X + rectangles[i + 1].Width + rightMarginPadding) - xPos, rectangleWidth);
                }

                y = editor.LineToY(segment.StartLine.LineNumber);
                var yEnd = editor.LineToY(segment.EndLine.LineNumber + 1) + (segment.EndLine.LineNumber == editor.LineCount ? editor.LineHeight : 0);
                if (yEnd == 0)
                {
                    yEnd = editor.VAdjustment.Upper;
                }
                rectangleHeight = yEnd - y;

                rectangles[i] = new Cairo.Rectangle(xPos, y - yPadding, rectangleWidth, rectangleHeight + yPadding * 2);
            }

            for (int i = 0; i < foldSegments.Count; i++)
            {
                Cairo.Rectangle clampedRect;
                var             rect = rectangles[i];

                if (i == foldSegments.Count - 1)
                {
/*					var radius = (int)(editor.Options.Zoom * 2);
 *                                      int w = 2 * radius;
 *                                      using (var shadow = new Blur (
 *                                              System.Math.Min ((int)rect.Width + w * 2, editor.Allocation.Width),
 *                                              System.Math.Min ((int)rect.Height + w * 2, editor.Allocation.Height),
 *                                              radius)) {
 *                                              using (var gctx = shadow.GetContext ()) {
 *                                                      gctx.Color = new Cairo.Color (0, 0, 0, 0);
 *                                                      gctx.Fill ();
 *
 *                                                      var a = 0;
 *                                                      var b = 0;
 *                                                      DrawRoundRectangle (gctx, true, true, w - a, w - b, editor.LineHeight / 4, rect.Width + a * 2, rect.Height + a * 2);
 *                                                      var bg = editor.ColorStyle.Default.CairoColor;
 *                                                      gctx.Color = new Cairo.Color (bg.R, bg.G, bg.B, 0.6);
 *                                                      gctx.Fill ();
 *                                              }
 *
 *                                              cr.Save ();
 *                                              cr.Translate (rect.X - w - editor.HAdjustment.Value, rect.Y - editor.VAdjustment.Value - w);
 *                                              shadow.Draw (cr);
 *                                              cr.Restore ();
 *                                      }*/

                    var curPadSize = 1;

                    var age   = (DateTime.Now - startTime).TotalMilliseconds;
                    var alpha = 0.1;
                    if (age < animationLength)
                    {
                        var animationState = age / (double)animationLength;
                        curPadSize = (int)(3 + System.Math.Sin(System.Math.PI * animationState) * 3);
                        alpha      = 0.1 + (1.0 - animationState) / 5;
                    }

                    var bg = editor.ColorStyle.PlainText.Foreground;
                    cr.SetSourceRGBA(bg.R, bg.G, bg.B, alpha);
                    clampedRect = ClampRect(rect.X - editor.HAdjustment.Value - curPadSize, rect.Y - editor.VAdjustment.Value - curPadSize, editor.LineHeight / 2, rect.Width + curPadSize * 2, rect.Height + curPadSize * 2, area);
                    DrawRoundRectangle(cr, true, true, clampedRect.X, clampedRect.Y, editor.LineHeight / 2, clampedRect.Width, clampedRect.Height);
                    cr.Fill();

                    if (age < animationLength)
                    {
                        var animationState = age / (double)animationLength;
                        curPadSize  = (int)(2 + System.Math.Sin(System.Math.PI * animationState) * 2);
                        clampedRect = ClampRect(rect.X - editor.HAdjustment.Value - curPadSize, rect.Y - editor.VAdjustment.Value - curPadSize, editor.LineHeight / 2, rect.Width + curPadSize * 2, rect.Height + curPadSize * 2, area);
                        DrawRoundRectangle(cr, true, true, clampedRect.X, clampedRect.Y, editor.LineHeight / 2, clampedRect.Width, clampedRect.Height);
                        cr.SetSourceColor(GetColor(i, brightness, colorCount));
                        cr.Fill();

                        continue;
                    }
                }

                clampedRect = ClampRect(rect.X - editor.HAdjustment.Value, rect.Y - editor.VAdjustment.Value, editor.LineHeight / 2, rect.Width, rect.Height, area);
                DrawRoundRectangle(cr, true, true, clampedRect.X, clampedRect.Y, editor.LineHeight / 2, clampedRect.Width, clampedRect.Height);

                cr.SetSourceColor(GetColor(i, brightness, colorCount));
                cr.Fill();
            }
        }