public override bool DrawBackground (TextEditor editor, Cairo.Context cr, double y, LineMetrics metrics)
		{
			// check, if a message bubble is active in that line.
			if (LineSegment != null && LineSegment.Markers.Any (m => m != this && (m is IExtendingTextLineMarker)))
				return false;

			return base.DrawBackground (editor, cr, y, metrics);
		}
		public override void DrawBackground (Mono.TextEditor.MonoTextEditor editor, Context cr, LineMetrics metrics, int startOffset, int endOffset)
		{
			int markerStart = usage.Offset;
			int markerEnd = usage.EndOffset;

			if (markerEnd < startOffset || markerStart > endOffset) 
				return; 

			double @from;
			double to;
			var startXPos = metrics.TextRenderStartPosition;
			var endXPos = metrics.TextRenderEndPosition;
			var y = metrics.LineYRenderStartPosition;
			if (markerStart < startOffset && endOffset < markerEnd) {
				@from = startXPos;
				to = endXPos;
			} else {
				int start = startOffset < markerStart ? markerStart : startOffset;
				int end = endOffset < markerEnd ? endOffset : markerEnd;

				uint curIndex = 0, byteIndex = 0;
				TextViewMargin.TranslateToUTF8Index (metrics.Layout.LineChars, (uint)(start - startOffset), ref curIndex, ref byteIndex);

				int x_pos = metrics.Layout.Layout.IndexToPos ((int)byteIndex).X;

				@from = startXPos + (int)(x_pos / Pango.Scale.PangoScale);

				TextViewMargin.TranslateToUTF8Index (metrics.Layout.LineChars, (uint)(end - startOffset), ref curIndex, ref byteIndex);
				x_pos = metrics.Layout.Layout.IndexToPos ((int)byteIndex).X;

				to = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
			}

			@from = Math.Max (@from, editor.TextViewMargin.XOffset);
			to = Math.Max (to, editor.TextViewMargin.XOffset);
			if (@from < to) {
				Mono.TextEditor.Highlighting.AmbientColor colorStyle;
				if ((usage.UsageType & ReferenceUsageType.Write) == ReferenceUsageType.Write ||
					(usage.UsageType & ReferenceUsageType.Declariton) == ReferenceUsageType.Declariton) {
					colorStyle = editor.ColorStyle.ChangingUsagesRectangle;
					if (colorStyle.Color.A == 0.0)
						colorStyle = editor.ColorStyle.UsagesRectangle;
				} else {
					colorStyle = editor.ColorStyle.UsagesRectangle;
				}

				using (var lg = new LinearGradient (@from + 1, y + 1.5, to , y + editor.LineHeight - 1)) {
					lg.AddColorStop (0, colorStyle.Color);
					lg.AddColorStop (1, colorStyle.SecondColor);
					cr.SetSource (lg);
					cr.RoundedRectangle (@from - 0.5, y + 0.5, to - @from + 1, editor.LineHeight - 1, 2);
					cr.FillPreserve ();
				}

				cr.SetSourceColor (colorStyle.BorderColor);
				cr.Stroke ();
			}
		}
		public override bool DrawBackground (TextEditor editor, Cairo.Context cr, double y, LineMetrics metrics)
		{
			if (metrics.SelectionStart > 0)
				return true;
			cr.Color = color;
			cr.Rectangle (metrics.TextRenderStartPosition, y, metrics.TextRenderEndPosition - metrics.TextRenderStartPosition, editor.LineHeight);
			cr.Fill ();
			return true;
		}
		public override bool DrawBackground (MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics)
		{
			if (metrics.SelectionStart > 0)
				return true;
			cr.SetSourceColor (color);
			cr.Rectangle (metrics.TextRenderStartPosition, metrics.LineYRenderStartPosition, metrics.TextRenderEndPosition - metrics.TextRenderStartPosition, editor.LineHeight);
			cr.Fill ();
			return true;
		}
Example #5
0
 public override bool DrawBackground(MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics)
 {
     if (metrics.SelectionStart > 0)
     {
         return(true);
     }
     cr.SetSourceColor(color);
     cr.Rectangle(metrics.TextRenderStartPosition, metrics.LineYRenderStartPosition, metrics.TextRenderEndPosition - metrics.TextRenderStartPosition, editor.LineHeight);
     cr.Fill();
     return(true);
 }
		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 ();
		}
        public override bool DrawBackground(TextEditor editor, Context cr, double y, LineMetrics metrics)
        {
            int caretOffset = editor.Caret.Offset - BaseOffset;

            foreach (var link in mode.Links)
            {
                if (!link.IsEditable)
                {
                    continue;
                }
                bool isPrimaryHighlighted = link.PrimaryLink.Offset <= caretOffset && caretOffset <= link.PrimaryLink.EndOffset;
                foreach (TextSegment segment in link.Links)
                {
                    if ((BaseOffset + segment.Offset <= metrics.TextStartOffset && metrics.TextStartOffset < BaseOffset + segment.EndOffset) || (metrics.TextStartOffset <= BaseOffset + segment.Offset && BaseOffset + segment.Offset < metrics.TextEndOffset))
                    {
                        int strOffset    = BaseOffset + segment.Offset - metrics.TextStartOffset;
                        int strEndOffset = BaseOffset + segment.EndOffset - metrics.TextStartOffset;

                        var x_pos  = metrics.Layout.Layout.GetCoordinateFromIndex(strOffset).X;                         //.IndexToPos (strOffset).X;
                        var x_pos2 = metrics.Layout.Layout.GetCoordinateFromIndex(strEndOffset).X;

                        //x_pos = (int)(x_pos / Pango.Scale.PangoScale);
                        //x_pos2 = (int)(x_pos2 / Pango.Scale.PangoScale);
                        Color fillGc, rectangleGc;
                        if (segment == link.PrimaryLink)
                        {
                            fillGc      = isPrimaryHighlighted ? editor.ColorStyle.PrimaryTemplateHighlighted.SecondColor : editor.ColorStyle.PrimaryTemplate.SecondColor;
                            rectangleGc = isPrimaryHighlighted ? editor.ColorStyle.PrimaryTemplateHighlighted.SecondColor : editor.ColorStyle.PrimaryTemplate.SecondColor;
                        }
                        else
                        {
                            fillGc      = isPrimaryHighlighted ? editor.ColorStyle.SecondaryTemplateHighlighted.SecondColor : editor.ColorStyle.SecondaryTemplate.SecondColor;
                            rectangleGc = isPrimaryHighlighted ? editor.ColorStyle.SecondaryTemplateHighlighted.Color : editor.ColorStyle.SecondaryTemplate.Color;
                        }

                        // Draw segment
                        double x1 = metrics.TextRenderStartPosition + x_pos - 1;
                        double x2 = metrics.TextRenderStartPosition + x_pos2 - 1 + 0.5;

                        cr.Rectangle(x1 + 0.5, y + 0.5, x2 - x1, editor.LineHeight - 1);

                        cr.SetColor(fillGc);
                        cr.FillPreserve();

                        cr.SetColor(rectangleGc);
                        cr.Stroke();
                    }
                }
            }
            return(true);
        }
Example #8
0
        public override bool DrawBackground(MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics)
        {
            int caretOffset = editor.Caret.Offset - BaseOffset;

            foreach (var link in mode.Links)
            {
                if (!link.IsEditable)
                {
                    continue;
                }
                bool isPrimaryHighlighted = link.PrimaryLink.Offset <= caretOffset && caretOffset <= link.PrimaryLink.EndOffset;
                foreach (TextSegment segment in link.Links)
                {
                    if ((BaseOffset + segment.Offset <= metrics.TextStartOffset && metrics.TextStartOffset < BaseOffset + segment.EndOffset) || (metrics.TextStartOffset <= BaseOffset + segment.Offset && BaseOffset + segment.Offset < metrics.TextEndOffset))
                    {
                        int strOffset    = BaseOffset + segment.Offset - metrics.TextStartOffset;
                        int strEndOffset = BaseOffset + segment.EndOffset - metrics.TextStartOffset;

                        int x_pos  = metrics.Layout.IndexToPos(strOffset).X;
                        int x_pos2 = metrics.Layout.IndexToPos(strEndOffset).X;

                        x_pos  = (int)(x_pos / Pango.Scale.PangoScale);
                        x_pos2 = (int)(x_pos2 / Pango.Scale.PangoScale);
                        Cairo.Color fillGc, rectangleGc;
                        if (segment.Equals(link.PrimaryLink))
                        {
                            fillGc      = SyntaxHighlightingService.GetColor(editor.EditorTheme, isPrimaryHighlighted ? EditorThemeColors.PrimaryTemplateHighlighted2 : EditorThemeColors.PrimaryTemplate2);
                            rectangleGc = SyntaxHighlightingService.GetColor(editor.EditorTheme, isPrimaryHighlighted ? EditorThemeColors.PrimaryTemplateHighlighted2 : EditorThemeColors.PrimaryTemplate2);
                        }
                        else
                        {
                            fillGc      = SyntaxHighlightingService.GetColor(editor.EditorTheme, isPrimaryHighlighted ? EditorThemeColors.SecondaryTemplateHighlighted2 : EditorThemeColors.SecondaryTemplate2);
                            rectangleGc = SyntaxHighlightingService.GetColor(editor.EditorTheme, isPrimaryHighlighted ? EditorThemeColors.SecondaryTemplateHighlighted : EditorThemeColors.SecondaryTemplate);
                        }

                        // Draw segment
                        double x1 = metrics.TextRenderStartPosition + x_pos - 1;
                        double x2 = metrics.TextRenderStartPosition + x_pos2 - 1 + 0.5;

                        cr.Rectangle(x1 + 0.5, metrics.LineYRenderStartPosition + 0.5, x2 - x1, editor.LineHeight - 1);

                        cr.SetSourceColor(fillGc);
                        cr.FillPreserve();

                        cr.SetSourceColor(rectangleGc);
                        cr.Stroke();
                    }
                }
            }
            return(true);
        }
