internal protected override void Draw(Gdk.Drawable win, Gdk.Rectangle area, long line, int x, int y) { int top = y; int bottom = top + this.Editor.LineHeight; bool isOdd = (top + (int)this.Data.VAdjustment.Value) % 2 != 0; win.DrawLine(isOdd? bgGC : bgGC2, x, top, x, bottom); win.DrawLine(isOdd? foldDashedLineGC : foldDashedLineGC2, x, top, x, bottom); }
internal protected override void Draw(Gdk.Drawable win, Gdk.Rectangle area, int line, int x, int y, int lineHeight) { win.DrawLine(UseBGColor ? bgGC : gc, x, y, x, y + lineHeight); // int top = y; // int bottom = top + lineHeight; // bool isOdd = (top + (int)editor.VAdjustment.Value) % 2 != 0; // win.DrawLine (isOdd? bgGC : bgGC2, x, top, x, bottom); // win.DrawLine (isOdd? foldDashedLineGC : foldDashedLineGC2, x, top, x, bottom); }
protected override bool OnExposeEvent(Gdk.EventExpose args) { Gdk.Drawable win = args.Window; int width, height; layout.GetPixelSize(out width, out height); int arrowHeight = height / 2; int arrowWidth = arrowHeight + 1; int arrowXPos = this.Allocation.X + this.Allocation.Width - arrowWidth; if (DrawRightBorder) { arrowXPos -= 2; } //HACK: don't ever draw insensitive, only active/prelight/normal, because insensitive generally looks really ugly //this *might* cause some theme issues with the state of the text/arrows rendering on top of it var state = window != null? StateType.Active : State == StateType.Insensitive? StateType.Normal : State; //HACK: paint the button background as if it were bigger, but it stays clipped to the real area, // so we get the content but not the border. This might break with crazy themes. //FIXME: we can't use the style's actual internal padding because GTK# hasn't wrapped GtkBorder AFAICT // (default-border, inner-border, default-outside-border, etc - see http://git.gnome.org/browse/gtk+/tree/gtk/gtkbutton.c) const int padding = 4; Style.PaintBox(Style, args.Window, state, ShadowType.None, args.Area, this, "button", Allocation.X - padding, Allocation.Y - padding, Allocation.Width + padding * 2, Allocation.Height + padding * 2); int xPos = Allocation.Left; if (Pixbuf != null) { win.DrawPixbuf(this.Style.BaseGC(StateType.Normal), Pixbuf, 0, 0, xPos + pixbufSpacing, Allocation.Y + (Allocation.Height - Pixbuf.Height) / 2, Pixbuf.Width, Pixbuf.Height, Gdk.RgbDither.None, 0, 0); xPos += Pixbuf.Width + pixbufSpacing * 2; } //constrain the text area so it doesn't get rendered under the arrows var textArea = new Gdk.Rectangle(xPos, Allocation.Y + ySpacing, arrowXPos - xPos - 2, Allocation.Height - ySpacing); Style.PaintLayout(Style, win, state, true, textArea, this, "", textArea.X, textArea.Y, layout); state = Sensitive ? StateType.Normal : StateType.Insensitive; Gtk.Style.PaintArrow(this.Style, win, state, ShadowType.None, args.Area, this, "", ArrowType.Up, true, arrowXPos, Allocation.Y + (Allocation.Height) / 2 - arrowHeight, arrowWidth, arrowHeight); Gtk.Style.PaintArrow(this.Style, win, state, ShadowType.None, args.Area, this, "", ArrowType.Down, true, arrowXPos, Allocation.Y + (Allocation.Height) / 2, arrowWidth, arrowHeight); if (DrawRightBorder) { win.DrawLine(this.Style.DarkGC(StateType.Normal), Allocation.X + Allocation.Width - 1, Allocation.Y, Allocation.X + Allocation.Width - 1, Allocation.Y + Allocation.Height); } return(false); }
void DrawFoldSegment(Gdk.Drawable win, int x, int y, bool isOpen, bool isSelected) { Gdk.Rectangle drawArea = new Gdk.Rectangle(x + (Width - foldSegmentSize) / 2, y + (editor.LineHeight - foldSegmentSize) / 2, foldSegmentSize, foldSegmentSize); win.DrawRectangle(foldBgGC, true, drawArea); win.DrawRectangle(isSelected ? foldLineHighlightedGC : foldLineGC, false, drawArea); win.DrawLine(foldToggleMarkerGC, drawArea.Left + drawArea.Width * 3 / 10, drawArea.Top + drawArea.Height / 2, drawArea.Right - drawArea.Width * 3 / 10, drawArea.Top + drawArea.Height / 2); if (!isOpen) { win.DrawLine(foldToggleMarkerGC, drawArea.Left + drawArea.Width / 2, drawArea.Top + drawArea.Height * 3 / 10, drawArea.Left + drawArea.Width / 2, drawArea.Bottom - drawArea.Height * 3 / 10); } }
internal protected override void Draw(Gdk.Drawable win, Gdk.Rectangle area, long line, int x, int y) { if (backgroundGC == null) { OptionsChanged(); } win.DrawRectangle(backgroundGC, true, x, y, Width, Editor.LineHeight); win.DrawLine(separatorGC, x + Width - 1, y, x + Width - 1, y + Editor.LineHeight); foreach (long bookmark in Data.Bookmarks) { if (line * Editor.BytesInRow <= bookmark && bookmark < line * Editor.BytesInRow + Editor.BytesInRow) { DrawBookmark(win, x, y); return; } } }
/* * void InternalDrawBackground (TextEditor Editor, Gdk.Drawable win, Pango.Layout layout, bool selected, int startOffset, int endOffset, int y, ref int startXPos, int endXPos, ref bool drawBg) * { * Gdk.Rectangle clipRectangle = new Gdk.Rectangle (mode.Editor.TextViewMargin.XOffset, 0, * Editor.Allocation.Width - mode.Editor.TextViewMargin.XOffset, Editor.Allocation.Height); * * // draw default background * using (Gdk.GC fillGc = new Gdk.GC (win)) { * fillGc.ClipRectangle = clipRectangle; * fillGc.RgbFgColor = selected ? Editor.ColorStyle.Selection.BackgroundColor : Editor.ColorStyle.Default.BackgroundColor; * win.DrawRectangle (fillGc, true, startXPos, y, endXPos, Editor.LineHeight); * } * * if (startOffset >= endOffset) * return; * * int caretOffset = Editor.Caret.Offset - BaseOffset; * foreach (TextLink link in mode.Links) { * if (!link.IsEditable) * continue; * bool isPrimaryHighlighted = link.PrimaryLink.Offset <= caretOffset && caretOffset <= link.PrimaryLink.EndOffset; * * foreach (ISegment segment in link.Links) { * * if ((BaseOffset + segment.Offset <= startOffset && startOffset < BaseOffset + segment.EndOffset) || * (startOffset <= BaseOffset + segment.Offset && BaseOffset + segment.Offset < endOffset)) { * int strOffset = BaseOffset + segment.Offset - startOffset; * int strEndOffset = BaseOffset + segment.EndOffset - startOffset; * * int lineNr, x_pos, x_pos2; * layout.IndexToLineX (strOffset, false, out lineNr, out x_pos); * layout.IndexToLineX (strEndOffset, false, out lineNr, out x_pos2); * x_pos = (int)(x_pos / Pango.Scale.PangoScale); * x_pos2 = (int)(x_pos2 / Pango.Scale.PangoScale); * using (Gdk.GC rectangleGc = new Gdk.GC (win)) { * rectangleGc.ClipRectangle = clipRectangle; * using (Gdk.GC fillGc = new Gdk.GC (win)) { * fillGc.ClipRectangle = clipRectangle; * drawBg = false; * * if (segment == link.PrimaryLink) { * fillGc.RgbFgColor = isPrimaryHighlighted ? Editor.ColorStyle.PrimaryTemplateHighlighted.BackgroundColor : Editor.ColorStyle.PrimaryTemplate.BackgroundColor; * rectangleGc.RgbFgColor = isPrimaryHighlighted ? Editor.ColorStyle.PrimaryTemplateHighlighted.Color : Editor.ColorStyle.PrimaryTemplate.Color; * } else { * fillGc.RgbFgColor = isPrimaryHighlighted ? Editor.ColorStyle.SecondaryTemplateHighlighted.BackgroundColor : Editor.ColorStyle.SecondaryTemplate.BackgroundColor; * rectangleGc.RgbFgColor = isPrimaryHighlighted ? Editor.ColorStyle.SecondaryTemplateHighlighted.Color : Editor.ColorStyle.SecondaryTemplate.Color; * } * // Draw segment * if (!selected) * win.DrawRectangle (fillGc, true, startXPos, y, x_pos2 - x_pos, Editor.LineHeight); * * int x1 = startXPos + x_pos - 1; * int x2 = startXPos + x_pos2 - 1; * int y2 = y + Editor.LineHeight - 1; * * win.DrawLine (rectangleGc, x1, y, x2, y); * win.DrawLine (rectangleGc, x1, y2, x2, y2); * win.DrawLine (rectangleGc, x1, y, x1, y2); * win.DrawLine (rectangleGc, x2, y, x2, y2); * } * } * } * } * } * startXPos += Editor.GetWidth (Editor.Document.GetTextBetween (startOffset, endOffset)); * } */ /* bool Overlaps (ISegment segment, int start, int end) * { * return segment.Offset <= start && start < segment.EndOffset || * segment.Offset <= end && end < segment.EndOffset || * start <= segment.Offset && segment.Offset < end || * start < segment.EndOffset && segment.EndOffset < end; * }*/ public bool DrawBackground(TextEditor Editor, Gdk.Drawable win, TextViewMargin.LayoutWrapper layout, int selectionStart, int selectionEnd, int startOffset, int endOffset, int y, int startXPos, int endXPos, ref bool drawBg) { int caretOffset = Editor.Caret.Offset - BaseOffset; foreach (TextLink link in mode.Links) { if (!link.IsEditable) { continue; } bool isPrimaryHighlighted = link.PrimaryLink.Offset <= caretOffset && caretOffset <= link.PrimaryLink.EndOffset; foreach (ISegment segment in link.Links) { if ((BaseOffset + segment.Offset <= startOffset && startOffset < BaseOffset + segment.EndOffset) || (startOffset <= BaseOffset + segment.Offset && BaseOffset + segment.Offset < endOffset)) { int strOffset = BaseOffset + segment.Offset - startOffset; int strEndOffset = BaseOffset + segment.EndOffset - startOffset; int x_pos = layout.Layout.IndexToPos(strOffset).X; int x_pos2 = layout.Layout.IndexToPos(strEndOffset).X; x_pos = (int)(x_pos / Pango.Scale.PangoScale); x_pos2 = (int)(x_pos2 / Pango.Scale.PangoScale); using (Gdk.GC rectangleGc = new Gdk.GC(win)) { // rectangleGc.ClipRectangle = clipRectangle; using (Gdk.GC fillGc = new Gdk.GC(win)) { // fillGc.ClipRectangle = clipRectangle; drawBg = false; if (segment == link.PrimaryLink) { fillGc.RgbFgColor = isPrimaryHighlighted ? Editor.ColorStyle.PrimaryTemplateHighlighted.BackgroundColor : Editor.ColorStyle.PrimaryTemplate.BackgroundColor; rectangleGc.RgbFgColor = isPrimaryHighlighted ? Editor.ColorStyle.PrimaryTemplateHighlighted.Color : Editor.ColorStyle.PrimaryTemplate.Color; } else { fillGc.RgbFgColor = isPrimaryHighlighted ? Editor.ColorStyle.SecondaryTemplateHighlighted.BackgroundColor : Editor.ColorStyle.SecondaryTemplate.BackgroundColor; rectangleGc.RgbFgColor = isPrimaryHighlighted ? Editor.ColorStyle.SecondaryTemplateHighlighted.Color : Editor.ColorStyle.SecondaryTemplate.Color; } // Draw segment int x1 = startXPos + x_pos - 1; int x2 = startXPos + x_pos2 - 1; int y2 = y + Editor.LineHeight - 1; if (selectionStart < 0) { // Console.WriteLine ("Draw BG at " + y + "//" + Editor.GetTextEditorData ().VAdjustment.Value); // Console.WriteLine (Environment.StackTrace); win.DrawRectangle(fillGc, true, x1, y, x2 - x1, Editor.LineHeight); } win.DrawLine(rectangleGc, x1, y, x2, y); win.DrawLine(rectangleGc, x1, y2, x2, y2); win.DrawLine(rectangleGc, x1, y, x1, y2); win.DrawLine(rectangleGc, x2, y, x2, y2); } } } } } /* * int curOffset = startOffset; * foreach (TextLink link in mode.Links) { * if (!link.IsEditable) * continue; * ISegment segment = link.Links.Where (s => Overlaps (s, curOffset - BaseOffset, endOffset - BaseOffset)).FirstOrDefault (); * if (segment == null) { * break; * } * InternalDrawBackground (Editor, win, layout, selected, curOffset, segment.Offset + BaseOffset, y, ref startXPos, endXPos, ref drawBg); * curOffset = segment.EndOffset + BaseOffset; * InternalDrawBackground (Editor, win, layout, selected, segment.Offset + BaseOffset, curOffset, y, ref startXPos, endXPos, ref drawBg); * } * InternalDrawBackground (Editor, win, layout, selected, curOffset, endOffset, y, ref startXPos, endXPos, ref drawBg); */ return(true); }
internal protected override void Draw(Gdk.Drawable win, Gdk.Rectangle area, int line, int x, int y, int lineHeight) { foldSegmentSize = Width * 4 / 6; foldSegmentSize -= (foldSegmentSize) % 2; Gdk.Rectangle drawArea = new Gdk.Rectangle(x, y, Width, lineHeight); Document.LineState state = editor.Document.GetLineState(line); bool isFoldStart = false; bool isContaining = false; bool isFoldEnd = false; bool isStartSelected = false; bool isContainingSelected = false; bool isEndSelected = false; if (line < editor.Document.LineCount) { LineSegment lineSegment = editor.Document.GetLine(line); startFoldings.Clear(); containingFoldings.Clear(); endFoldings.Clear(); foreach (FoldSegment segment in editor.Document.GetFoldingContaining(lineSegment)) { if (segment.StartLine.Offset == lineSegment.Offset) { startFoldings.Add(segment); } else if (segment.EndLine.Offset == lineSegment.Offset) { endFoldings.Add(segment); } else { containingFoldings.Add(segment); } } isFoldStart = startFoldings.Count > 0; isContaining = containingFoldings.Count > 0; isFoldEnd = endFoldings.Count > 0; isStartSelected = this.lineHover != null && IsMouseHover(startFoldings); isContainingSelected = this.lineHover != null && IsMouseHover(containingFoldings); isEndSelected = this.lineHover != null && IsMouseHover(endFoldings); } Gdk.GC bgGC = foldBgGC; if (editor.TextViewMargin.BackgroundRenderer != null) { if (isContainingSelected || isStartSelected || isEndSelected) { bgGC = foldBgGC; } else { bgGC = foldLineHighlightedGCBg; } } win.DrawRectangle(bgGC, true, drawArea); if (state == Document.LineState.Changed) { win.DrawRectangle(lineStateChangedGC, true, x + 1, y, Width / 3, lineHeight); // win.DrawRectangle (bgGC, true, x + 3 , y, Width - 3, lineHeight); } else if (state == Document.LineState.Dirty) { win.DrawRectangle(lineStateDirtyGC, true, x + 1, y, Width / 3, lineHeight); // win.DrawRectangle (bgGC, true, x + 3 , y, Width - 3, lineHeight); } /* else { * win.DrawRectangle (bgGC, true, drawArea); * }*/ if (line < editor.Document.LineCount) { int foldSegmentYPos = y + (editor.LineHeight - foldSegmentSize) / 2; int xPos = x + Width / 2; if (isFoldStart) { bool isVisible = true; bool moreLinedOpenFold = false; foreach (FoldSegment foldSegment in startFoldings) { if (foldSegment.IsFolded) { isVisible = false; } else { moreLinedOpenFold = foldSegment.EndLine.Offset > foldSegment.StartLine.Offset; } } bool isFoldEndFromUpperFold = false; foreach (FoldSegment foldSegment in endFoldings) { if (foldSegment.EndLine.Offset > foldSegment.StartLine.Offset && !foldSegment.IsFolded) { isFoldEndFromUpperFold = true; } } DrawFoldSegment(win, x, y, isVisible, isStartSelected); if (isContaining || isFoldEndFromUpperFold) { win.DrawLine(isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, drawArea.Top, xPos, foldSegmentYPos - 2); } if (isContaining || moreLinedOpenFold) { win.DrawLine(isEndSelected || (isStartSelected && isVisible) || isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, foldSegmentYPos + foldSegmentSize + 2, xPos, drawArea.Bottom); } } else { if (isFoldEnd) { int yMid = drawArea.Top + drawArea.Height / 2; win.DrawLine(isEndSelected ? foldLineHighlightedGC : foldLineGC, xPos, yMid, x + Width - 2, yMid); win.DrawLine(isContainingSelected || isEndSelected ? foldLineHighlightedGC : foldLineGC, xPos, drawArea.Top, xPos, yMid); if (isContaining) { win.DrawLine(isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, yMid + 1, xPos, drawArea.Bottom); } } else if (isContaining) { win.DrawLine(isContainingSelected ? foldLineHighlightedGC : foldLineGC, xPos, drawArea.Top, xPos, drawArea.Bottom); } } } }