static Cairo.Color[,,,,] CreateColorMatrix(TextEditor editor, bool isError) { string typeString = isError ? "error" : "warning"; Cairo.Color[,,,,] colorMatrix = new Cairo.Color[2, 2, 3, 2, 2]; ColorSheme style = editor.ColorStyle; if (style == null) { style = new DefaultStyle(editor.Style); } var baseColor = style.GetChunkStyle("bubble." + typeString + "").CairoBackgroundColor; AdjustColorMatrix(colorMatrix, 0, baseColor); var hsl = (HslColor)baseColor; hsl.S *= 0.6; baseColor = hsl; AdjustColorMatrix(colorMatrix, 1, hsl); double factor = 1.03; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 3; k++) { HslColor color = colorMatrix [i, j, k, 0, 0]; color.L *= factor; colorMatrix [i, j, k, 1, 0] = color; } } } var selectionColor = ColorSheme.ToCairoColor(style.Selection.BackgroundColor); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 3; k++) { for (int l = 0; l < 2; l++) { var color = colorMatrix [i, j, k, l, 0]; colorMatrix [i, j, k, l, 1] = new Cairo.Color((color.R + selectionColor.R * 1.5) / 2.5, (color.G + selectionColor.G * 1.5) / 2.5, (color.B + selectionColor.B * 1.5) / 2.5); } } } } return(colorMatrix); }
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.81 + hslColor.L * 0.25 * (colorCount - colorPosition) / colorCount; } else { hslColor.L = hslColor.L * 0.86 + 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 = ColorSheme.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 (); }