Example #9
0
		public override void DrawBackground (MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, int startOffset, int endOffset)
		{
			this.editor = editor;
			int markerStart = base.Offset;
			int markerEnd = base.EndOffset;

			if (markerEnd < startOffset || markerStart > endOffset)
				return;

			double @from;
			double to;
			var startXPos = metrics.TextRenderStartPosition;
			var endXPos = metrics.TextRenderEndPosition;
			var y = metrics.LineYRenderStartPosition;
			if (markerStart < startOffset && endOffset < markerEnd) {
				@from = startXPos;
				to = endXPos;
			} else {
				int start = startOffset < markerStart ? markerStart : startOffset;
				int end = endOffset < markerEnd ? endOffset : markerEnd;

				uint curIndex = 0, byteIndex = 0;
				TextViewMargin.TranslateToUTF8Index (metrics.Layout.LineChars, (uint)(start - startOffset), ref curIndex, ref byteIndex);

				int x_pos = metrics.Layout.Layout.IndexToPos ((int)byteIndex).X;

				@from = startXPos + (int)(x_pos / Pango.Scale.PangoScale);

				TextViewMargin.TranslateToUTF8Index (metrics.Layout.LineChars, (uint)(end - startOffset), ref curIndex, ref byteIndex);
				x_pos = metrics.Layout.Layout.IndexToPos ((int)byteIndex).X;

				to = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
			}

			@from = Math.Max (@from, editor.TextViewMargin.XOffset);
			to = Math.Max (to, editor.TextViewMargin.XOffset);
			if (@from < to) {
				cr.SetSourceColor (background(editor).Color);
				cr.RoundedRectangle (@from + 2.5, y + 0.5, to - @from, editor.LineHeight - 1, 2); // 2.5 to make space for the column guideline

				if (background(editor).HasBorderColor) {
					cr.FillPreserve ();

					cr.SetSourceColor (background(editor).BorderColor);
					cr.Stroke ();
				} else {
					cr.Fill ();
				}
			}
		}
Example #10
0
        public override void Draw(MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics)
        {
            var    startOffset = metrics.TextStartOffset;
            int    endOffset   = metrics.TextEndOffset;
            double startXPos   = metrics.TextRenderStartPosition;
            double endXPos     = metrics.TextRenderEndPosition;
            double y           = metrics.LineYRenderStartPosition;
            var    layout      = metrics.Layout.Layout;
            var    lineOffset  = LineSegment.Offset;
            int    markerStart = lineOffset + startColumn;
            int    markerEnd   = lineOffset + endColumn;

            if (markerEnd < startOffset || markerStart > endOffset)
            {
                return;
            }

            double @from;
            double to;

            if (markerStart < startOffset && endOffset < markerEnd)
            {
                @from = startXPos;
                to    = endXPos;
            }
            else
            {
                int start = startOffset < markerStart ? markerStart : startOffset;
                int end   = endOffset < markerEnd ? endOffset : markerEnd;

                uint curIndex = 0, byteIndex = 0;
                int  x_pos = layout.IndexToPos((int)metrics.Layout.TranslateToUTF8Index((uint)(start - startOffset), ref curIndex, ref byteIndex)).X;

                @from = startXPos + (int)(x_pos / Pango.Scale.PangoScale);

                x_pos = layout.IndexToPos((int)metrics.Layout.TranslateToUTF8Index((uint)(end - startOffset), ref curIndex, ref byteIndex)).X;

                to = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
            }

            @from = System.Math.Max(@from, editor.TextViewMargin.XOffset);
            to    = System.Math.Max(to, editor.TextViewMargin.XOffset);
            if (@from < to)
            {
                cr.DrawLine(editor.EditorTheme.GetForeground(editor.EditorTheme.GetChunkStyle(new ScopeStack(style))), @from + 0.5, y + editor.LineHeight - 1.5, to + 0.5, y + editor.LineHeight - 1.5);
            }
        }
		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 #12
0
        public override void Draw(MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics)
        {
            var    startOffset = metrics.TextStartOffset;
            int    endOffset   = metrics.TextEndOffset;
            double startXPos   = metrics.TextRenderStartPosition;
            double endXPos     = metrics.TextRenderEndPosition;
            double y           = metrics.LineYRenderStartPosition;
            var    layout      = metrics.Layout.Layout;

            int markerStart = LineSegment.Offset + System.Math.Max(StartCol - 1, 0);
            int markerEnd   = LineSegment.Offset + (EndCol < 1 ? LineSegment.Length : EndCol - 1);

            if (markerEnd < startOffset || markerStart > endOffset)
            {
                return;
            }

            if (editor.IsSomethingSelected)
            {
                var range = editor.SelectionRange;
                if (range.Contains(markerStart))
                {
                    int end = System.Math.Min(markerEnd, range.EndOffset);
                    InternalDraw(markerStart, end, editor, cr, layout, true, startOffset, endOffset, y, startXPos, endXPos);
                    InternalDraw(range.EndOffset, markerEnd, editor, cr, layout, false, startOffset, endOffset, y, startXPos, endXPos);
                    return;
                }
                if (range.Contains(markerEnd))
                {
                    InternalDraw(markerStart, range.Offset, editor, cr, layout, false, startOffset, endOffset, y, startXPos, endXPos);
                    InternalDraw(range.Offset, markerEnd, editor, cr, layout, true, startOffset, endOffset, y, startXPos, endXPos);
                    return;
                }
                if (markerStart <= range.Offset && range.EndOffset <= markerEnd)
                {
                    InternalDraw(markerStart, range.Offset, editor, cr, layout, false, startOffset, endOffset, y, startXPos, endXPos);
                    InternalDraw(range.Offset, range.EndOffset, editor, cr, layout, true, startOffset, endOffset, y, startXPos, endXPos);
                    InternalDraw(range.EndOffset, markerEnd, editor, cr, layout, false, startOffset, endOffset, y, startXPos, endXPos);
                    return;
                }
            }

            InternalDraw(markerStart, markerEnd, editor, cr, layout, false, startOffset, endOffset, y, startXPos, endXPos);
        }
        public override void Draw(TextEditor editor, Context cr, double y, LineMetrics metrics)
        {
            var    startOffset = metrics.TextStartOffset;
            int    endOffset   = metrics.TextEndOffset;
            double startXPos   = metrics.TextRenderStartPosition;
            double endXPos     = metrics.TextRenderEndPosition;
            var    layout      = metrics.Layout.Layout;
            int    markerStart = line.Offset + startColumn;
            int    markerEnd   = line.Offset + endColumn;

            if (markerEnd < startOffset || markerStart > endOffset)
            {
                return;
            }

            double @from;
            double to;

            if (markerStart < startOffset && endOffset < markerEnd)
            {
                @from = startXPos;
                to    = endXPos;
            }
            else
            {
                int start = startOffset < markerStart ? markerStart : startOffset;
                int end   = endOffset < markerEnd ? endOffset : markerEnd;
                var x_pos = layout.GetCoordinateFromIndex(start - startOffset).X;

                @from = startXPos + (x_pos /* / Pango.Scale.PangoScale*/);

                x_pos = layout.GetCoordinateFromIndex(end - startOffset).X;

                to = startXPos + (x_pos /* / Pango.Scale.PangoScale*/);
            }

            @from = System.Math.Max(@from, editor.TextViewMargin.XOffset);
            to    = System.Math.Max(to, editor.TextViewMargin.XOffset);
            if (@from < to)
            {
                cr.DrawLine(editor.ColorStyle.GetForeground(editor.ColorStyle.GetChunkStyle(style)), @from + 0.5, y + editor.LineHeight - 1.5, to + 0.5, y + editor.LineHeight - 1.5);
            }
        }
		public override void DrawBackground (MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, int startOffset, int endOffset)
		{
			int markerStart = Offset;
			int markerEnd = EndOffset;

			double @from;
			double to;
			var startXPos = metrics.TextRenderStartPosition;
			var endXPos = metrics.TextRenderEndPosition;
			var y = metrics.LineYRenderStartPosition;
			if (markerStart < startOffset && endOffset < markerEnd) {
				@from = startXPos;
				to = endXPos;
			} else {
				int start = startOffset < markerStart ? markerStart : startOffset;
				int end = endOffset < markerEnd ? endOffset : markerEnd;

				uint curIndex = 0, byteIndex = 0;
				TextViewMargin.TranslateToUTF8Index (metrics.Layout.LineChars, (uint)(start - startOffset), ref curIndex, ref byteIndex);

				int x_pos = metrics.Layout.Layout.IndexToPos ((int)byteIndex).X;

				@from = startXPos + (int)(x_pos / Pango.Scale.PangoScale);

				TextViewMargin.TranslateToUTF8Index (metrics.Layout.LineChars, (uint)(end - startOffset), ref curIndex, ref byteIndex);
				x_pos = metrics.Layout.Layout.IndexToPos ((int)byteIndex).X;

				to = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
			}

			@from = Math.Max (@from, editor.TextViewMargin.XOffset);
			to = Math.Max (to, editor.TextViewMargin.XOffset);
			if (@from <= to) {
				if (metrics.TextEndOffset < markerEnd)
					to = metrics.WholeLineWidth + metrics.TextRenderStartPosition;
				var c1 = editor.Options.GetColorStyle ().PlainText.Background;
				var c2 = editor.Options.GetColorStyle ().SelectedText.Background;
				cr.SetSourceRGB ((c1.R + c2.R) / 2, (c1.G + c2.G) / 2, (c1.B + c2.B) / 2);
				cr.Rectangle (@from, y, to - @from, metrics.LineHeight);
				cr.Fill ();
			}
		}
Example #15
0
		public override bool DrawBackground (TextEditor editor, Cairo.Context cr, double y, LineMetrics metrics)
		{
			// check, if a message bubble is active in that line.
			if (LineSegment != null && LineSegment.Markers.Any (m => m != this && (m is IExtendingTextLineMarker)))
				return false;

			var sidePadding = 4;
			var rounding = editor.LineHeight / 2 - 1;

			var d = metrics.TextRenderEndPosition - metrics.TextRenderStartPosition;
			if (d > 0) {
				cr.LineWidth = 1;
				cr.RoundedRectangle (metrics.TextRenderStartPosition, Math.Floor (y) + 0.5, d + sidePadding, metrics.LineHeight - 1, rounding);
				cr.SetSourceColor (BackgroundColor); 
				cr.FillPreserve ();
				cr.SetSourceColor (BorderColor); 
				cr.Stroke ();
			}

			return base.DrawBackground (editor, cr, y, metrics);
		}
