/// <summary> /// Draws the caret using the given context objects. /// </summary> /// <param name="renderContext">The render context.</param> public void Draw(IRenderContext renderContext) { // Get the draw region. Rectangle drawRegion = GetDrawRegion(); // Make sure the render area intersects with the caret. if (!renderContext.RenderRegion.IntersectsWith(drawRegion)) { // Not visible, don't show anything. return; } // Turn off antialiasing for a sharper, thin line. Context context = renderContext.CairoContext; Antialias oldAntialias = context.Antialias; context.Antialias = Antialias.None; // Draw the caret on the screen. try { context.LineWidth = 1; context.Color = new Color(0, 0, 0, 1); context.MoveTo(drawRegion.X, drawRegion.Y); context.LineTo(drawRegion.X, drawRegion.Y + drawRegion.Height); context.Stroke(); } finally { // Restore the context. context.Antialias = oldAntialias; } }
internal static extern void cairo_set_antialias(IntPtr cr, Antialias antialias);
internal static extern void cairo_font_options_set_antialias(IntPtr options, Antialias aa);
internal static extern void cairo_set_antialias (IntPtr cr, Antialias antialias);
internal static extern void cairo_font_options_set_antialias (IntPtr options, Antialias aa);
/// <summary> /// Draws a layout with a given style to the render context. /// </summary> /// <param name="displayContext">The display context.</param> /// <param name="renderContext">The render context.</param> /// <param name="region">The region for the various elements.</param> /// <param name="style">The style used for borders and padding.</param> public static void DrawLayout( IDisplayContext displayContext, IRenderContext renderContext, Rectangle region, BlockStyle style) { // If we don't have a style, then don't do anything. if (style == null) { return; } // Get the style for the line number. Spacing margins = style.GetMargins(); Borders borders = style.GetBorders(); double marginLeftX = margins.Left + borders.Left.LineWidth; double marginRightX = margins.Right + borders.Right.LineWidth; // Get the context and save settings because we use anti-aliasing // to get a sharper line. Context cairoContext = renderContext.CairoContext; Antialias oldAntialias = cairoContext.Antialias; try { // Draw the background color. Color?backgroundColor = style.GetBackgroundColor(); if (backgroundColor.HasValue) { var cairoArea = new Rectangle( region.X + marginLeftX, region.Y, region.Width - marginLeftX - marginRightX, region.Height); cairoContext.Color = backgroundColor.Value; cairoContext.Rectangle(cairoArea); cairoContext.Fill(); } // Figure out the width for rendering the horizontal borders so // they line up a little bit nicer. We adjust for half the border // width because Cairo draws in the middle and we have to shift by // half that to get the side to line up with the end of the // horizontal. double topMarginY = region.Y + margins.Top; double bottomMarginY = region.Y + region.Height - margins.Bottom; double leftMarginX = region.X + margins.Left + (borders.Left.LineWidth / 2); double rightMarginX = leftMarginX + region.Width - margins.Width; // Draw the border lines. cairoContext.Antialias = Antialias.None; if (borders.Top.LineWidth > 0) { // Set up the line width and colors. cairoContext.LineWidth = borders.Top.LineWidth; cairoContext.Color = borders.Top.Color; cairoContext.MoveTo(leftMarginX, topMarginY); cairoContext.LineTo(rightMarginX, topMarginY); cairoContext.Stroke(); } if (borders.Bottom.LineWidth > 0) { cairoContext.LineWidth = borders.Bottom.LineWidth; cairoContext.Color = borders.Bottom.Color; cairoContext.MoveTo(leftMarginX, bottomMarginY); cairoContext.LineTo(rightMarginX, bottomMarginY); cairoContext.Stroke(); } if (borders.Left.LineWidth > 0) { cairoContext.LineWidth = borders.Left.LineWidth; cairoContext.Color = borders.Left.Color; cairoContext.MoveTo(region.X + marginLeftX, topMarginY); cairoContext.LineTo(region.X + marginLeftX, bottomMarginY); cairoContext.Stroke(); } if (borders.Right.LineWidth > 0) { cairoContext.LineWidth = borders.Right.LineWidth; cairoContext.Color = borders.Right.Color; cairoContext.MoveTo(region.X + region.Width - margins.Right, topMarginY); cairoContext.LineTo(region.X + region.Width - margins.Right, bottomMarginY); cairoContext.Stroke(); } } finally { // Restore the context. cairoContext.Antialias = oldAntialias; } }