HslColor GetColor (int i, double brightness, int colorCount) { HslColor hslColor = new HslColor (editor.ColorStyle.PlainText.Background); int colorPosition = i + 1; if (i == foldSegments.Count - 1) return hslColor; if (brightness < 0.5) { hslColor.L = hslColor.L * 0.81 + hslColor.L * 0.25 * (colorCount - colorPosition) / colorCount; } else { hslColor.L = hslColor.L * 0.86 + hslColor.L * 0.1 * colorPosition / colorCount; } return hslColor; }
static Color AdjustColor(Color baseColor, Color color) { double b1 = Mono.TextEditor.HslColor.Brightness(color); double b2 = Mono.TextEditor.HslColor.Brightness(baseColor); double delta = Math.Abs(b1 - b2); if (delta < 0.1) { Mono.TextEditor.HslColor color1 = color; color1.L -= 0.5; if (Math.Abs(Mono.TextEditor.HslColor.Brightness(color1) - b2) < delta) { color1 = color; color1.L += 0.5; } return(color1); } return(color); }
public static List<HslColor> GenerateHighlightColors (HslColor backGround, HslColor foreGround, int n) { double bgH = (backGround.H == 0 && backGround.S == 0) ? 2 / 3.0 : backGround.H; var result = new List<HslColor> (); for (int i = 0; i < n; i++) { double h = bgH + (i + 1.0) / (double)n; // for monochromatic backround the h value doesn't matter if (i + 1 == n && !(backGround.H == 0 && backGround.S == 0)) h = bgH + 0.5; if (h > 1.0) h -= 1.0; double s = 0.85; double l = 0.5; if (backGround.H == 0 && backGround.S == 0 && backGround.L < 0.5) l = 0.8; result.Add (Mono.TextEditor.HslColor.FromHsl (h, s, l)); } return result; }
public static double Brightness (HslColor c) { return Brightness ((Cairo.Color)c); }
internal protected override void OptionsChanged () { foldBgGC = editor.ColorStyle.PlainText.Background; foldLineGC = editor.ColorStyle.FoldLineColor.Color; foldLineHighlightedGC = editor.ColorStyle.PlainText.Foreground; HslColor hslColor = new HslColor (editor.ColorStyle.PlainText.Background); double brightness = HslColor.Brightness (hslColor); if (brightness < 0.5) { hslColor.L = hslColor.L * 0.85 + hslColor.L * 0.25; } else { hslColor.L = hslColor.L * 0.9; } foldLineHighlightedGCBg = hslColor; foldToggleMarkerGC = editor.ColorStyle.FoldCross.Color; foldToggleMarkerBackground = editor.ColorStyle.FoldCross.SecondColor; lineStateChangedGC = editor.ColorStyle.QuickDiffChanged.Color; lineStateDirtyGC = editor.ColorStyle.QuickDiffDirty.Color; marginWidth = editor.LineHeight; }
protected override bool OnExposeEvent(Gdk.EventExpose evnt) { using (var cr = Gdk.CairoHelper.Create(evnt.Window)) { cr.SetSourceRGBA(1, 1, 1, 0); cr.Operator = Cairo.Operator.Source; cr.Paint(); } using (var cr = Gdk.CairoHelper.Create(evnt.Window)) { cr.Translate(width / 2, height / 2); cr.Scale(1 + scale / 8, 1 + scale / 8); int x = -(marker.ErrorTextBounds.Width) / 2; int y = -marker.ErrorTextBounds.Height / 2; if (marker.FitsInSameLine) { cr.MoveTo(x + Editor.LineHeight / 2, y); cr.LineTo(x, 0); cr.LineTo(x + Editor.LineHeight / 2, marker.ErrorTextBounds.Height / 2); } else { cr.MoveTo(x, -marker.ErrorTextBounds.Height / 2); cr.LineTo(x, marker.ErrorTextBounds.Height / 2); } cr.LineTo(x + marker.ErrorTextBounds.Width, marker.ErrorTextBounds.Height / 2); cr.LineTo(x + marker.ErrorTextBounds.Width, y); cr.ClosePath(); Mono.TextEditor.HslColor hsl = marker.colorMatrix [0, 0, 0, 0, 0]; double delta = 1 + 2 - scale; hsl.S += delta; var color = (Cairo.Color)hsl; color.A = opacity; cr.Color = color; cr.FillPreserve(); color = marker.colorMatrix [0, 0, 2, 0, 0]; color.A = opacity; cr.Color = color; cr.Stroke(); int errorCounterWidth = 0; if (marker.Errors.Count > 1) { double rY = y + Editor.LineHeight / 6; int ew, eh; marker.errorCountLayout.GetPixelSize(out ew, out eh); errorCounterWidth = ew + 10; int rX = x + marker.ErrorTextBounds.Width - errorCounterWidth; int rW = errorCounterWidth - 2; double rH = Editor.LineHeight * 3 / 4; BookmarkMarker.DrawRoundRectangle(cr, rX, rY, 8, rW, rH); cr.Color = new Cairo.Color(0.5, 0.5, 0.5); cr.Fill(); cr.MoveTo(rX + rW / 2 - rW / 4, rY + rH - rH / 4); cr.LineTo(rX + rW / 2 + rW / 4, rY + rH - rH / 4); cr.LineTo(rX + rW / 2, rY + rH / 4); cr.ClosePath(); cr.Color = new Cairo.Color(1, 1, 1); cr.Fill(); } cr.Color = new Cairo.Color(0, 0, 0); marker.EnsureLayoutCreated(base.Editor); int layoutWidth, layoutHeight; marker.Layouts [0].Layout.GetPixelSize(out layoutWidth, out layoutHeight); double ly; if (marker.CollapseExtendedErrors || marker.Errors.Count == 1) { ly = 1 + y + (marker.ErrorTextBounds.Height - layoutHeight) / 2; double x2 = x + MessageBubbleTextMarker.border; if (marker.FitsInSameLine) { x2 += 1 + Editor.LineHeight / 2; } cr.Translate(x2, ly); cr.ShowLayout(marker.Layouts [0].Layout); } else { ly = 1 + y + (Editor.LineHeight - layoutHeight) / 2; for (int i = 0; i < marker.Errors.Count; i++) { marker.Layouts [i].Layout.GetPixelSize(out layoutWidth, out layoutHeight); cr.Save(); double x2; if (i == 0) { x2 = x + marker.ErrorTextBounds.Width - layoutWidth - errorCounterWidth; } else { x2 = x + MessageBubbleTextMarker.border; } if (marker.FitsInSameLine) { x2 += Editor.LineHeight / 2; } cr.Translate(x2, ly); cr.ShowLayout(marker.Layouts [i].Layout); cr.Restore(); ly += Editor.LineHeight; } } } return(false); }
void DrawValue(Cairo.Context ctx, Gdk.GC gc, DateTime initialTime, int ytop, int lx, int tx, ref int ty, ref int maxx, ref int maxy, int indent, CounterValueInfo val) { Gdk.Color color; if (val.Counter != null) { color = val.Counter.GetColor(); } else { color = Style.Black; } // Draw text gc.RgbFgColor = color; double ms = (val.Time - initialTime).TotalMilliseconds; string txt = (ms / 1000).ToString("0.00000") + ": " + (val.Duration.TotalMilliseconds / 1000).ToString("0.00000") + " " + val.Trace; layout.SetText(txt); GdkWindow.DrawLayout(gc, tx + indent, ty, layout); int tw, th; layout.GetPixelSize(out tw, out th); if (tx + tw + indent > maxx) { maxx = tx + tw + indent; } HotSpot hp = AddHotSpot(tx + indent, ty, tw, th); int tempTy = ty; hp.Action = delegate { int ytm = ytop + (int)((ms * scale) / 1000); SetBaseTime((int)(tempTy + (th / 2) + 0.5) - ytm); }; hp.OnMouseOver += delegate { overValue = val; QueueDraw(); }; hp.Action += delegate { focusedValue = val; QueueDraw(); }; // Draw time marker int ytime = ytop + (int)((ms * scale) / 1000) + baseTime; if (val == focusedValue || val == overValue) { ctx.NewPath(); double dx = val == focusedValue ? 0 : 2; ctx.Rectangle(lx + 0.5 + dx - SelectedValuePadding, ytime + 0.5, LineEndWidth - dx * 2 + SelectedValuePadding, ((val.Duration.TotalMilliseconds * scale) / 1000)); Mono.TextEditor.HslColor hsl = color; hsl.L = val == focusedValue ? 0.9 : 0.8; ctx.SetSourceColor(hsl); ctx.Fill(); } ctx.NewPath(); ctx.LineWidth = 1; ctx.MoveTo(lx + 0.5, ytime + 0.5); ctx.LineTo(lx + LineEndWidth + 0.5, ytime + 0.5); ctx.LineTo(tx - 3 - LineEndWidth + 0.5, ty + (th / 2) + 0.5); ctx.LineTo(tx + indent - 3 + 0.5, ty + (th / 2) + 0.5); ctx.SetSourceColor(color.ToCairoColor()); ctx.Stroke(); // Expander bool incLine = true; if (val.CanExpand) { double ex = tx + indent - 3 - ExpanderSize - 2 + 0.5; double ey = ty + (th / 2) - (ExpanderSize / 2) + 0.5; hp = AddHotSpot(ex, ey, ExpanderSize, ExpanderSize); DrawExpander(ctx, ex, ey, val.Expanded, false); hp.OnMouseOver = delegate { using (Cairo.Context c = CairoHelper.Create(GdkWindow)) { DrawExpander(c, ex, ey, val.Expanded, true); } }; hp.OnMouseLeave = delegate { using (Cairo.Context c = CairoHelper.Create(GdkWindow)) { DrawExpander(c, ex, ey, val.Expanded, false); } }; hp.Action = delegate { ToggleExpand(val); }; if (val.Expanded && val.ExpandedTimerTraces.Count > 0) { ty += th + LineSpacing; foreach (CounterValueInfo cv in val.ExpandedTimerTraces) { DrawValue(ctx, gc, initialTime, ytop, lx, tx, ref ty, ref maxx, ref maxy, indent + ChildIndent, cv); } incLine = false; } } if (incLine) { ty += th + LineSpacing; } if (ytime > maxy) { maxy = ytime; } }
public void Draw(Cairo.Context cr, Cairo.Rectangle area) { TextViewMargin textViewMargin = editor.TextViewMargin; ISyntaxMode mode = Document.SyntaxMode != null && editor.Options.EnableSyntaxHighlighting ? Document.SyntaxMode : new SyntaxMode(Document); TextViewMargin.LayoutWrapper lineLayout = null; double brightness = HslColor.Brightness(editor.ColorStyle.PlainText.Background); int colorCount = foldSegments.Count + 2; cr.Color = GetColor(-1, brightness, colorCount); cr.Rectangle(area); cr.Fill(); var rectangles = new Cairo.Rectangle[foldSegments.Count]; const int xPadding = 4; const int yPadding = 2; const int rightMarginPadding = 16; for (int i = foldSegments.Count - 1; i >= 0; i--) { var segment = foldSegments [i]; var segmentStartLine = segment.StartLine; var segmentEndLine = segment.EndLine; int curWidth = 0; var endLine = segmentEndLine.NextLine; var y = editor.LineToY(segmentStartLine.LineNumber); for (var curLine = segmentStartLine; curLine != endLine && y < editor.VAdjustment.Value + editor.Allocation.Height; curLine = curLine.NextLine) { var curLayout = textViewMargin.CreateLinePartLayout(mode, curLine, curLine.Offset, curLine.Length, -1, -1); var width = (int)(curLayout.PangoWidth / Pango.Scale.PangoScale); curWidth = System.Math.Max(curWidth, width); y += editor.GetLineHeight(curLine); } double xPos = textViewMargin.XOffset; double rectangleWidth = 0, rectangleHeight = 0; lineLayout = textViewMargin.CreateLinePartLayout(mode, segmentStartLine, segmentStartLine.Offset, segmentStartLine.Length, -1, -1); var rectangleStart = lineLayout.Layout.IndexToPos(GetFirstNonWsIdx(lineLayout.Layout.Text)); xPos = System.Math.Max(textViewMargin.XOffset, (textViewMargin.XOffset + textViewMargin.TextStartPosition + rectangleStart.X / Pango.Scale.PangoScale) - xPadding); lineLayout = textViewMargin.CreateLinePartLayout(mode, segmentEndLine, segmentEndLine.Offset, segmentEndLine.Length, -1, -1); var rectangleEnd = lineLayout.Layout.IndexToPos(GetFirstNonWsIdx(lineLayout.Layout.Text)); xPos = System.Math.Min(xPos, System.Math.Max(textViewMargin.XOffset, (textViewMargin.XOffset + textViewMargin.TextStartPosition + rectangleEnd.X / Pango.Scale.PangoScale) - xPadding)); rectangleWidth = textViewMargin.XOffset + textViewMargin.TextStartPosition + curWidth - xPos + xPadding * 2; if (i < foldSegments.Count - 1) { rectangleWidth = System.Math.Max((rectangles [i + 1].X + rectangles[i + 1].Width + rightMarginPadding) - xPos, rectangleWidth); } y = editor.LineToY(segment.StartLine.LineNumber); var yEnd = editor.LineToY(segment.EndLine.LineNumber + 1); if (yEnd == 0) { yEnd = editor.VAdjustment.Upper; } rectangleHeight = yEnd - y; rectangles[i] = new Cairo.Rectangle(xPos, y - yPadding, rectangleWidth, rectangleHeight + yPadding * 2); } for (int i = 0; i < foldSegments.Count; i++) { var rect = rectangles[i]; if (i == foldSegments.Count - 1) { /* var radius = (int)(editor.Options.Zoom * 2); * int w = 2 * radius; * using (var shadow = new Blur ( * System.Math.Min ((int)rect.Width + w * 2, editor.Allocation.Width), * System.Math.Min ((int)rect.Height + w * 2, editor.Allocation.Height), * radius)) { * using (var gctx = shadow.GetContext ()) { * gctx.Color = new Cairo.Color (0, 0, 0, 0); * gctx.Fill (); * * var a = 0; * var b = 0; * DrawRoundRectangle (gctx, true, true, w - a, w - b, editor.LineHeight / 4, rect.Width + a * 2, rect.Height + a * 2); * var bg = editor.ColorStyle.Default.CairoColor; * gctx.Color = new Cairo.Color (bg.R, bg.G, bg.B, 0.6); * gctx.Fill (); * } * * cr.Save (); * cr.Translate (rect.X - w - editor.HAdjustment.Value, rect.Y - editor.VAdjustment.Value - w); * shadow.Draw (cr); * cr.Restore (); * }*/ var curPadSize = 1; var age = (DateTime.Now - startTime).TotalMilliseconds; var alpha = 0.1; if (age < animationLength) { var animationState = age / (double)animationLength; curPadSize = (int)(3 + System.Math.Sin(System.Math.PI * animationState) * 3); alpha = 0.1 + (1.0 - animationState) / 5; } var bg = editor.ColorStyle.PlainText.Foreground; cr.Color = new Cairo.Color(bg.R, bg.G, bg.B, alpha); DrawRoundRectangle(cr, true, true, rect.X - editor.HAdjustment.Value - curPadSize, rect.Y - editor.VAdjustment.Value - curPadSize, editor.LineHeight / 2, rect.Width + curPadSize * 2, rect.Height + curPadSize * 2); cr.Fill(); if (age < animationLength) { var animationState = age / (double)animationLength; curPadSize = (int)(2 + System.Math.Sin(System.Math.PI * animationState) * 2); DrawRoundRectangle(cr, true, true, rect.X - editor.HAdjustment.Value - curPadSize, rect.Y - editor.VAdjustment.Value - curPadSize, editor.LineHeight / 2, rect.Width + curPadSize * 2, rect.Height + curPadSize * 2); cr.Color = GetColor(i, brightness, colorCount); cr.Fill(); continue; } } DrawRoundRectangle(cr, true, true, rect.X - editor.HAdjustment.Value, rect.Y - editor.VAdjustment.Value, editor.LineHeight / 2, rect.Width, rect.Height); cr.Color = GetColor(i, brightness, colorCount); cr.Fill(); } }
void ResultTextDataFunc(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) { if (TreeIter.Zero.Equals(iter)) { return; } var textRenderer = (CellRendererText)cell; var searchResult = (SearchResult)store.GetValue(iter, SearchResultColumn); if (searchResult == null || searchResult.Offset < 0) { textRenderer.Markup = "Invalid search result"; return; } string textMarkup = searchResult.TextMarkup; if (textMarkup == null) { var doc = GetDocument(searchResult); if (doc == null) { textMarkup = "Can't create document for:" + searchResult.FileName; goto end; } bool isSelected = treeviewSearchResults.Selection.IterIsSelected(iter); if (searchResult.Markup == null) { if (searchResult.LineNumber <= 0) { searchResult.LineNumber = doc.OffsetToLineNumber(searchResult.Offset); } DocumentLine line = doc.GetLine(searchResult.LineNumber); if (line == null) { textMarkup = "Invalid line number " + searchResult.LineNumber + " from offset: " + searchResult.Offset; goto end; } int indent = line.GetIndentation(doc).Length; var data = new Mono.TextEditor.TextEditorData(doc); data.ColorStyle = highlightStyle; var lineText = doc.GetTextAt(line.Offset + indent, line.Length - indent); int col = searchResult.Offset - line.Offset - indent; // search result contained part of the indent. if (col + searchResult.Length < lineText.Length) { lineText = doc.GetTextAt(line.Offset, line.Length); } var markup = doc.SyntaxMode != null? data.GetMarkup(line.Offset + indent, line.Length - indent, true, !isSelected, false) : GLib.Markup.EscapeText(lineText); searchResult.Markup = AdjustColors(markup.Replace("\t", new string (' ', TextEditorOptions.DefaultOptions.TabSize))); if (col >= 0) { uint start; uint end; try { start = (uint)TextViewMargin.TranslateIndexToUTF8(lineText, col); end = (uint)TextViewMargin.TranslateIndexToUTF8(lineText, Math.Min(lineText.Length, col + searchResult.Length)); } catch (Exception e) { LoggingService.LogError("Exception while translating index to utf8 (column was:" + col + " search result length:" + searchResult.Length + " line text:" + lineText + ")", e); return; } searchResult.StartIndex = start; searchResult.EndIndex = end; } } try { textMarkup = searchResult.Markup; if (!isSelected) { var searchColor = searchResult.GetBackgroundMarkerColor(highlightStyle).Color; double b1 = Mono.TextEditor.HslColor.Brightness(searchColor); double b2 = Mono.TextEditor.HslColor.Brightness(AdjustColor(Style.Base(StateType.Normal), (Mono.TextEditor.HslColor)highlightStyle.PlainText.Foreground)); double delta = Math.Abs(b1 - b2); if (delta < 0.1) { Mono.TextEditor.HslColor color1 = highlightStyle.SearchResult.Color; if (color1.L + 0.5 > 1.0) { color1.L -= 0.5; } else { color1.L += 0.5; } searchColor = color1; } if (searchResult.StartIndex != searchResult.EndIndex) { var markupBuilder = new StringBuilder(); bool inMarkup = false, inEntity = false, closed = false; int i = 0; for (int j = 0; j < textMarkup.Length; j++) { var ch = textMarkup [j]; if (inEntity) { if (ch == ';') { inEntity = false; } markupBuilder.Append(ch); continue; } if (inMarkup) { if (ch == '>') { inMarkup = false; } markupBuilder.Append(ch); continue; } if (i == searchResult.EndIndex) { markupBuilder.Append("</span>"); markupBuilder.Append(textMarkup.Substring(j)); closed = true; break; } if (ch == '&') { inEntity = true; markupBuilder.Append(ch); continue; } if (ch == '<') { inMarkup = true; markupBuilder.Append(ch); continue; } if (i == searchResult.StartIndex) { markupBuilder.Append("<span background=\"" + ColorToPangoMarkup((HslColor)searchColor) + "\">"); } markupBuilder.Append(ch); i++; } if (!closed) { markupBuilder.Append("</span>"); } textMarkup = markupBuilder.ToString(); } } } catch (Exception e) { LoggingService.LogError("Error whil setting the text renderer markup to: " + searchResult.Markup, e); } end: searchResult.TextMarkup = textMarkup; } textRenderer.Markup = textMarkup; }
public void Draw (Cairo.Context cr, Cairo.Rectangle area, LineSegment lineSegment, double x, double y, double lineHeight) { int foundSegment = -1; if (lineSegment != null) { for (int i = 0; i < foldSegments.Count; i++) { FoldSegment segment = foldSegments[i]; if (segment.StartLine.Offset <= lineSegment.Offset && lineSegment.EndOffset <= segment.EndLine.EndOffset) { foundSegment = i; roles[i] = Roles.Between; if (segment.StartLine.Offset == lineSegment.Offset) { roles[i] |= Roles.Start; if (segment.IsFolded) roles[i] |= Roles.End; } if (segment.EndLine.Offset == lineSegment.Offset) roles[i] |= Roles.End; } } } TextViewMargin textViewMargin = editor.TextViewMargin; SyntaxMode mode = Document.SyntaxMode != null && editor.Options.EnableSyntaxHighlighting ? Document.SyntaxMode : SyntaxMode.Default; // Gdk.Rectangle lineArea = new Gdk.Rectangle (textViewMargin.XOffset, y, editor.Allocation.Width - textViewMargin.XOffset, editor.LineHeight); // Gdk.GC gc = new Gdk.GC (drawable); TextViewMargin.LayoutWrapper lineLayout = null; double brightness = HslColor.Brightness (editor.ColorStyle.Default.BackgroundColor); int colorCount = foldSegments.Count + 2; for (int segment = -1; segment <= foundSegment; segment++) { HslColor hslColor = new HslColor (editor.ColorStyle.Default.BackgroundColor); int colorPosition = segment + 1; if (segment == foldSegments.Count - 1) colorPosition += 2; if (brightness < 0.5) { hslColor.L = hslColor.L * 0.85 + hslColor.L * 0.25 * (colorCount - colorPosition) / colorCount; } else { hslColor.L = hslColor.L * 0.9 + hslColor.L * 0.1 * colorPosition / colorCount; } Roles role = Roles.Between; double xPos = textViewMargin.XOffset; double rectangleWidth = editor.Allocation.Width - xPos; if (segment >= 0) { LineSegment segmentStartLine = foldSegments[segment].StartLine; lineLayout = textViewMargin.CreateLinePartLayout (mode, segmentStartLine, segmentStartLine.Offset, segmentStartLine.EditableLength, -1, -1); Pango.Rectangle rectangle = lineLayout.Layout.IndexToPos (GetFirstNonWsIdx (lineLayout.Layout.Text)); xPos = System.Math.Max (textViewMargin.XOffset, (textViewMargin.XOffset + rectangle.X / Pango.Scale.PangoScale - editor.HAdjustment.Value)); LineSegment segmentEndLine = foldSegments[segment].EndLine; lineLayout = textViewMargin.CreateLinePartLayout (mode, segmentEndLine, segmentEndLine.Offset, segmentEndLine.EditableLength, -1, -1); rectangle = lineLayout.Layout.IndexToPos (GetFirstNonWsIdx (lineLayout.Layout.Text)); xPos = System.Math.Min (xPos ,System.Math.Max (textViewMargin.XOffset, (textViewMargin.XOffset + rectangle.X / Pango.Scale.PangoScale - editor.HAdjustment.Value))); int width = editor.Allocation.Width; if (editor.HAdjustment.Upper > width) { width = (int)(textViewMargin.XOffset + editor.HAdjustment.Upper - editor.HAdjustment.Value); } rectangleWidth = (int)(width - xPos - 6 * (segment + 1)); role = roles[segment]; } DrawRoundRectangle (cr, (role & Roles.Start) == Roles.Start, (role & Roles.End) == Roles.End, xPos, y, editor.LineHeight / 2, rectangleWidth, lineHeight); cr.Color = Style.ToCairoColor (hslColor); cr.Fill (); /* if (segment == foldSegments.Count - 1) { cr.Color = new Cairo.Color (0.5, 0.5, 0.5, 1); cr.Stroke (); }*/ if (lineLayout != null && lineLayout.IsUncached) { lineLayout.Dispose (); lineLayout = null; } } // gc.Dispose (); }
internal protected override void OptionsChanged () { foldBgGC = editor.ColorStyle.FoldLine.CairoBackgroundColor; foldLineGC = editor.ColorStyle.FoldLine.CairoColor; foldLineHighlightedGC = editor.ColorStyle.FoldLineHighlighted; HslColor hslColor = new HslColor (editor.ColorStyle.Default.CairoBackgroundColor); double brightness = HslColor.Brightness (hslColor); if (brightness < 0.5) { hslColor.L = hslColor.L * 0.85 + hslColor.L * 0.25; } else { hslColor.L = hslColor.L * 0.9; } foldLineHighlightedGCBg = hslColor; foldToggleMarkerGC = editor.ColorStyle.FoldToggleMarker; lineStateChangedGC = editor.ColorStyle.LineChangedBg; lineStateDirtyGC = editor.ColorStyle.LineDirtyBg; marginWidth = editor.LineHeight; }
// void ResultLineDataFunc (TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) // { // if (TreeIter.Zero.Equals (iter)) // return; // var lineRenderer = (CellRendererText)cell; // var searchResult = (SearchResult)store.GetValue (iter, SearchResultColumn); // if (searchResult == null) // return; // // Document doc = GetDocument (searchResult); // int lineNr = doc.OffsetToLineNumber (searchResult.Offset) + 1; // bool didRead = (bool)store.GetValue (iter, DidReadColumn); // lineRenderer.Markup = MarkupText (lineNr.ToString (), didRead); // } // void ResultTextDataFunc(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) { if (TreeIter.Zero.Equals(iter)) { return; } var textRenderer = (CellRendererText)cell; var searchResult = (SearchResult)store.GetValue(iter, SearchResultColumn); if (searchResult == null || searchResult.Offset < 0) { textRenderer.Markup = "Invalid search result"; return; } var doc = GetDocument(searchResult); if (doc == null) { textRenderer.Markup = "Can't create document for:" + searchResult.FileName; return; } int lineNr = doc.OffsetToLineNumber(searchResult.Offset); DocumentLine line = doc.GetLine(lineNr); if (line == null) { textRenderer.Markup = "Invalid line number " + lineNr + " from offset: " + searchResult.Offset; return; } bool isSelected = treeviewSearchResults.Selection.IterIsSelected(iter); int indent = line.GetIndentation(doc).Length; var data = new Mono.TextEditor.TextEditorData(doc); data.ColorStyle = highlightStyle; string markup = doc.SyntaxMode != null? data.GetMarkup(line.Offset + indent, line.Length - indent, true, !isSelected, false) : GLib.Markup.EscapeText(doc.GetTextAt(line.Offset, line.Length)); if (!isSelected) { int col = searchResult.Offset - line.Offset - indent; string tag; int pos1 = FindPosition(markup, col, out tag); int pos2 = FindPosition(markup, col + searchResult.Length, out tag); if (pos1 >= 0 && pos2 >= 0) { markup = tag.StartsWith("span") ? markup.Insert(pos2, "</span></span><" + tag + ">") : markup.Insert(pos2, "</span>"); Color searchColor = Mono.TextEditor.Highlighting.ColorScheme.ToGdkColor(highlightStyle.SearchTextBg); double b1 = Mono.TextEditor.HslColor.Brightness(searchColor); double b2 = Mono.TextEditor.HslColor.Brightness(AdjustColor(Style.Base(StateType.Normal), highlightStyle.Default.Color)); double delta = Math.Abs(b1 - b2); if (delta < 0.1) { Mono.TextEditor.HslColor color1 = highlightStyle.SearchTextBg; if (color1.L + 0.5 > 1.0) { color1.L -= 0.5; } else { color1.L += 0.5; } searchColor = color1; } markup = markup.Insert(pos1, "<span background=\"" + SyntaxMode.ColorToPangoMarkup(searchColor) + "\">"); } } string markupText = AdjustColors(markup.Replace("\t", new string (' ', TextEditorOptions.DefaultOptions.TabSize))); try { textRenderer.Markup = markupText; } catch (Exception e) { LoggingService.LogError("Error whil setting the text renderer markup to: " + markup, e); } }
protected override bool OnExposeEvent (Gdk.EventExpose evnt) { if (State == StateType.Prelight) { int w = Allocation.Width, h = Allocation.Height; double x=Allocation.Left, y=Allocation.Top, r=3; x += 0.5; y += 0.5; h -=1; w -= 1; using (Cairo.Context ctx = Gdk.CairoHelper.Create (GdkWindow)) { HslColor c = new HslColor (Style.Background (Gtk.StateType.Normal)); HslColor c1 = c; HslColor c2 = c; if (State != StateType.Prelight) { c1.L *= 0.8; c2.L *= 0.95; } else { c1.L *= 1.1; c2.L *= 1; } Cairo.Gradient pat; switch (bar.Position) { case PositionType.Top: pat = new Cairo.LinearGradient (x, y, x, y+h); break; case PositionType.Bottom: pat = new Cairo.LinearGradient (x, y, x, y+h); break; case PositionType.Left: pat = new Cairo.LinearGradient (x+w, y, x, y); break; default: pat = new Cairo.LinearGradient (x, y, x+w, y); break; } pat.AddColorStop (0, c1); pat.AddColorStop (1, c2); ctx.NewPath (); ctx.Arc (x+r, y+r, r, 180 * (Math.PI / 180), 270 * (Math.PI / 180)); ctx.LineTo (x+w-r, y); ctx.Arc (x+w-r, y+r, r, 270 * (Math.PI / 180), 360 * (Math.PI / 180)); ctx.LineTo (x+w, y+h); ctx.LineTo (x, y+h); ctx.ClosePath (); ctx.Pattern = pat; ctx.FillPreserve (); c1 = c; c1.L *= 0.7; ctx.LineWidth = 1; ctx.Color = c1; ctx.Stroke (); // Inner line ctx.NewPath (); ctx.Arc (x+r+1, y+r+1, r, 180 * (Math.PI / 180), 270 * (Math.PI / 180)); ctx.LineTo (x+w-r-1, y+1); ctx.Arc (x+w-r-1, y+r+1, r, 270 * (Math.PI / 180), 360 * (Math.PI / 180)); ctx.LineTo (x+w-1, y+h-1); ctx.LineTo (x+1, y+h-1); ctx.ClosePath (); c1 = c; //c1.L *= 0.9; ctx.LineWidth = 1; ctx.Color = c1; ctx.Stroke (); } } bool res = base.OnExposeEvent (evnt); return res; }
// void ResultLineDataFunc (TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) // { // if (TreeIter.Zero.Equals (iter)) // return; // var lineRenderer = (CellRendererText)cell; // var searchResult = (SearchResult)store.GetValue (iter, SearchResultColumn); // if (searchResult == null) // return; // // Document doc = GetDocument (searchResult); // int lineNr = doc.OffsetToLineNumber (searchResult.Offset) + 1; // bool didRead = (bool)store.GetValue (iter, DidReadColumn); // lineRenderer.Markup = MarkupText (lineNr.ToString (), didRead); // } // void ResultTextDataFunc(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) { if (TreeIter.Zero.Equals(iter)) { return; } var textRenderer = (CellRendererText)cell; var searchResult = (SearchResult)store.GetValue(iter, SearchResultColumn); if (searchResult == null || searchResult.Offset < 0) { textRenderer.Markup = "Invalid search result"; return; } var doc = GetDocument(searchResult); if (doc == null) { textRenderer.Markup = "Can't create document for:" + searchResult.FileName; return; } bool isSelected = treeviewSearchResults.Selection.IterIsSelected(iter); if (searchResult.Markup == null) { if (searchResult.LineNumber <= 0) { searchResult.LineNumber = doc.OffsetToLineNumber(searchResult.Offset); } DocumentLine line = doc.GetLine(searchResult.LineNumber); if (line == null) { textRenderer.Markup = "Invalid line number " + searchResult.LineNumber + " from offset: " + searchResult.Offset; return; } int indent = line.GetIndentation(doc).Length; var data = new Mono.TextEditor.TextEditorData(doc); data.ColorStyle = highlightStyle; var lineText = doc.GetTextAt(line.Offset + indent, line.Length - indent); int col = searchResult.Offset - line.Offset - indent; // search result contained part of the indent. if (col + searchResult.Length < lineText.Length) { lineText = doc.GetTextAt(line.Offset, line.Length); } var markup = doc.SyntaxMode != null? data.GetMarkup(line.Offset + indent, line.Length - indent, true, !isSelected, false) : GLib.Markup.EscapeText(lineText); searchResult.Markup = AdjustColors(markup.Replace("\t", new string (' ', TextEditorOptions.DefaultOptions.TabSize))); uint start; uint end; try { start = (uint)TextViewMargin.TranslateIndexToUTF8(lineText, col); end = (uint)TextViewMargin.TranslateIndexToUTF8(lineText, col + searchResult.Length); } catch (Exception e) { LoggingService.LogError("Exception while translating index to utf8 (column was:" + col + " search result length:" + searchResult.Length + " line text:" + lineText + ")", e); return; } searchResult.StartIndex = start; searchResult.EndIndex = end; } try { textRenderer.Markup = searchResult.Markup; if (!isSelected) { var searchColor = highlightStyle.SearchResult.Color; double b1 = Mono.TextEditor.HslColor.Brightness(searchColor); double b2 = Mono.TextEditor.HslColor.Brightness(AdjustColor(Style.Base(StateType.Normal), (Mono.TextEditor.HslColor)highlightStyle.PlainText.Foreground)); double delta = Math.Abs(b1 - b2); if (delta < 0.1) { Mono.TextEditor.HslColor color1 = highlightStyle.SearchResult.Color; if (color1.L + 0.5 > 1.0) { color1.L -= 0.5; } else { color1.L += 0.5; } searchColor = color1; } var attr = new Pango.AttrBackground((ushort)(searchColor.R * ushort.MaxValue), (ushort)(searchColor.G * ushort.MaxValue), (ushort)(searchColor.B * ushort.MaxValue)); attr.StartIndex = searchResult.StartIndex; attr.EndIndex = searchResult.EndIndex; using (var list = textRenderer.Attributes.Copy()) { list.Insert(attr); textRenderer.Attributes = list; } } } catch (Exception e) { LoggingService.LogError("Error whil setting the text renderer markup to: " + searchResult.Markup, e); } }
protected override bool OnExposeEvent(EventExpose evnt) { if (data == null) { BuildData(); } hostSpots.Clear(); int ytop = padding; int markerX = 3; int lx = markerX + MarkerWidth + 1; int tx = 250; int ty = ytop; int maxx = lx; int maxy = 0; DateTime initialTime = mainValue.TimeStamp; Cairo.Context ctx = CairoHelper.Create(GdkWindow); Gdk.GC gc = new Gdk.GC(GdkWindow); gc.RgbFgColor = Style.White; GdkWindow.DrawRectangle(gc, true, 0, 0, Allocation.Width, Allocation.Height); // Draw full time marker ctx.NewPath(); ctx.Rectangle(markerX, ytop + baseTime + 0.5, MarkerWidth / 2, ((mainValue.Duration.TotalMilliseconds * scale) / 1000)); Mono.TextEditor.HslColor hsl = Style.Foreground(Gtk.StateType.Normal); hsl.L = 0.8; ctx.SetSourceColor(hsl); ctx.Fill(); // Draw values foreach (CounterValueInfo val in data) { DrawValue(ctx, gc, initialTime, ytop, lx, tx, ref ty, ref maxx, ref maxy, 0, val); } if (ty > maxy) { maxy = ty; } int totalms = (int)mainValue.Duration.TotalMilliseconds; int marks = (totalms / 1000) + 1; ctx.LineWidth = 1; gc.RgbFgColor = Style.Foreground(Gtk.StateType.Normal); for (int n = 0; n <= marks; n++) { ctx.NewPath(); int y = ytop + (int)(n * scale) + baseTime; ctx.MoveTo(markerX, y + 0.5); ctx.LineTo(markerX + MarkerWidth, y + 0.5); ctx.SetSourceColor(Style.Foreground(Gtk.StateType.Normal).ToCairoColor()); ctx.Stroke(); y += 2; layout.SetText(n + "s"); GdkWindow.DrawLayout(gc, markerX + 1, y + 2, layout); int tw, th; layout.GetPixelSize(out tw, out th); y += th; if (y > maxy) { maxy = y; } } ((IDisposable)ctx).Dispose(); maxy += padding; maxx += padding; if (lastHeight != maxy || lastWidth != maxx) { lastWidth = maxx; lastHeight = maxy; SetSizeRequest(maxx, maxy); } return(true); }
internal protected override void OptionsChanged () { DisposeGCs (); foldBgGC = new Gdk.GC (editor.GdkWindow); foldBgGC.RgbFgColor = editor.ColorStyle.FoldLine.BackgroundColor; foldLineGC = new Gdk.GC (editor.GdkWindow); foldLineGC.RgbFgColor = editor.ColorStyle.FoldLine.Color; foldLineHighlightedGC = new Gdk.GC (editor.GdkWindow); foldLineHighlightedGC.RgbFgColor = editor.ColorStyle.FoldLineHighlighted; HslColor hslColor = new HslColor (editor.ColorStyle.Default.BackgroundColor); double brightness = HslColor.Brightness (editor.ColorStyle.Default.BackgroundColor); if (brightness < 0.5) { hslColor.L = hslColor.L * 0.85 + hslColor.L * 0.25; } else { hslColor.L = hslColor.L * 0.9; } foldLineHighlightedGCBg = new Gdk.GC (editor.GdkWindow); foldLineHighlightedGCBg.RgbFgColor = hslColor; foldToggleMarkerGC = new Gdk.GC (editor.GdkWindow); foldToggleMarkerGC.RgbFgColor = editor.ColorStyle.FoldToggleMarker; lineStateChangedGC = new Gdk.GC (editor.GdkWindow); lineStateChangedGC.RgbFgColor = new Gdk.Color (108, 226, 108); lineStateDirtyGC = new Gdk.GC (editor.GdkWindow); lineStateDirtyGC.RgbFgColor = new Gdk.Color (255, 238, 98); marginWidth = editor.LineHeight; /* layout.FontDescription = editor.Options.Font; layout.SetText ("!"); int tmp; layout.GetPixelSize (out tmp, out this.marginWidth); marginWidth *= 8; marginWidth /= 10;*/ }
public static double Brightness(HslColor c) { return(Brightness((Cairo.Color)c)); }