Example #16
0
        public override void Draw(MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics)
        {
            if (editor is null)
            {
                throw new ArgumentNullException(nameof(editor));
            }
            if (cr is null)
            {
                throw new ArgumentNullException(nameof(cr));
            }
            if (metrics is null)
            {
                throw new ArgumentNullException(nameof(metrics));
            }

            var    startOffset   = metrics.TextStartOffset;
            int    endOffset     = metrics.TextEndOffset;
            double startXPos     = metrics.TextRenderStartPosition;
            double endXPos       = metrics.TextRenderEndPosition;
            double y             = metrics.LineYRenderStartPosition;
            var    layoutWrapper = metrics.Layout;
            var    layout        = layoutWrapper?.Layout;

            if (layout == null || LineSegment == null)
            {
                return;
            }
            var lineOffset  = LineSegment.Offset;
            int markerStart = lineOffset + startColumn;
            int markerEnd   = lineOffset + endColumn;

            if (markerEnd < startOffset || markerStart > endOffset)
            {
                return;
            }

            var(x1, x2) = CalculateXPositions(startOffset, endOffset, startXPos, endXPos, layoutWrapper, layout, markerStart, markerEnd);
            DrawUnderline(editor, cr, y, layoutWrapper, markerStart, x1, x2);
        }
		public override void Draw (MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics)
		{
			var startOffset = metrics.TextStartOffset;
			int endOffset = metrics.TextEndOffset;
			double startXPos = metrics.TextRenderStartPosition;
			double endXPos = metrics.TextRenderEndPosition;
			double y = metrics.LineYRenderStartPosition;
			var layout = metrics.Layout.Layout;

			int markerStart = LineSegment.Offset + System.Math.Max (StartCol - 1, 0);
			int markerEnd = LineSegment.Offset + (EndCol < 1 ? LineSegment.Length : EndCol - 1);
			if (markerEnd < startOffset || markerStart > endOffset) 
				return; 
			
			if (editor.IsSomethingSelected) {
				var range = editor.SelectionRange;
				if (range.Contains (markerStart)) {
					int end = System.Math.Min (markerEnd, range.EndOffset);
					InternalDraw (markerStart, end, editor, cr, layout, true, startOffset, endOffset, y, startXPos, endXPos);
					InternalDraw (range.EndOffset, markerEnd, editor, cr, layout, false, startOffset, endOffset, y, startXPos, endXPos);
					return;
				}
				if (range.Contains (markerEnd)) {
					InternalDraw (markerStart, range.Offset, editor, cr, layout, false, startOffset, endOffset, y, startXPos, endXPos);
					InternalDraw (range.Offset, markerEnd, editor, cr, layout, true, startOffset, endOffset, y, startXPos, endXPos);
					return;
				}
				if (markerStart <= range.Offset && range.EndOffset <= markerEnd) {
					InternalDraw (markerStart, range.Offset, editor, cr, layout, false, startOffset, endOffset, y, startXPos, endXPos);
					InternalDraw (range.Offset, range.EndOffset, editor, cr, layout, true, startOffset, endOffset, y, startXPos, endXPos);
					InternalDraw (range.EndOffset, markerEnd, editor, cr, layout, false, startOffset, endOffset, y, startXPos, endXPos);
					return;
				}
				
			}
			
			InternalDraw (markerStart, markerEnd, editor, cr, layout, false, startOffset, endOffset, y, startXPos, endXPos);
		}
Example #18
0
 public virtual void Draw(TextEditor editor, Xwt.Drawing.Context cr, double y, LineMetrics metrics)
 {
 }
		public override void Draw (TextEditor editor, Cairo.Context cr, double y, LineMetrics metrics)
		{
			Color = Info.ErrorType == ErrorType.Warning ? editor.ColorStyle.UnderlineWarning.Color : editor.ColorStyle.UnderlineError.Color;

			base.Draw (editor, cr, y, metrics);
		}
Example #20
0
 public virtual void Draw(MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics)
 {
 }
Example #21
0
 public virtual void DrawBackground(MonoTextEditor editor, Context cr, LineMetrics metrics, int startOffset, int endOffset)
 {
 }
Example #22
0
		/// <summary>
		/// Draws the background of the text.
		/// </summary>
		/// <returns><c>true</c>, if background was drawn, <c>false</c> otherwise.</returns>
		/// <param name="editor">The editor.</param>
		/// <param name="cr">The cairo context.</param>
		/// <param name="y">The y coordinate.</param>
		/// <param name="metrics">The line metrics.</param>
		public virtual bool DrawBackground (TextEditor editor, Cairo.Context cr, double y, LineMetrics metrics)
		{
			return false;
		}
		public override void Draw (TextEditor editor, Cairo.Context g, double y, LineMetrics metrics)
		{
			EnsureLayoutCreated (editor);
			double x = editor.TextViewMargin.XOffset;
			int errorCounterWidth = GetErrorCountBounds (metrics.Layout).Item1;

			var sx = metrics.TextRenderEndPosition;
			var width = LayoutWidth + errorCounterWidth + editor.LineHeight;
			var drawLayout = layouts[0].Layout;
			int ex = 0 , ey = 0;
			bool customLayout = sx + width > editor.Allocation.Width;
			bool hideText = false;
			bubbleIsReduced = customLayout;
			if (customLayout) {
				width = editor.Allocation.Width - sx;
				string text = layouts[0].Layout.Text;
				drawLayout = new Pango.Layout (editor.PangoContext);
				drawLayout.FontDescription = cache.fontDescription;
				for (int j = text.Length - 4; j > 0; j--) {
					drawLayout.SetText (text.Substring (0, j) + "...");
					drawLayout.GetPixelSize (out ex, out ey);
					if (ex + (errorCountLayout != null ? errorCounterWidth : 0) + editor.LineHeight < width)
						break;
				}
				if (ex + (errorCountLayout != null ? errorCounterWidth : 0) + editor.LineHeight > width) {
					hideText = true;
					drawLayout.SetMarkup ("<span weight='heavy'>···</span>");
					width = Math.Max (17, errorCounterWidth) + editor.LineHeight;
					sx = Math.Min (sx, editor.Allocation.Width - width);
				}
			}
			bubbleDrawX = sx - editor.TextViewMargin.XOffset;
			bubbleDrawY = y;
			bubbleWidth = width;
			g.RoundedRectangle (sx, y + 1, width, editor.LineHeight - 2, editor.LineHeight / 2 - 1);
			g.Color = TagColor.Color;
			g.Fill ();

			if (errorCounterWidth > 0 && errorCountLayout != null) {
				g.RoundedRectangle (sx + width - errorCounterWidth - editor.LineHeight / 2, y + 2, errorCounterWidth, editor.LineHeight - 4, editor.LineHeight / 2 - 3);
				g.Color = CounterColor.Color;
				g.Fill ();

				g.Save ();
				int ew, eh;
				errorCountLayout.GetPixelSize (out ew, out eh);
				g.Translate (sx + width - errorCounterWidth - editor.LineHeight / 2 + (errorCounterWidth - ew) / 2, y + 1);
				g.Color = CounterColor.SecondColor;
				g.ShowLayout (errorCountLayout);
				g.Restore ();
			}

			if (errorCounterWidth <= 0 || errorCountLayout == null || !hideText) {
				g.Save ();
				g.Translate (sx + editor.LineHeight / 2, y + (editor.LineHeight - layouts [0].Height) / 2 + layouts [0].Height % 2);
				g.Color = TagColor.SecondColor;
				g.ShowLayout (drawLayout);
				g.Restore ();
			}

			if (customLayout)
				drawLayout.Dispose ();

		}
Example #24
0
        public override void Draw(TextEditor editor, Xwt.Drawing.Context cr, double y, LineMetrics metrics)
        {
            var    startOffset = metrics.TextStartOffset;
            int    endOffset   = metrics.TextEndOffset;
            double startXPos   = metrics.TextRenderStartPosition;
            double endXPos     = metrics.TextRenderEndPosition;
            var    layout      = metrics.Layout.Layout;
            int    markerStart = line.Offset + startColumn;
            int    markerEnd   = line.Offset + endColumn;

            if (markerEnd < startOffset || markerStart > endOffset)
            {
                return;
            }

            double @from;
            double to;

            if (markerStart < startOffset && endOffset < markerEnd)
            {
                @from = startXPos;
                to    = endXPos;
            }
            else
            {
                int start = startOffset < markerStart ? markerStart : startOffset;
                int end   = endOffset < markerEnd ? endOffset : markerEnd;

                int curIndex = 0, byteIndex = 0;
                var x_pos = layout.IndexToPos((int)metrics.Layout.TranslateToUTF8Index(start - startOffset, ref curIndex, ref byteIndex)).X;

                @from = startXPos + (int)(x_pos);

                x_pos = layout.IndexToPos((int)metrics.Layout.TranslateToUTF8Index(end - startOffset, ref curIndex, ref byteIndex)).X;

                to = startXPos + (int)(x_pos);
            }

            @from = System.Math.Max(@from, editor.TextViewMargin.XOffset);
            to    = System.Math.Max(to, editor.TextViewMargin.XOffset);
            if (@from < to)
            {
                cr.DrawLine(editor.ColorStyle.GetForeground(editor.ColorStyle.GetChunkStyle(style)), @from + 0.5, y + editor.LineHeight - 1.5, to + 0.5, y + editor.LineHeight - 1.5);
            }
        }
 /// <summary>
 /// Draws the background of the text.
 /// </summary>
 /// <returns><c>true</c>, if background was drawn, <c>false</c> otherwise.</returns>
 /// <param name="editor">The editor.</param>
 /// <param name="cr">The cairo context.</param>
 /// <param name="y">The y coordinate.</param>
 /// <param name="metrics">The line metrics.</param>
 public virtual bool DrawBackground(TextEditor editor, Context cr, double y, LineMetrics metrics)
 {
     return(false);
 }
 public virtual void Draw(TextEditor editor, Context cr, double y, LineMetrics metrics)
 {
     Draw(editor, cr, metrics.Layout.Layout, false, metrics.TextStartOffset, metrics.TextEndOffset, y, metrics.TextRenderStartPosition, metrics.TextRenderEndPosition);
 }
Example #27
0
 public virtual void Draw(TextEditor editor, Cairo.Context cr, double y, LineMetrics metrics)
 {
 }
Example #28
0
        void InternalDraw(int markerStart, int markerEnd, MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, bool selected, int startOffset, int endOffset, double y, double startXPos, double endXPos)
        {
            if (markerStart > markerEnd)
            {
                return;
            }
            var    layout = metrics.Layout.Layout;
            double @from;
            double to;

            if (markerStart < startOffset && endOffset < markerEnd)
            {
                @from = startXPos;
                to    = endXPos;
            }
            else
            {
                int             start = startOffset < markerStart ? markerStart : startOffset;
                int             end   = endOffset < markerEnd ? endOffset : markerEnd;
                int /*lineNr,*/ x_pos;
                uint            curIndex  = 0;
                uint            byteIndex = 0;
                metrics.Layout.TranslateToUTF8Index((uint)(start - startOffset), ref curIndex, ref byteIndex);

                x_pos = layout.IndexToPos(System.Math.Max(0, (int)byteIndex)).X;
                @from = startXPos + (int)(x_pos / Pango.Scale.PangoScale);

                metrics.Layout.TranslateToUTF8Index((uint)(end - startOffset), ref curIndex, ref byteIndex);

                x_pos = layout.IndexToPos(System.Math.Max(0, (int)byteIndex)).X;

                to = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
                var line = editor.GetLineByOffset(endOffset);
                if (markerEnd > endOffset || @from == to)
                {
                    to += editor.TextViewMargin.CharWidth;
                    if (@from >= to)
                    {
                        @from = to - editor.TextViewMargin.CharWidth;
                    }
                }
            }
            @from = System.Math.Max(@from, editor.TextViewMargin.XOffset);
            to    = System.Math.Max(to, editor.TextViewMargin.XOffset);
            if (@from >= to)
            {
                return;
            }
            double height = editor.LineHeight / 5;

            // TODO : EditorTheme does that look ok ?

            // if (selected) {
            //	cr.SetSourceColor (editor.EditorTheme.SelectedText.Foreground);
            // } else

            if (ColorName == null)
            {
                cr.SetSourceColor(Color);
            }
            else
            {
                HslColor color;
                editor.EditorTheme.TryGetColor(ColorName, out color);
                cr.SetSourceColor(color);
            }
            // }
            if (Wave)
            {
                Pango.CairoHelper.ShowErrorUnderline(cr, @from, y + editor.LineHeight - height, to - @from, height);
            }
            else
            {
                cr.LineWidth = 1;
                cr.MoveTo(@from, y + editor.LineHeight - 1.5);
                cr.LineTo(to, y + editor.LineHeight - 1.5);
                cr.Stroke();
            }
        }
Example #29
0
 /// <summary>
 /// Draws the background of the text.
 /// </summary>
 /// <returns><c>true</c>, if background was drawn, <c>false</c> otherwise.</returns>
 /// <param name="editor">The editor.</param>
 /// <param name="cr">The cairo context.</param>
 /// <param name="metrics">The line metrics.</param>
 public virtual bool DrawBackground(MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics)
 {
     return(false);
 }
		public override void Draw (MonoTextEditor editor, Cairo.Context g, LineMetrics metrics)
		{

		}
		void DrawErrorMarkers (MonoTextEditor editor, Cairo.Context g, LineMetrics metrics, double y)
		{
			uint curIndex = 0, byteIndex = 0;

			var o = metrics.LineSegment.Offset;

			foreach (var task in errors.Select (t => t.Task)) {
				var column = (uint)(Math.Min (Math.Max (0, task.Column - 1), metrics.Layout.LineChars.Length));
				var line = editor.GetLine (task.Line);
				// skip possible white space locations 
				while (column < line.Length && char.IsWhiteSpace (editor.GetCharAt (line.Offset + (int)column))) {
					column++;
				}
				if (column >= line.Length)
					continue;
				int index = (int)metrics.Layout.TranslateToUTF8Index (column, ref curIndex, ref byteIndex);
				var pos = metrics.Layout.Layout.IndexToPos (index);
				var co = o + task.Column - 1;
				g.SetSourceColor (GetMarkerColor (false, metrics.SelectionStart <= co && co < metrics.SelectionEnd));
				g.MoveTo (
					metrics.TextRenderStartPosition + editor.TextViewMargin.TextStartPosition + pos.X / Pango.Scale.PangoScale,
					y + editor.LineHeight - 3
					);
				g.RelLineTo (3, 3);
				g.RelLineTo (-6, 0);
				g.ClosePath ();

				g.Fill ();
			}
		}
		void DrawLinePart (Cairo.Context cr, DocumentLine line, int lineNumber, int logicalRulerColumn, int offset, int length, ref double pangoPosition, ref bool isSelectionDrawn, double y, double maxX, double _lineHeight)
		{
			ISyntaxMode mode = Document.SyntaxMode != null && textEditor.Options.EnableSyntaxHighlighting ? Document.SyntaxMode : new SyntaxMode (Document);
			int selectionStart;
			int selectionEnd;
			if (this.HideSelection) {
				selectionStart = selectionEnd = -1;
			} else {
				GetSelectionOffsets (line, out selectionStart, out selectionEnd);
			}

			// ---- new renderer
			LayoutWrapper layout = CreateLinePartLayout (mode, line, logicalRulerColumn, offset, length, selectionStart, selectionEnd);
			int lineOffset = line.Offset;
			double width = layout.PangoWidth / Pango.Scale.PangoScale;
			double xPos = pangoPosition / Pango.Scale.PangoScale;

			// The caret line marker must be drawn below the text markers otherwise the're invisible
			if ((HighlightCaretLine || textEditor.Options.HighlightCaretLine) && Caret.Line == lineNumber)
				DrawCaretLineMarker (cr, xPos, y, layout.PangoWidth / Pango.Scale.PangoScale, _lineHeight);

			//		if (!(HighlightCaretLine || textEditor.Options.HighlightCaretLine) || Document.GetLine(Caret.Line) != line) {
			if (BackgroundRenderer == null) {
				foreach (var bg in layout.BackgroundColors) {
					int x1, x2;
					x1 = layout.Layout.IndexToPos (bg.FromIdx).X;
					x2 = layout.Layout.IndexToPos (bg.ToIdx).X;
					DrawRectangleWithRuler (
						cr, xPos + textEditor.HAdjustment.Value - TextStartPosition,
						new Cairo.Rectangle ((x1 + pangoPosition) / Pango.Scale.PangoScale, y, (x2 - x1) / Pango.Scale.PangoScale + 1, _lineHeight),
						bg.Color, true);
				}
			}


			bool drawBg = true;
			bool drawText = true;

			LineMetrics metrics  = new LineMetrics {
				LineSegment = line,
				Layout = layout,

				SelectionStart = selectionStart,
				SelectionEnd = selectionEnd,

				TextStartOffset = offset,
				TextEndOffset = offset + length,

				TextRenderStartPosition = xPos,
				TextRenderEndPosition = xPos + width,

				LineHeight = _lineHeight,
				WholeLineWidth = textEditor.Allocation.Width - xPos
			};

			foreach (TextLineMarker marker in line.Markers) {
				if (!marker.IsVisible)
					continue;

				if (marker.DrawBackground (textEditor, cr, y, metrics)) {
					isSelectionDrawn |= (marker.Flags & TextLineMarkerFlags.DrawsSelection) == TextLineMarkerFlags.DrawsSelection;
				}

				var bgMarker = marker as IBackgroundMarker;
				if (bgMarker != null) {
					isSelectionDrawn |= (marker.Flags & TextLineMarkerFlags.DrawsSelection) == TextLineMarkerFlags.DrawsSelection;
					drawText &= bgMarker.DrawBackground (textEditor, cr, metrics.Layout, metrics.SelectionStart, metrics.SelectionEnd, metrics.TextStartOffset, metrics.TextEndOffset, y, metrics.TextRenderStartPosition, metrics.TextRenderEndPosition, ref drawBg);
					continue;
				}
			}

			if (DecorateLineBg != null)
				DecorateLineBg (cr, layout, offset, length, xPos, y, selectionStart, selectionEnd);
			

			if (!isSelectionDrawn && (layout.StartSet || selectionStart == offset + length) && BackgroundRenderer == null) {
				double startX;
				double endX;

				if (selectionStart != offset + length) {
					var start = layout.Layout.IndexToPos ((int)layout.SelectionStartIndex);
					startX = System.Math.Floor (start.X / Pango.Scale.PangoScale);
					var end = layout.Layout.IndexToPos ((int)layout.SelectionEndIndex);
					endX = System.Math.Ceiling (end.X / Pango.Scale.PangoScale);
				} else {
					startX = width;
					endX = startX;
				}

				if (textEditor.MainSelection.SelectionMode == SelectionMode.Block && startX == endX) {
					endX = startX + 2;
				}
				DrawRectangleWithRuler (cr, xPos + textEditor.HAdjustment.Value - TextStartPosition, new Cairo.Rectangle (xPos + startX, y, endX - startX, _lineHeight), this.SelectionColor.Background, true);
			}

			// highlight search results
			TextSegment firstSearch;
			int o = offset;
			uint curIndex = 0, byteIndex = 0;
			if (textEditor.HighlightSearchPattern) {
				while (!(firstSearch = GetFirstSearchResult (o, offset + length)).IsInvalid) {
					double x = pangoPosition;
					HandleSelection (lineOffset, logicalRulerColumn, selectionStart, selectionEnd, System.Math.Max (lineOffset, firstSearch.Offset), System.Math.Min (lineOffset + line.Length, firstSearch.EndOffset), delegate(int start, int end) {
						uint startIndex = (uint)(start - offset);
						uint endIndex = (uint)(end - offset);
						if (startIndex < endIndex && endIndex <= layout.LineChars.Length) {
							uint startTranslated = TranslateToUTF8Index (layout.LineChars, startIndex, ref curIndex, ref byteIndex);
							uint endTranslated = TranslateToUTF8Index (layout.LineChars, endIndex, ref curIndex, ref byteIndex);
							
							int l, x1, x2;
							layout.Layout.IndexToLineX ((int)startTranslated, false, out l, out x1);
							layout.Layout.IndexToLineX ((int)endTranslated, false, out l, out x2);
							int w = (int) System.Math.Ceiling ((x2 - x1) / Pango.Scale.PangoScale);
							int s = (int) System.Math.Floor ((x1 + x) / Pango.Scale.PangoScale);
							double corner = System.Math.Min (4, width) * textEditor.Options.Zoom;

							cr.Color = MainSearchResult.IsInvalid || MainSearchResult.Offset != firstSearch.Offset ? ColorStyle.SearchResult.Color : ColorStyle.SearchResultMain.Color;
							FoldingScreenbackgroundRenderer.DrawRoundRectangle (cr, true, true, s, y, corner, w + 1, LineHeight);
							cr.Fill ();
						}
					}, null);
	
					o = System.Math.Max (firstSearch.EndOffset, o + 1);
				}
			}
			
			cr.Save ();
			cr.Translate (xPos, y);
			cr.ShowLayout (layout.Layout);
			cr.Restore ();
			if (offset == line.Offset) {
				DrawIndent (cr, layout, line, xPos, y);
			}

			if (textEditor.Options.ShowWhitespaces != ShowWhitespaces.Never && !(BackgroundRenderer != null && textEditor.Options.ShowWhitespaces == ShowWhitespaces.Selection))
				DecorateTabsAndSpaces (cr, layout, offset, length, xPos, y, selectionStart, selectionEnd);

			if (lineNumber == Caret.Line) {
				int caretOffset = Caret.Offset;
				if (offset <= caretOffset && caretOffset <= offset + length) {
					int index = caretOffset - offset;

					if (Caret.Column > line.Length + 1) {
						string virtualSpace = "";
						var data = textEditor.GetTextEditorData ();
						if (data.HasIndentationTracker && line.Length == 0) {
							virtualSpace = this.textEditor.GetTextEditorData ().GetIndentationString (Caret.Location);
						}
						if (Caret.Column > line.Length + 1 + virtualSpace.Length) 
							virtualSpace += new string (' ', Caret.Column - line.Length - 1 - virtualSpace.Length);

						// predit layout already contains virtual space.
						if (!string.IsNullOrEmpty (textEditor.preeditString))
							virtualSpace = ""; 
						LayoutWrapper wrapper = new LayoutWrapper (PangoUtil.CreateLayout (textEditor));
						wrapper.LineChars = virtualSpace.ToCharArray ();
						wrapper.Layout.SetText (virtualSpace);
						wrapper.Layout.Tabs = tabArray;
						wrapper.Layout.FontDescription = textEditor.Options.Font;
						int vy, vx;
						wrapper.Layout.GetSize (out vx, out vy);
						
						var x = ((pangoPosition + vx + layout.PangoWidth) / Pango.Scale.PangoScale);
						SetVisibleCaretPosition (x, y, x, y);
						xPos = (pangoPosition + layout.PangoWidth) / Pango.Scale.PangoScale;

						if (!isSelectionDrawn && (selectionEnd == lineOffset + line.Length) && BackgroundRenderer == null) {
							double startX;
							double endX;
							startX = xPos;
							endX = (pangoPosition + vx + layout.PangoWidth) / Pango.Scale.PangoScale;
							DrawRectangleWithRuler (cr, xPos + textEditor.HAdjustment.Value - TextStartPosition, new Cairo.Rectangle (startX, y, endX - startX, _lineHeight), this.SelectionColor.Background, true);
						}

						// When drawing virtual space before the selection start paint it as unselected.
						var virtualSpaceMod = selectionStart < caretOffset ? 0 : virtualSpace.Length;

						if ((!textEditor.IsSomethingSelected || (selectionStart >= offset && selectionStart != selectionEnd)) && (HighlightCaretLine || textEditor.Options.HighlightCaretLine) && Caret.Line == lineNumber)
							DrawCaretLineMarker (cr, pangoPosition / Pango.Scale.PangoScale, y, vx / Pango.Scale.PangoScale, _lineHeight);

						if (DecorateLineBg != null)
							DecorateLineBg (cr, wrapper, offset, length, xPos, y, selectionStart + virtualSpaceMod, selectionEnd + virtualSpace.Length);

						switch (textEditor.Options.ShowWhitespaces) {
						case ShowWhitespaces.Selection:
							if (textEditor.IsSomethingSelected && (selectionStart < offset || selectionStart == selectionEnd) && BackgroundRenderer == null)
								DecorateTabsAndSpaces (cr, wrapper, offset, length, xPos, y, selectionStart, selectionEnd + virtualSpace.Length);
							break;
						case ShowWhitespaces.Always:
							DecorateTabsAndSpaces (cr, wrapper, offset, length, xPos, y, selectionStart, selectionEnd + virtualSpace.Length);
							break;
						}

						wrapper.Dispose ();
						pangoPosition += vx;
					} else if (index == length && string.IsNullOrEmpty (textEditor.preeditString)) {
						var x = (pangoPosition + layout.PangoWidth) / Pango.Scale.PangoScale;
						SetVisibleCaretPosition (x, y, x, y);
					} else if (index >= 0 && index <= length) {
						Pango.Rectangle strong_pos, weak_pos;
						curIndex = byteIndex = 0;
						int utf8ByteIndex = (int)TranslateToUTF8Index (layout.LineChars, (uint)index, ref curIndex, ref byteIndex);
						layout.Layout.GetCursorPos (utf8ByteIndex, out strong_pos, out weak_pos);
						var cx = xPos + (strong_pos.X / Pango.Scale.PangoScale);
						var cy = y + (strong_pos.Y / Pango.Scale.PangoScale);
						if (textEditor.preeditCursorCharIndex == 0) {
							SetVisibleCaretPosition (cx, cy, cx, cy);
						} else {
							var preeditIndex = (uint)(index + textEditor.preeditCursorCharIndex);
							utf8ByteIndex = (int)TranslateToUTF8Index (layout.LineChars, preeditIndex, ref curIndex, ref byteIndex);
							layout.Layout.GetCursorPos (utf8ByteIndex, out strong_pos, out weak_pos);
							var pcx = xPos + (strong_pos.X / Pango.Scale.PangoScale);
							var pcy = y + (strong_pos.Y / Pango.Scale.PangoScale);
							SetVisibleCaretPosition (pcx, pcy, cx, cy);
						}
					}
				}
			}

			foreach (TextLineMarker marker in line.Markers.Where (m => m.IsVisible)) {
				if (layout.Layout != null)
					marker.Draw (textEditor, cr, y, metrics);
			}

			foreach (var marker in Document.GetTextSegmentMarkersAt (line).Where (m => m.IsVisible)) {
				if (layout.Layout != null)
					marker.Draw (textEditor, cr, layout.Layout, false, /*selected*/offset, offset + length, y, xPos, xPos + width);
			}

			pangoPosition += layout.PangoWidth;
			int scaledDown = (int)(pangoPosition / Pango.Scale.PangoScale);
			pangoPosition = scaledDown * Pango.Scale.PangoScale;

			if (layout.IsUncached)
				layout.Dispose ();
		}
Example #33
0
		public virtual void Draw (TextEditor editor, Cairo.Context cr, double y, LineMetrics metrics)
		{
			Draw (editor, cr, metrics.Layout.Layout, false, metrics.TextStartOffset, metrics.TextEndOffset, y, metrics.TextRenderStartPosition, metrics.TextRenderEndPosition);
		}
		public override void Draw (TextEditor editor, Cairo.Context g, double y, LineMetrics metrics)
		{

		}
Example #35
0
 public override void DrawBackground(MonoTextEditor editor, Context cr, LineMetrics metrics, int startOffset, int endOffset)
 {
     int x1 = editor.LocationToPoint(editor.OffsetToLocation(this.Offset), false).X;
     int x2 = editor.LocationToPoint(editor.OffsetToLocation(this.Offset + this.Length), false).X;
     cr.Rectangle(x1, metrics.LineYRenderStartPosition + 0.5, x2 - x1, metrics.LineHeight - 1);
     cr.SetSourceRGB(1.0, 1.0, 0.0);
     cr.Fill();
 }
		void DrawErrorMarkers (TextEditor editor, Cairo.Context g, LineMetrics metrics, double y)
		{
			uint curIndex = 0, byteIndex = 0;

			var o = metrics.LineSegment.Offset;

			foreach (var task in errors.Select (t => t.Task)) {
				var column = (uint)(Math.Min (Math.Max (0, task.Column - 1), metrics.Layout.LineChars.Length));
				int index = (int)metrics.Layout.TranslateToUTF8Index (column, ref curIndex, ref byteIndex);
				var pos = metrics.Layout.Layout.IndexToPos (index);
				var co = o + task.Column - 1;
				g.SetSourceColor (GetMarkerColor (false, metrics.SelectionStart <= co && co < metrics.SelectionEnd));
				g.MoveTo (
					metrics.TextRenderStartPosition + editor.TextViewMargin.TextStartPosition + pos.X / Pango.Scale.PangoScale,
					y + editor.LineHeight - 3
					);
				g.RelLineTo (3, 3);
				g.RelLineTo (-6, 0);
				g.ClosePath ();

				g.Fill ();
			}
		}
Example #37
0
		public virtual void Draw (TextEditor editor, Cairo.Context cr, double y, LineMetrics metrics)
		{
#pragma warning disable 618
			Draw (editor, cr, metrics.Layout.Layout, false, metrics.TextStartOffset, metrics.TextEndOffset, y, metrics.TextRenderStartPosition, metrics.TextRenderEndPosition);
#pragma warning restore 618
		}
			public override bool DrawBackground (TextEditor editor, Cairo.Context cr, double y, LineMetrics metrics)
			{
				if (metrics.SelectionStart >= 0 || editor.CurrentMode is TextLinkEditMode || editor.TextViewMargin.SearchResultMatchCount > 0)
					return false;
				foreach (var usage in Usages) {
					int markerStart = usage.TextSegment.Offset;
					int markerEnd = usage.TextSegment.EndOffset;
					
					if (markerEnd < metrics.TextStartOffset || markerStart > metrics.TextEndOffset) 
						return false; 
					
					double @from;
					double to;
					
					if (markerStart < metrics.TextStartOffset && metrics.TextEndOffset < markerEnd) {
						@from = metrics.TextRenderStartPosition;
						to = metrics.TextRenderEndPosition;
					} else {
						int start = metrics.TextStartOffset < markerStart ? markerStart : metrics.TextStartOffset;
						int end = metrics.TextEndOffset < markerEnd ? metrics.TextEndOffset : markerEnd;
						
						uint curIndex = 0, byteIndex = 0;
						TextViewMargin.TranslateToUTF8Index (metrics.Layout.LineChars, (uint)(start - metrics.TextStartOffset), ref curIndex, ref byteIndex);
						
						int x_pos = metrics.Layout.Layout.IndexToPos ((int)byteIndex).X;
						
						@from = metrics.TextRenderStartPosition + (int)(x_pos / Pango.Scale.PangoScale);
						
						TextViewMargin.TranslateToUTF8Index (metrics.Layout.LineChars, (uint)(end - metrics.TextStartOffset), ref curIndex, ref byteIndex);
						x_pos = metrics.Layout.Layout.IndexToPos ((int)byteIndex).X;
			
						to = metrics.TextRenderStartPosition + (int)(x_pos / Pango.Scale.PangoScale);
					}
		
					@from = System.Math.Max (@from, editor.TextViewMargin.XOffset);
					to = System.Math.Max (to, editor.TextViewMargin.XOffset);
					if (@from < to) {
						Mono.TextEditor.Highlighting.AmbientColor colorStyle;
						if ((usage.UsageType & ReferenceUsageType.Write) == ReferenceUsageType.Write) {
							colorStyle = editor.ColorStyle.ChangingUsagesRectangle;
						} else {
							colorStyle = editor.ColorStyle.UsagesRectangle;
						}

						using (var lg = new LinearGradient (@from + 1, y + 1, to , y + editor.LineHeight)) {
							lg.AddColorStop (0, colorStyle.Color);
							lg.AddColorStop (1, colorStyle.SecondColor);
							cr.SetSource (lg);
							cr.RoundedRectangle (@from + 0.5, y + 1.5, to - @from - 1, editor.LineHeight - 2, editor.LineHeight / 4);
							cr.FillPreserve ();
						}
						
						cr.SetSourceColor (colorStyle.BorderColor);
						cr.Stroke ();
					}
				}
				return true;
			}
		void DrawLinePart (Cairo.Context cr, DocumentLine line, int lineNumber, int logicalRulerColumn, int offset, int length, ref double position, ref bool isSelectionDrawn, double y, double maxX, double _lineHeight)
		{
			ISyntaxMode mode = Document.SyntaxMode != null && textEditor.Options.EnableSyntaxHighlighting ? Document.SyntaxMode : new SyntaxMode (Document);
			int selectionStartOffset;
			int selectionEndOffset;
			if (this.HideSelection) {
				selectionStartOffset = selectionEndOffset = -1;
			} else {
				GetSelectionOffsets (line, out selectionStartOffset, out selectionEndOffset);
			}

			// ---- new renderer
			LayoutWrapper layout = CreateLinePartLayout (mode, line, logicalRulerColumn, offset, length, selectionStartOffset, selectionEndOffset);
			int lineOffset = line.Offset;
			double width = layout.Width;
			double xPos = position;

			// The caret line marker must be drawn below the text markers otherwise the're invisible
			if ((HighlightCaretLine || textEditor.GetTextEditorData ().HighlightCaretLine) && Caret.Line == lineNumber)
				DrawCaretLineMarker (cr, xPos, y, layout.Width, _lineHeight);

			//		if (!(HighlightCaretLine || textEditor.Options.HighlightCaretLine) || Document.GetLine(Caret.Line) != line) {
			if (BackgroundRenderer == null) {
				foreach (var bg in layout.BackgroundColors) {
					int x1, x2;
					x1 = layout.Layout.IndexToPos (bg.FromIdx).X;
					x2 = layout.Layout.IndexToPos (bg.ToIdx).X;
					DrawRectangleWithRuler (
						cr, xPos + textEditor.HAdjustment.Value - TextStartPosition,
						new Cairo.Rectangle (x1 / Pango.Scale.PangoScale + position, y, (x2 - x1) / Pango.Scale.PangoScale + 1, _lineHeight),
						bg.Color, true);
				}
			}

			var metrics  = new LineMetrics {
				LineSegment = line,
				Layout = layout,

				SelectionStart = selectionStartOffset,
				SelectionEnd = selectionEndOffset,

				TextStartOffset = offset,
				TextEndOffset = offset + length,

				TextRenderStartPosition = xPos,
				TextRenderEndPosition = xPos + width,

				LineHeight = _lineHeight,
				WholeLineWidth = textEditor.Allocation.Width - xPos,

				LineYRenderStartPosition = y
			};

			foreach (TextLineMarker marker in line.Markers) {
				if (!marker.IsVisible)
					continue;

				if (marker.DrawBackground (textEditor, cr, metrics)) {
					isSelectionDrawn |= (marker.Flags & TextLineMarkerFlags.DrawsSelection) == TextLineMarkerFlags.DrawsSelection;
				}
			}

			var textSegmentMarkers = TextDocument.OrderTextSegmentMarkersByInsertion (Document.GetTextSegmentMarkersAt (line).Where (m => m.IsVisible)).ToArray ();
			foreach (var marker in textSegmentMarkers) {
				if (layout.Layout != null)
					marker.DrawBackground (textEditor, cr, metrics, offset, offset + length);
			}


			if (DecorateLineBg != null)
				DecorateLineBg (cr, layout, offset, length, xPos, y, selectionStartOffset, selectionEndOffset);
			

			if (!isSelectionDrawn && (layout.StartSet || selectionStartOffset == offset + length) && BackgroundRenderer == null) {
				double startX;
				int startY;
				double endX;
				int endY;
				if (selectionStartOffset != offset + length) {
					var start = layout.Layout.IndexToPos (layout.SelectionStartIndex);
					startX = System.Math.Floor (start.X / Pango.Scale.PangoScale);
					startY = (int)(y + System.Math.Floor (start.Y / Pango.Scale.PangoScale));

					var end = layout.Layout.IndexToPos (layout.SelectionEndIndex);
					endX = System.Math.Ceiling (end.X / Pango.Scale.PangoScale);
					endY = (int)(y + System.Math.Ceiling (end.Y / Pango.Scale.PangoScale));
				} else {
					startY = endY = (int)y;
					startX = width;
					endX = startX;
				}

				if (textEditor.MainSelection.SelectionMode == SelectionMode.Block && startX == endX) {
					endX = startX + 2;
				}
				if (startY == endY) {
					DrawRectangleWithRuler (
						cr,
						xPos + textEditor.HAdjustment.Value - TextStartPosition,
						new Cairo.Rectangle (xPos + startX, startY, endX - startX, LineHeight),
						this.SelectionColor.Background,
						true
						);
				} else {
					DrawRectangleWithRuler (
						cr,
						xPos + textEditor.HAdjustment.Value - TextStartPosition,
						new Cairo.Rectangle (xPos + startX, startY, textEditor.Allocation.Width - xPos - startX, LineHeight),
						this.SelectionColor.Background,
						true
					);

					if (endY - startY > LineHeight) {
						DrawRectangleWithRuler (
							cr,
							xPos,
							new Cairo.Rectangle (xPos, startY + LineHeight, textEditor.Allocation.Width - xPos, endY - startY - LineHeight),
							this.SelectionColor.Background,
							true
						);
					}

					DrawRectangleWithRuler (
						cr,
						xPos,
						new Cairo.Rectangle (xPos, endY, endX, LineHeight),
						this.SelectionColor.Background,
						true
						);
				}
			}

			// highlight search results
			TextSegment firstSearch;
			int o = offset;
			uint curIndex = 0, byteIndex = 0;
			if (textEditor.HighlightSearchPattern) {
				while (!(firstSearch = GetFirstSearchResult (o, offset + length)).IsInvalid) {
					double x = position;
					HandleSelection (lineOffset, logicalRulerColumn, selectionStartOffset, selectionEndOffset, System.Math.Max (lineOffset, firstSearch.Offset), System.Math.Min (lineOffset + line.Length, firstSearch.EndOffset), delegate(int start, int end) {
						uint startIndex = (uint)(start - offset);
						uint endIndex = (uint)(end - offset);
						if (startIndex < endIndex && endIndex <= layout.LineChars.Length) {
							uint startTranslated = TranslateToUTF8Index (layout.LineChars, startIndex, ref curIndex, ref byteIndex);
							uint endTranslated = TranslateToUTF8Index (layout.LineChars, endIndex, ref curIndex, ref byteIndex);
							
							int l, x1, x2;
							layout.Layout.IndexToLineX ((int)startTranslated, false, out l, out x1);
							layout.Layout.IndexToLineX ((int)endTranslated, false, out l, out x2);
							int w = (int) System.Math.Ceiling ((x2 - x1) / Pango.Scale.PangoScale);
							int s = (int) System.Math.Floor (x1 / Pango.Scale.PangoScale + x);
							double corner = System.Math.Min (4, width) * textEditor.Options.Zoom;

							cr.SetSourceColor (MainSearchResult.IsInvalid || MainSearchResult.Offset != firstSearch.Offset ? ColorStyle.SearchResult.Color : ColorStyle.SearchResultMain.Color);
							FoldingScreenbackgroundRenderer.DrawRoundRectangle (cr, true, true, s, y, corner, w + 1, LineHeight);
							cr.Fill ();
						}
					}, null);
	
					o = System.Math.Max (firstSearch.EndOffset, o + 1);
				}
			}
			
			cr.Save ();
			cr.Translate (xPos, y);
			cr.ShowLayout (layout.Layout);
			cr.Restore ();
			if (offset == line.Offset) {
				DrawIndent (cr, layout, line, xPos, y);
			}

			if (textEditor.Options.ShowWhitespaces != ShowWhitespaces.Never && !(BackgroundRenderer != null && textEditor.Options.ShowWhitespaces == ShowWhitespaces.Selection))
				DecorateTabsAndSpaces (cr, layout, offset, xPos, y, selectionStartOffset, selectionEndOffset);


			if (textEditor.IsSomethingSelected && !isSelectionDrawn && BackgroundRenderer == null) {
				if (lineNumber == textEditor.MainSelection.End.Line && textEditor.MainSelection.End.Column > line.Length + 1) {
					using (var wrapper = GetVirtualSpaceLayout (line, textEditor.MainSelection.End)) {
						double startX;
						double endX;
						startX = xPos;
						endX = position + wrapper.Width + layout.Width;
						DrawRectangleWithRuler (cr, xPos + textEditor.HAdjustment.Value - TextStartPosition, new Cairo.Rectangle (startX, y, endX - startX, _lineHeight), this.SelectionColor.Background, true);

						if (lineNumber == Caret.Line &&
						    textEditor.Options.ShowWhitespaces == ShowWhitespaces.Selection &&
						    textEditor.IsSomethingSelected &&
						    (selectionStartOffset < offset || selectionStartOffset == selectionEndOffset) &&
						    BackgroundRenderer == null) {
							DecorateTabsAndSpaces (cr, wrapper, offset, xPos, y, selectionStartOffset, selectionEndOffset + wrapper.LineChars.Length);
						}
					}
				}
				
			}

			if (lineNumber == Caret.Line) {
				int caretOffset = Caret.Offset;
				if (offset <= caretOffset && caretOffset <= offset + length) {
					int index = caretOffset - offset;
					//This if means we have temporary indent
					if (Caret.Column > line.Length + 1) {
						using (var wrapper = GetVirtualSpaceLayout (line, Caret.Location)) {
							var x = (position + wrapper.Width) + layout.Width;
							SetVisibleCaretPosition (x, y, x, y);
							xPos = position + layout.Width;


							// When drawing virtual space before the selection start paint it as unselected.
							var virtualSpaceMod = selectionStartOffset < caretOffset ? 0 : wrapper.LineChars.Length;

							if ((!textEditor.IsSomethingSelected || (selectionStartOffset >= offset && selectionStartOffset != selectionEndOffset)) && (HighlightCaretLine || textEditor.Options.HighlightCaretLine) && Caret.Line == lineNumber)
								DrawCaretLineMarker (cr, position, y, wrapper.Width, _lineHeight);

							if (DecorateLineBg != null)
								DecorateLineBg (cr, wrapper, offset, length, xPos, y, selectionStartOffset + virtualSpaceMod, selectionEndOffset + wrapper.LineChars.Length);

							if (textEditor.Options.ShowWhitespaces == ShowWhitespaces.Always) {
								DecorateTabsAndSpaces (cr, wrapper, offset, xPos, y, selectionStartOffset, selectionEndOffset + wrapper.LineChars.Length);
							}
						}
					} else if (index == length && string.IsNullOrEmpty (textEditor.preeditString)) {
						var x = position + layout.Width;
						SetVisibleCaretPosition (x, y, x, y);
					} else if (index >= 0 && index <= length) {
						Pango.Rectangle strong_pos, weak_pos;
						curIndex = byteIndex = 0;
						int utf8ByteIndex = (int)TranslateToUTF8Index (layout.LineChars, (uint)index, ref curIndex, ref byteIndex);
						layout.Layout.GetCursorPos (utf8ByteIndex, out strong_pos, out weak_pos);
						var cx = xPos + (strong_pos.X / Pango.Scale.PangoScale);
						var cy = y + (strong_pos.Y / Pango.Scale.PangoScale);
						if (textEditor.preeditCursorCharIndex == 0) {
							SetVisibleCaretPosition (cx, cy, cx, cy);
						} else {
							var preeditIndex = (uint)(index + textEditor.preeditCursorCharIndex);
							utf8ByteIndex = (int)TranslateToUTF8Index (layout.LineChars, preeditIndex, ref curIndex, ref byteIndex);
							layout.Layout.GetCursorPos (utf8ByteIndex, out strong_pos, out weak_pos);
							var pcx = xPos + (strong_pos.X / Pango.Scale.PangoScale);
							var pcy = y + (strong_pos.Y / Pango.Scale.PangoScale);
							SetVisibleCaretPosition (pcx, pcy, cx, cy);
						}
					}
				}
			}
			foreach (TextLineMarker marker in line.Markers.Where (m => m.IsVisible)) {
				if (layout.Layout != null)
					marker.Draw (textEditor, cr, metrics);
			}

			foreach (var marker in textSegmentMarkers) {
				if (layout.Layout != null)
					marker.Draw (textEditor, cr, metrics, offset, offset + length);
			}
			position += System.Math.Floor (layout.LastLineWidth);

			if (layout.IsUncached)
				layout.Dispose ();
		}
Example #40
0
        public virtual void Draw(TextEditor editor, Cairo.Context cr, double y, LineMetrics metrics)
        {
#pragma warning disable 618
            Draw(editor, cr, metrics.Layout.Layout, false, metrics.TextStartOffset, metrics.TextEndOffset, y, metrics.TextRenderStartPosition, metrics.TextRenderEndPosition);
#pragma warning restore 618
        }
		Tuple<int, int> GetErrorCountBounds (LineMetrics metrics)
		{
			EnsureLayoutCreated (editor);
			var lineTextPx = editor.TextViewMargin.XOffset + metrics.TextRenderEndPosition;
			if (errors.Count > 1 && errorCountLayout != null || editor.Allocation.Width < lineTextPx + layouts [0].Width) {
				int ew = 0, eh = 0;
				if (errorCountLayout != null) {
					errorCountLayout.GetPixelSize (out ew, out eh);
				} else {
					ew = 10;
				}
				return Tuple.Create (ew + 10, eh);
			}
			return Tuple.Create (0, 0);
		}
			void GetLineDrawingPosition (LineMetrics metrics, int startOffset, out double fromX, out double toX)
			{
				var startXPos = metrics.TextRenderStartPosition;
				var endXPos = metrics.TextRenderEndPosition;
				int start = this.Offset;
				int end = this.EndOffset;

				uint curIndex = 0, byteIndex = 0;
				TextViewMargin.TranslateToUTF8Index (metrics.Layout.LineChars, (uint)(start - startOffset), ref curIndex, ref byteIndex);

				int x_pos = metrics.Layout.Layout.IndexToPos ((int)byteIndex).X;

				fromX = startXPos + (int)(x_pos / Pango.Scale.PangoScale);

				TextViewMargin.TranslateToUTF8Index (metrics.Layout.LineChars, (uint)(end - startOffset), ref curIndex, ref byteIndex);
				x_pos = metrics.Layout.Layout.IndexToPos ((int)byteIndex).X;

				toX = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
			}
		public override bool DrawBackground (TextEditor editor, Cairo.Context g, double y, LineMetrics metrics)
		{
			if (!IsVisible)
				return false;
			bool markerShouldDrawnAsHidden = cache.CurrentSelectedTextMarker != null && cache.CurrentSelectedTextMarker != this;
			if (metrics.LineSegment.Markers.Any (m => m is DebugTextMarker))
				return false;

			EnsureLayoutCreated (editor);
			double x = editor.TextViewMargin.XOffset;
			int right = editor.Allocation.Width;
			bool isCaretInLine = metrics.TextStartOffset <= editor.Caret.Offset && editor.Caret.Offset <= metrics.TextEndOffset;
			int errorCounterWidth = GetErrorCountBounds (metrics).Item1;

			double x2 = System.Math.Max (right - LayoutWidth - border - (ShowIconsInBubble ? cache.errorPixbuf.Width : 0) - errorCounterWidth, editor.TextViewMargin.XOffset + editor.LineHeight / 2);

			bool isEolSelected = editor.IsSomethingSelected && editor.SelectionMode != Mono.TextEditor.SelectionMode.Block ? editor.SelectionRange.Contains (lineSegment.Offset + lineSegment.Length) : false;

			int active = editor.Document.GetTextAt (lineSegment) == initialText ? 0 : 1;
			bool highlighted = active == 0 && isCaretInLine;

			// draw background
			if (!markerShouldDrawnAsHidden) {
				DrawRectangle (g, x, y, right, editor.LineHeight);
				g.SetSourceColor (LineColor.Color);
				g.Fill ();

				if (metrics.Layout.StartSet || metrics.SelectionStart == metrics.TextEndOffset) {
					double startX;
					double endX;

					if (metrics.SelectionStart != metrics.TextEndOffset) {
						var start = metrics.Layout.Layout.IndexToPos ((int)metrics.Layout.SelectionStartIndex);
						startX = (int)(start.X / Pango.Scale.PangoScale);
						var end = metrics.Layout.Layout.IndexToPos ((int)metrics.Layout.SelectionEndIndex);
						endX = (int)(end.X / Pango.Scale.PangoScale);
					} else {
						startX = x2;
						endX = startX;
					}

					if (editor.MainSelection.SelectionMode == Mono.TextEditor.SelectionMode.Block && startX == endX)
						endX = startX + 2;
					startX += metrics.TextRenderStartPosition;
					endX += metrics.TextRenderStartPosition;
					startX = Math.Max (editor.TextViewMargin.XOffset, startX);
					// clip region to textviewmargin start
					if (isEolSelected)
						endX = editor.Allocation.Width + (int)editor.HAdjustment.Value;
					if (startX < endX) {
						DrawRectangle (g, startX, y, endX - startX, editor.LineHeight);
						g.SetSourceColor (GetLineColor (highlighted, true));
						g.Fill ();
					}
				}
				DrawErrorMarkers (editor, g, metrics, y);
			}

			double y2 = y + 0.5;
			double y2Bottom = y2 + editor.LineHeight - 1;
			var selected = isEolSelected;
			var lineTextPx = editor.TextViewMargin.XOffset + editor.TextViewMargin.TextStartPosition + metrics.Layout.Width;
			if (x2 < lineTextPx) 
				x2 = lineTextPx;

			if (editor.Options.ShowRuler) {
				double divider = Math.Max (editor.TextViewMargin.XOffset, x + editor.TextViewMargin.RulerX);
				if (divider >= x2) {
					g.MoveTo (new Cairo.PointD (divider + 0.5, y2));
					g.LineTo (new Cairo.PointD (divider + 0.5, y2Bottom));
					g.SetSourceColor (GetLineColorBorder (highlighted, selected));
					g.Stroke ();
				}
			}

			return true;
		}
Example #44
0
		public override void Draw (MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, int startOffset, int endOffset)
		{
			if (OnlyShowLinkOnHover) {
					if (editor.TextViewMargin.MarginCursor != textLinkCursor)
					return;
				if (editor.TextViewMargin.HoveredLine == null)
					return;
				var hoverOffset = editor.LocationToOffset (editor.TextViewMargin.HoveredLocation);
				if (!Segment.Contains (hoverOffset)) 
					return; 
			}
			this.Color = editor.ColorStyle.LinkColor.Color;

			if (!OnlyShowLinkOnHover) {
				if (editor.TextViewMargin.MarginCursor == textLinkCursor && editor.TextViewMargin.HoveredLine != null) {
					var hoverOffset = editor.LocationToOffset (editor.TextViewMargin.HoveredLocation);
					if (Segment.Contains (hoverOffset))
						this.Color = editor.ColorStyle.ActiveLinkColor.Color;
				}
			}

			base.Draw (editor, cr, metrics, startOffset, endOffset);
		}
Example #45
0
		public override void Draw (MonoTextEditor editor, Cairo.Context cr, LineMetrics layout, int startOffset, int endOffset)
		{
			if (DebuggingService.IsDebugging)
				return;
			int markerStart = Segment.Offset;
			int markerEnd = Segment.EndOffset;
			if (markerEnd < startOffset || markerStart > endOffset) 
				return;
			
			double drawFrom;
			double drawTo;
			double y = layout.LineYRenderStartPosition;
			double startXPos = layout.TextRenderStartPosition;
			double endXPos = layout.TextRenderEndPosition;

			if (markerStart < startOffset && endOffset < markerEnd) {
				drawTo = endXPos;
				var line = editor.GetLineByOffset (startOffset);
				int offset = line.GetIndentation (editor.Document).Length;
				drawFrom = startXPos + (layout.Layout.Layout.IndexToPos (offset).X  / Pango.Scale.PangoScale);
			} else {
				int start;
				if (startOffset < markerStart) {
					start = markerStart;
				} else {
					var line = editor.GetLineByOffset (startOffset);
					int offset = line.GetIndentation (editor.Document).Length;
					start = startOffset + offset;
				}
				int end = endOffset < markerEnd ? endOffset : markerEnd;
				int x_pos;

				x_pos = layout.Layout.Layout.IndexToPos (start - startOffset).X;
				drawFrom = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
				x_pos = layout.Layout.Layout.IndexToPos (end - startOffset).X;
	
				drawTo = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
			}
			
			drawFrom = Math.Max (drawFrom, editor.TextViewMargin.XOffset);
			drawTo = Math.Max (drawTo, editor.TextViewMargin.XOffset);
			if (drawFrom >= drawTo)
				return;
			
			double height = editor.LineHeight / 5;
			cr.SetSourceColor (color);
			if (effect == MonoDevelop.Ide.Editor.TextSegmentMarkerEffect.WavedLine) {	
				Pango.CairoHelper.ShowErrorUnderline (cr, drawFrom, y + editor.LineHeight - height, drawTo - drawFrom, height);
			} else if (effect == MonoDevelop.Ide.Editor.TextSegmentMarkerEffect.DottedLine) {
				cr.Save ();
				cr.LineWidth = 1;
				cr.MoveTo (drawFrom + 1, y + editor.LineHeight - 1 + 0.5);
				cr.RelLineTo (Math.Min (drawTo - drawFrom, 4 * 3), 0);
				cr.SetDash (new double[] { 2, 2 }, 0);
				cr.Stroke ();
				cr.Restore ();
			} else {
				cr.MoveTo (drawFrom, y + editor.LineHeight - 1);
				cr.LineTo (drawTo, y + editor.LineHeight - 1);
				cr.Stroke ();
			}
		}
Example #46
0
        void InternalDraw(int markerStart, int markerEnd, MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, bool selected, int startOffset, int endOffset, double y, double startXPos, double endXPos)
        {
            if (markerStart >= markerEnd)
            {
                return;
            }
            var    layout = metrics.Layout.Layout;
            double @from;
            double to;

            if (markerStart < startOffset && endOffset < markerEnd)
            {
                @from = startXPos;
                to    = endXPos;
            }
            else
            {
                int             start = Math.Max(startOffset, markerStart);
                int             end   = Math.Min(endOffset, markerEnd);
                int /*lineNr,*/ x_pos;
                uint            curIndex  = 0;
                uint            byteIndex = 0;

                var textLength = metrics.Layout.Text.Length;
                if (textLength > 0)
                {
                    uint idx = (uint)Math.Min(Math.Max(0, start - startOffset), textLength - 1);
                    metrics.Layout.TranslateToUTF8Index(idx, ref curIndex, ref byteIndex);

                    x_pos = layout.IndexToPos(System.Math.Max(0, (int)byteIndex)).X;
                    @from = startXPos + (int)(x_pos / Pango.Scale.PangoScale);

                    idx = (uint)Math.Min(Math.Max(0, end - startOffset), textLength - 1);
                    metrics.Layout.TranslateToUTF8Index(idx, ref curIndex, ref byteIndex);

                    x_pos = layout.IndexToPos(System.Math.Max(0, (int)byteIndex)).X;

                    to = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
                }
                else
                {
                    @from = startXPos;
                    to    = startXPos + editor.TextViewMargin.CharWidth;
                }

                var line = editor.GetLineByOffset(endOffset);
                if (markerEnd > endOffset || @from == to)
                {
                    to += editor.TextViewMargin.CharWidth;
                    if (@from >= to)
                    {
                        @from = to - editor.TextViewMargin.CharWidth;
                    }
                }
            }
            @from = System.Math.Max(@from, editor.TextViewMargin.XOffset);
            to    = System.Math.Max(to, editor.TextViewMargin.XOffset);
            if (Length == 0)
            {
                to += editor.TextViewMargin.charWidth;
            }

            if (@from >= to)
            {
                return;
            }
            double height = editor.LineHeight / 5;

            if (string.IsNullOrEmpty(ColorName))
            {
                cr.SetSourceColor(Color);
            }
            else
            {
                HslColor color;
                editor.EditorTheme.TryGetColor(ColorName, out color);
                cr.SetSourceColor(color);
            }
            cr.LineWidth = editor.Options.Zoom;

            switch (Effect)
            {
            case MonoDevelop.Ide.Editor.TextSegmentMarkerEffect.WavedLine:
                cr.Rectangle(@from, 0, to - @from, editor.Allocation.Height);
                cr.Clip();
                Pango.CairoHelper.ShowErrorUnderline(cr, metrics.TextRenderStartPosition, y + editor.LineHeight - height, editor.Allocation.Width, height);
                cr.ResetClip();
                break;

            case MonoDevelop.Ide.Editor.TextSegmentMarkerEffect.DottedLine:
                cr.Save();
                cr.MoveTo(@from, y + editor.LineHeight - editor.Options.Zoom - 0.5);
                cr.LineTo(to, y + editor.LineHeight - editor.Options.Zoom - 0.5);
                cr.SetDash(new double [] { 2 * editor.Options.Zoom, 2 * editor.Options.Zoom }, 0);
                cr.Stroke();
                cr.Restore();
                break;

            case MonoDevelop.Ide.Editor.TextSegmentMarkerEffect.Underline:
                cr.MoveTo(@from, y + editor.LineHeight - editor.Options.Zoom - 0.5);
                cr.LineTo(to, y + editor.LineHeight - editor.Options.Zoom - 0.5);
                cr.Stroke();
                break;

            default:
                throw new InvalidOperationException("Invalid text segment marker effect " + Effect + " not supported by this marker.");
            }
        }
			public override void DrawBackground (MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, int startOffset, int endOffset)
			{
				try {
					double fromX, toX;
					GetLineDrawingPosition (metrics, startOffset, out fromX, out toX);

					fromX = Math.Max (fromX, editor.TextViewMargin.XOffset);
					toX = Math.Max (toX, editor.TextViewMargin.XOffset);
					if (fromX < toX) {
						var bracketMatch = new Cairo.Rectangle (fromX + 0.5, metrics.LineYRenderStartPosition + 0.5, toX - fromX - 1, editor.LineHeight - 2);
						if (editor.TextViewMargin.BackgroundRenderer == null) {
							cr.SetSourceColor (editor.ColorStyle.BraceMatchingRectangle.Color);
							cr.Rectangle (bracketMatch);
							cr.FillPreserve ();
							cr.SetSourceColor (editor.ColorStyle.BraceMatchingRectangle.SecondColor);
							cr.Stroke ();
						}
					}
				} catch (Exception e) {
					LoggingService.LogError ($"Error while drawing bracket matcher ({this}) startOffset={startOffset} lineCharLength={metrics.Layout.LineChars.Length}", e);
				}
			}
			public bool DrawBackground (TextEditor editor, Cairo.Context cr, double y, LineMetrics metrics, ref bool drawBg)
			{
				drawBg = false;
				if (metrics.SelectionStart >= 0 || editor.CurrentMode is TextLinkEditMode || editor.TextViewMargin.SearchResultMatchCount > 0)
					return true;
				foreach (var usage in Usages) {
					int markerStart = usage.Offset;
					int markerEnd = usage.EndOffset;
					
					if (markerEnd < metrics.TextStartOffset || markerStart > metrics.TextEndOffset) 
						return true; 
					
					double @from;
					double to;
					
					if (markerStart < metrics.TextStartOffset && metrics.TextEndOffset < markerEnd) {
						@from = metrics.TextRenderStartPosition;
						to = metrics.TextRenderEndPosition;
					} else {
						int start = metrics.TextStartOffset < markerStart ? markerStart : metrics.TextStartOffset;
						int end = metrics.TextEndOffset < markerEnd ? metrics.TextEndOffset : markerEnd;
						
						uint curIndex = 0, byteIndex = 0;
						TextViewMargin.TranslateToUTF8Index (metrics.Layout.LineChars, (uint)(start - metrics.TextStartOffset), ref curIndex, ref byteIndex);
						
						int x_pos = metrics.Layout.Layout.IndexToPos ((int)byteIndex).X;
						
						@from = metrics.TextRenderStartPosition + (int)(x_pos / Pango.Scale.PangoScale);
						
						TextViewMargin.TranslateToUTF8Index (metrics.Layout.LineChars, (uint)(end - metrics.TextStartOffset), ref curIndex, ref byteIndex);
						x_pos = metrics.Layout.Layout.IndexToPos ((int)byteIndex).X;
			
						to = metrics.TextRenderStartPosition + (int)(x_pos / Pango.Scale.PangoScale);
					}
		
					@from = System.Math.Max (@from, editor.TextViewMargin.XOffset);
					to = System.Math.Max (to, editor.TextViewMargin.XOffset);
					if (@from < to) {
						cr.Color = (HslColor)editor.ColorStyle.UsagesRectangle.SecondColor;
						cr.Rectangle (@from + 1, y + 1, to - @from - 1, editor.LineHeight - 2);
						cr.Fill ();
						
						cr.Color = (HslColor)editor.ColorStyle.UsagesRectangle.Color;
						cr.Rectangle (@from + 0.5, y + 0.5, to - @from, editor.LineHeight - 1);
						cr.Stroke ();
					}
				}
				return true;
			}