void ExposeTitle(Cairo.Context c) { // The primary title background c.SetSourceRGBA(0, 0, 0, 0.3); c.Rectangle(0, m_titleOffset, this.Allocation.Width, m_titleHeight); c.Fill(); // The title shadow (lip) c.SetSourceRGBA(0, 0, 0, 0.1); c.Rectangle(0, m_titleOffset + m_titleHeight, this.Allocation.Width, m_titleLip); c.Fill(); // Paint the title text using (var p = Pango.CairoHelper.CreateLayout(c)) { int w = 0, h = 0, pad = 0; p.SetText(m_Title); p.GetPixelSize(out w, out h); pad = (m_titleHeight - h) / 2; c.MoveTo(pad, m_titleOffset + pad); c.SetSourceRGB(1.0, 1.0, 1.0); Pango.CairoHelper.ShowLayout(c, p); } }
public override void Draw(Cairo.Context cr, double xPos, double yPos, PrintLayer layer) { if (layer == PrintLayer.Text) { yPos -= _extents.YAdvance; // Only draw the line if there is enough space to display it if (_extents.Width > 2) { yPos -= (_extents.Height / 2) - (_lineThickness / 2); cr.Rectangle(xPos , yPos , _extents.Width , _lineThickness); cr.Fill(); } if (_lineType == PrintLineType.Double) { yPos -= 4; cr.Rectangle(xPos , yPos , _extents.Width , _lineThickness); cr.Fill(); } } }
//private double last_invalidate_value = -1; /*private void Invalidate () * { * double current_value = (IsValueUpdatePending ? PendingValue : Value); * * // FIXME: Something is wrong with the updating below causing an * // invalid region when IsValueUpdatePending is true, so when * // that is the case for now, we trigger a full invalidation * if (last_invalidate_value < 0 || IsValueUpdatePending) { * last_invalidate_value = current_value; * InvalidateRender (); * return; * } * * double max = Math.Max (last_invalidate_value, current_value) * RenderSize.Width; * double min = Math.Min (last_invalidate_value, current_value) * RenderSize.Width; * * Rect region = new Rect ( * InvalidationRect.X + min, * InvalidationRect.Y, * (max - min) + 2 * ThrobberSize, * InvalidationRect.Height * ); * * last_invalidate_value = current_value; * InvalidateRender (region); * }*/ /*protected override Rect InvalidationRect { * get { return new Rect ( * -Margin.Left - ThrobberSize / 2, * -Margin.Top, * Allocation.Width + ThrobberSize, * Allocation.Height); * } * }*/ protected override void ClippedRender(Cairo.Context cr) { double throbber_r = ThrobberSize / 2.0; double throbber_x = Math.Round(RenderSize.Width * (IsValueUpdatePending ? PendingValue : Value)); double throbber_y = (Allocation.Height - ThrobberSize) / 2.0 - Margin.Top + throbber_r; double bar_w = RenderSize.Width * Value; cr.SetSourceColor(Theme.Colors.GetWidgetColor(GtkColorClass.Base, Gtk.StateType.Normal)); cr.Rectangle(0, 0, RenderSize.Width, RenderSize.Height); cr.Fill(); Color color = Theme.Colors.GetWidgetColor(GtkColorClass.Dark, Gtk.StateType.Active); Color fill_color = CairoExtensions.ColorShade(color, 0.4); Color light_fill_color = CairoExtensions.ColorShade(color, 0.3); fill_color.A = 1.0; light_fill_color.A = 1.0; LinearGradient fill = new LinearGradient(0, 0, 0, RenderSize.Height); fill.AddColorStop(0, light_fill_color); fill.AddColorStop(0.5, fill_color); fill.AddColorStop(1, light_fill_color); cr.Rectangle(0, 0, bar_w, RenderSize.Height); cr.SetSource(fill); cr.Fill(); cr.SetSourceColor(fill_color); cr.Arc(throbber_x, throbber_y, throbber_r, 0, Math.PI * 2); cr.Fill(); }
private void DrawShape(Cairo.Context g, int width, int height) { int inner_x = radius + border + inner; int cx = Center.X; int cy = Center.Y; g.Operator = Operator.Source; g.Source = new SolidPattern(new Cairo.Color(0, 0, 0, 0)); g.Rectangle(0, 0, width, height); g.Paint(); g.NewPath(); g.Translate(cx, cy); g.Rotate(angle); g.Source = new SolidPattern(new Cairo.Color(0.2, 0.2, 0.2, .6)); g.Operator = Operator.Over; g.Rectangle(0, -(border + inner), inner_x, 2 * (border + inner)); g.Arc(inner_x, 0, inner + border, 0, 2 * Math.PI); g.Arc(0, 0, radius + border, 0, 2 * Math.PI); g.Fill(); g.Source = new SolidPattern(new Cairo.Color(0, 0, 0, 1.0)); g.Operator = Operator.DestOut; g.Arc(inner_x, 0, inner, 0, 2 * Math.PI); #if true g.Fill(); #else g.FillPreserve(); g.Operator = Operator.Over; RadialGradient rg = new RadialGradient(inner_x - (inner * 0.3), inner * 0.3, inner * 0.1, inner_x, 0, inner); rg.AddColorStop(0, new Cairo.Color(0.0, 0.2, .8, 0.5)); rg.AddColorStop(0.7, new Cairo.Color(0.0, 0.2, .8, 0.1)); rg.AddColorStop(1.0, new Cairo.Color(0.0, 0.0, 0.0, 0.0)); g.Source = rg; g.Fill(); rg.Destroy(); #endif g.Operator = Operator.Over; g.Matrix = new Matrix(); g.Translate(cx, cy); if (source != null) { SetSourcePixbuf(g, source, -source.Width / 2, -source.Height / 2); } g.Arc(0, 0, radius, 0, 2 * Math.PI); g.Fill(); if (overlay != null) { SetSourcePixbuf(g, overlay, -overlay.Width / 2, -overlay.Height / 2); g.Arc(0, 0, radius, angle, angle + Math.PI); g.ClosePath(); g.FillPreserve(); g.Source = new SolidPattern(new Cairo.Color(1.0, 1.0, 1.0, 1.0)); g.Stroke(); } }
protected void OnDrawingarea1ExposeEvent(object o, ExposeEventArgs args) { Console.WriteLine("Exposed"); DrawingArea area = (DrawingArea)o; Cairo.Context cr = Gdk.CairoHelper.Create(area.GdkWindow); int width = area.Allocation.Width; int height = area.Allocation.Height; int radius = (width < height ? width : height); cr.SetSourceRGB(0.0, 0.0, 0.0); cr.Rectangle(0, 0, width, height); cr.Fill(); cr.Translate(this.offsetX, this.offsetY); // move "pointer" cr.Scale(this.scale, this.scale); cr.SetSourceSurface(this.surface, 0, 0); // offset surface cr.Rectangle(0, 0, this.surface.Width, // offset cutout this.surface.Height); cr.Fill(); // apply cr.SetSourceRGB(1.0, 0.0, 0.0); cr.Arc(this.pointX, this.pointY, 2, 0, 2 * Math.PI); cr.Fill(); ((IDisposable)cr.GetTarget()).Dispose(); ((IDisposable)cr).Dispose(); }
void DrawBackground(Cairo.Context gr) { gr.Rectangle(0, 0, Allocation.Width, Allocation.Height); gr.Color = new Color(1, 1, 1); gr.Fill(); gr.Rectangle(0, 0, Allocation.Width, timeHeight); var gradient = new LinearGradient(0, 0, 0, timeHeight); gradient.AddColorStop(0, timeGradientStartColor); gradient.AddColorStop(1, timeGradientEndColor); gr.Pattern = gradient; gr.Fill(); gr.LineWidth = 1; gr.Color = lineColor; gr.MoveTo(0, timeHeight + 0.5); gr.LineTo(Allocation.Width, timeHeight + 0.5); gr.Stroke(); gr.MoveTo(0, timeHeight + eventHeight + 0.5); gr.LineTo(Allocation.Width, timeHeight + eventHeight + 0.5); gr.Stroke(); gr.MoveTo(boxWidth + 0.5, 0); gr.LineTo(boxWidth + 0.5, Allocation.Height); gr.Stroke(); }
protected void DrawHoverAndSelection(Cairo.Context cr) { cr.Save(); cr.Translate(XOffset, YOffset); cr.Scale(Scale, Scale); if (Hoverable && hoveringIndex != -1) { Cairo.Rectangle rect = GetTileRectSansPadding(HoveringX, HoveringY, scale: false, offset: false); cr.NewPath(); cr.SetSourceColor(HoverColor); cr.Rectangle(new Cairo.Rectangle(rect.X + 0.5, rect.Y + 0.5, rect.Width - 1, rect.Height - 1)); cr.LineWidth = 1; cr.LineJoin = LineJoin.Bevel; cr.Stroke(); } if (Selectable) { var rect = GetTileRectSansPadding(SelectedX, SelectedY, scale: false, offset: false); if (IsInBounds((int)rect.X, (int)rect.Y, scale: false, offset: false)) { cr.NewPath(); cr.SetSourceColor(SelectionColor); cr.Rectangle(rect.X + 0.5, rect.Y + 0.5, rect.Width - 1, rect.Height - 1); cr.LineWidth = 1; cr.Stroke(); } } cr.Restore(); }
protected override bool OnExposeEvent(EventExpose evnt) { using (Cairo.Context ctx = CairoHelper.Create(evnt.Window)) { int dx = (int)((double)Allocation.Width * dividerPosition); ctx.LineWidth = 1; ctx.Rectangle(0, 0, dx, Allocation.Height); ctx.SetSourceColor(LabelBackgroundColor); ctx.Fill(); ctx.Rectangle(dx, 0, Allocation.Width - dx, Allocation.Height); ctx.SetSourceRGB(1, 1, 1); ctx.Fill(); if (PropertyContentRightPadding > 0) { ctx.Rectangle(Allocation.Width - PropertyContentRightPadding, 0, PropertyContentRightPadding, Allocation.Height); ctx.SetSourceColor(LabelBackgroundColor); ctx.Fill(); ctx.MoveTo(Allocation.Width - PropertyContentRightPadding + 0.5, 0); ctx.RelLineTo(0, Allocation.Height); ctx.SetSourceColor(DividerColor); ctx.Stroke(); } ctx.MoveTo(dx + 0.5, 0); ctx.RelLineTo(0, Allocation.Height); ctx.SetSourceColor(DividerColor); ctx.Stroke(); int y = 0; Draw(ctx, rows, dx, PropertyLeftPadding, ref y); } return(base.OnExposeEvent(evnt)); }
protected override void Render(Gdk.Drawable window, Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags) { using (Cairo.Context gr = Gdk.CairoHelper.Create(window)) { gr.Rectangle(cell_area.X, cell_area.Y, cell_area.Width, cell_area.Height); gr.Color = (HslColor)widget.Style.Base((flags & CellRendererState.Selected) == CellRendererState.Selected ? StateType.Selected : StateType.Normal); gr.Fill(); var size = Math.Max(0, cell_area.Width - cell_area.Width * Time / 100.0); var linearGradient = new LinearGradient(cell_area.X, cell_area.Y, cell_area.Right, cell_area.Bottom); linearGradient.AddColorStop(0, new Cairo.Color(1, 0, 0)); linearGradient.AddColorStop(1, new Cairo.Color(1, 1, 1)); gr.Pattern = linearGradient; gr.Rectangle(cell_area.X + size, cell_area.Y + 2, cell_area.Width - size, cell_area.Height - 4); gr.Fill(); var layout = gr.CreateLayout(); layout.FontDescription = widget.PangoContext.FontDescription; layout.SetText(string.Format("{0:0.0}", Time)); int w, h; layout.GetPixelSize(out w, out h); gr.MoveTo(cell_area.X + cell_area.Width - 2 - w, cell_area.Y + (cell_area.Height - h) / 2); gr.Color = new Cairo.Color(0, 0, 0); gr.ShowLayout(layout); layout.Dispose(); } }
/*override (Gdk.EventButton evnt) * { * var res = base.OnButtonPressEvent(evnt); * if ((evnt.Button & (uint)Gdk.ModifierType.Button1Mask) != 0) * { * if ((evnt.Button & (uint)Gdk.ModifierType.ShiftMask) != 0) * { * // if is left click + shift * EnableMode = EnableMode.ActiveWithLimit; * } * else * { * // if is left click * EnableMode = EnableMode.Active; * } * }else if ((evnt.Button & (uint)Gdk.ModifierType.Button3Mask) != 0) * { * //right clicked * EnableMode = EnableMode.Disabled; * } * * QueueDraw(); * * return res; * }*/ void SetBgColor(EnableMode enableMode, Gdk.EventExpose evnt) { //this.ModifyBg(StateType.Normal, Colors[(int)EnableMode]); Cairo.Context cr = Gdk.CairoHelper.Create(this.GdkWindow); cr.Rectangle(0, 0, Allocation.Width, Allocation.Height); Color c = new Color(0, 0, 0); cr.SetSourceColor(c); cr.Stroke(); cr.Rectangle(1, 1, Allocation.Width - 1, Allocation.Height - 1); if (enableMode == EnableMode.Active) { c = Colors[1]; } else if (enableMode == EnableMode.ActiveWithLimit) { c = Colors[2]; } else if (enableMode == EnableMode.Disabled) { c = Colors[0]; } cr.SetSourceColor(c); cr.Fill(); cr.Target.Dispose(); cr.Dispose(); // set tooltip HasTooltip = true; TooltipText = enableMode.ToString(); }
void FillChecks (Context cr, int x, int y, int width, int height) { int CHECK_SIZE = 32; cr.Save (); Surface check = cr.Target.CreateSimilar (Content.Color, 2 * CHECK_SIZE, 2 * CHECK_SIZE); // draw the check using (Context cr2 = new Context (check)) { cr2.Operator = Operator.Source; cr2.Color = new Color (0.4, 0.4, 0.4); cr2.Rectangle (0, 0, 2 * CHECK_SIZE, 2 * CHECK_SIZE); cr2.Fill (); cr2.Color = new Color (0.7, 0.7, 0.7); cr2.Rectangle (x, y, CHECK_SIZE, CHECK_SIZE); cr2.Fill (); cr2.Rectangle (x + CHECK_SIZE, y + CHECK_SIZE, CHECK_SIZE, CHECK_SIZE); cr2.Fill (); } // Fill the whole surface with the check SurfacePattern check_pattern = new SurfacePattern (check); check_pattern.Extend = Extend.Repeat; cr.Source = check_pattern; cr.Rectangle (0, 0, width, height); cr.Fill (); check_pattern.Destroy (); check.Destroy (); cr.Restore (); }
public void DrawObject(Context ctx, DrawingObject body) { if (body == null) return; ctx.Save (); ctx.Color = new Cairo.Color (0, 0, 0); ctx.LineWidth = 1; foreach (Tuple<PointDouble, PointDouble> line in body.lines) { ctx.MoveTo (line.Item1.toPointD()); ctx.LineTo (line.Item2.toPointD()); } if (body.points.Count > 1) ctx.Rectangle(body._centerOfMass.X - 5, body._centerOfMass.Y - 5, 10, 10); ctx.Stroke (); foreach (PointDouble point in body.points) { ctx.Rectangle (point.X - 5, point.Y - 5, 10, 10); ctx.Fill (); } foreach (Tuple<PointDouble, double, double> force in body._forces) { DrawForce (ctx, force); } foreach (Tuple<PointDouble, double> moment in body._moments) { DrawMoment (ctx, moment); } ctx.Restore (); }
public void DrawRowSelection(Cairo.Context cr, int x, int y, int width, int height, bool filled, bool stroked, Cairo.Color color, CairoCorners corners) { color.A *= 0.85; Cairo.Color selection_color = color; Cairo.Color selection_stroke = CairoExtensions.ColorShade(selection_color, 0.85); selection_stroke.A = color.A; if (filled) { Cairo.Color selection_fill_light = CairoExtensions.ColorShade(selection_color, 1.05); Cairo.Color selection_fill_dark = selection_color; selection_fill_light.A = color.A; selection_fill_dark.A = color.A; LinearGradient grad = new LinearGradient(x, y, x, y + height); grad.AddColorStop(0, selection_fill_dark); grad.AddColorStop(1, selection_fill_light); cr.SetSource(grad); cr.Rectangle(x, y, width, height); cr.Fill(); grad.Dispose(); } if (stroked && !filled) { cr.LineWidth = 1.0; cr.SetSourceColor(selection_stroke); cr.Rectangle(x + 0.5, y + 0.5, width - 1, height - 1); cr.Stroke(); } }
public static SurfacePattern CreateImageBrush(ImageBrush brush, Size targetSize) { if (brush.Source == null) { return null; } // TODO: This is directly ported from Direct2D and could probably be made more // efficient on cairo by taking advantage of the fact that cairo has Extend.None. var image = ((BitmapImpl)brush.Source.PlatformImpl).Surface; var imageSize = new Size(brush.Source.PixelWidth, brush.Source.PixelHeight); var tileMode = brush.TileMode; var sourceRect = brush.SourceRect.ToPixels(imageSize); var destinationRect = brush.DestinationRect.ToPixels(targetSize); var scale = brush.Stretch.CalculateScaling(destinationRect.Size, sourceRect.Size); var translate = CalculateTranslate(brush, sourceRect, destinationRect, scale); var intermediateSize = CalculateIntermediateSize(tileMode, targetSize, destinationRect.Size); var intermediate = new ImageSurface (Format.ARGB32, (int)intermediateSize.Width, (int)intermediateSize.Height); using (var context = new Context(intermediate)) { Rect drawRect; var transform = CalculateIntermediateTransform( tileMode, sourceRect, destinationRect, scale, translate, out drawRect); context.Rectangle(drawRect.ToCairo()); context.Clip(); context.Transform(transform.ToCairo()); Gdk.CairoHelper.SetSourcePixbuf(context, image, 0, 0); context.Rectangle(0, 0, imageSize.Width, imageSize.Height); context.Fill(); var result = new SurfacePattern(intermediate); if ((brush.TileMode & TileMode.FlipXY) != 0) { // TODO: Currently always FlipXY as that's all cairo supports natively. // Support separate FlipX and FlipY by drawing flipped images to intermediate // surface. result.Extend = Extend.Reflect; } else { result.Extend = Extend.Repeat; } if (brush.TileMode != TileMode.None) { var matrix = result.Matrix; matrix.InitTranslate(-destinationRect.X, -destinationRect.Y); result.Matrix = matrix; } return result; } }
protected override void Draw(Context cr, Pixbuf prev, Pixbuf next, int width, int height, double progress) { cr.Color = new Color (0, 0, 0, progress); if (next != null) { double scale = Math.Min ((double)width/(double)next.Width, (double)height/(double)next.Height); cr.Save (); cr.Rectangle (0, 0, width, .5 * (height - scale*next.Height)); cr.Fill (); cr.Rectangle (0, height - .5 * (height - scale*next.Height), width, .5 * (height - scale*next.Height)); cr.Fill (); cr.Rectangle (0, 0, .5 * (width - scale*next.Width), height); cr.Fill (); cr.Rectangle (width - .5 * (width - scale*next.Width), 0, .5 * (width - scale*next.Width), height); cr.Fill (); cr.Rectangle (0, 0, width, height); cr.Scale (scale, scale); CairoHelper.SetSourcePixbuf (cr, next, .5 * ((double)width/scale - next.Width), .5 * ((double)height/scale - next.Height)); cr.PaintWithAlpha (progress); cr.Restore (); } }
protected void DrawBackground(Cairo.Context cr) { var totalRect = GetTotalBounds(); cr.SetSourceColor(BackgroundColor); cr.Rectangle(totalRect.X, totalRect.Y, totalRect.Width, totalRect.Height); cr.Fill(); cr.Save(); cr.Translate(XOffset, YOffset); cr.Scale(Scale, Scale); if (Surface != null) { cr.SetSource(Surface, 0, 0); using (SurfacePattern pattern = (SurfacePattern)cr.GetSource()) { pattern.Filter = Filter.Nearest; } cr.Paint(); } else if (Image != null) { using (Surface source = new BitmapSurface(Image)) { cr.SetSource(source, 0, 0); using (SurfacePattern pattern = (SurfacePattern)cr.GetSource()) { pattern.Filter = Filter.Nearest; } cr.Paint(); } } else { Cairo.Rectangle extents = cr.ClipExtents(); for (int i = 0; i < Width * Height; i++) { int tileX = i % Width; int tileY = i / Width; Cairo.Rectangle rect = GetTileRectWithPadding(tileX, tileY, scale: false, offset: false); if (!CairoHelper.RectsOverlap(extents, rect)) { continue; } cr.Save(); cr.Translate(rect.X + TilePaddingX, rect.Y + TilePaddingY); cr.Rectangle(0, 0, TileWidth, TileHeight); cr.Clip(); TileDrawer(i, cr); cr.Restore(); } } cr.Restore(); // Undo scale, offset }
public void Draw(Cairo.Context cr, Cairo.Rectangle rectangle) { if (IsSeparator) { cr.NewPath(); double x = Math.Ceiling(rectangle.X + rectangle.Width / 2) + 0.5; cr.MoveTo(x, rectangle.Y + 0.5 + 2); cr.RelLineTo(0, rectangle.Height - 1 - 4); cr.ClosePath(); cr.SetSourceColor(parent.Style.Dark(StateType.Normal).ToCairoColor()); cr.LineWidth = 1; cr.Stroke(); return; } if (Active || HoverPosition.X >= 0) { if (Active) { cr.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); using (var gr = new LinearGradient(rectangle.X, rectangle.Y, rectangle.X, rectangle.Y + rectangle.Height)) { gr.AddColorStop(0, Tabstrip.ActiveGradientStart); gr.AddColorStop(1, Tabstrip.ActiveGradientEnd); cr.SetSource(gr); } cr.Fill(); cr.Rectangle(rectangle.X + 0.5, rectangle.Y + 0.5, rectangle.Width - 1, rectangle.Height - 1); cr.SetSourceRGBA(1, 1, 1, 0.05); cr.LineWidth = 1; cr.Stroke(); } else if (HoverPosition.X >= 0) { cr.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); using (var gr = new LinearGradient(rectangle.X, rectangle.Y, rectangle.X, rectangle.Y + rectangle.Height)) { var c1 = Tabstrip.ActiveGradientStart; var c2 = Tabstrip.ActiveGradientEnd; c1.A = 0.2; c2.A = 0.2; gr.AddColorStop(0, c1); gr.AddColorStop(1, c2); cr.SetSource(gr); } cr.Fill(); } } if (Active) { cr.SetSourceRGB(1, 1, 1); } else { cr.SetSourceColor(parent.Style.Text(StateType.Normal).ToCairoColor()); } cr.MoveTo(rectangle.X + (rectangle.Width - w) / 2, (rectangle.Height - h) / 2); Pango.CairoHelper.ShowLayout(cr, layout); }
public void IntersectClip(RectangleD newClip) { cairoContext.Rectangle(newClip.X * drawingScaleX, newClip.Y * drawingScaleY, newClip.Width * drawingScaleX, newClip.Height * drawingScaleY); cairoContext.Clip(); }
void DrawButtonTabs(Cairo.Context cr, Cairo.Rectangle rectangle) { if (IsSeparator) { cr.NewPath(); double x = Math.Ceiling(rectangle.X + rectangle.Width / 2) + 0.5; cr.MoveTo(x, rectangle.Y + 0.5 + 2); cr.RelLineTo(0, rectangle.Height - 1 - 4); cr.ClosePath(); cr.Color = (HslColor)parent.Style.Dark(StateType.Normal); cr.LineWidth = 1; cr.Stroke(); return; } int topPadding = 2; if (Active || HoverPosition.X >= 0) { cr.Rectangle(rectangle.X + 1, rectangle.Y + 1 + topPadding, rectangle.Width - 1, rectangle.Height - topPadding); if (Active) { cr.Color = (HslColor)parent.Style.Background(StateType.Prelight); } else if (HoverPosition.X >= 0) { double rx = rectangle.X + HoverPosition.X; double ry = rectangle.Y + HoverPosition.Y; Cairo.RadialGradient gradient = new Cairo.RadialGradient(rx, ry, rectangle.Height * 1.5, rx, ry, 2); var color = (HslColor)parent.Style.Dark(StateType.Normal); color.L *= 1.1; gradient.AddColorStop(0, color); color.L *= 1.1; gradient.AddColorStop(1, color); cr.Pattern = gradient; } cr.Fill(); if (Active) { cr.Rectangle(rectangle.X + 0.5, rectangle.Y + 0.5 + topPadding, rectangle.Width - 1, rectangle.Height - topPadding); cr.Color = (HslColor)parent.Style.Dark(StateType.Normal); cr.LineWidth = 1; cr.Stroke(); } } cr.Save(); cr.Translate(rectangle.X + (rectangle.Width - w) / 2, (rectangle.Height - h) / 2 + topPadding); cr.Color = (HslColor)parent.Style.Text(StateType.Normal); cr.ShowLayout(layout); cr.Restore(); }
/// <summary> /// Draws black in the areas outside the view. /// Assumes that controlBounds is starting at (0, 0) in upper left corner. /// </summary> /// <param name="context">A context to perform drawing.</param> /// <param name="controlBounds">Bounds of the control.</param> /// <param name="view">The bounds of the view.</param> public static void Draw(Context context, Rectangle controlBounds, Rectangle view) { context.Color = new Cairo.Color (0.0, 0.0, 0.0); context.NewPath (); context.Rectangle (0.0, 0.0, view.X, controlBounds.Height); var wRight = controlBounds.Width - view.X - view.Width; context.Rectangle (view.X + view.Width, 0.0, wRight, controlBounds.Height); context.Rectangle (view.X, 0.0, view.Width, view.Y); var hBottom = controlBounds.Height - view.Y - view.Height; context.Rectangle (view.X, view.Y + view.Height, view.Width, hBottom); context.Fill (); }
protected override void Draw(Context cr, Pixbuf prev, Pixbuf next, int width, int height, double progress) { cr.SetSourceColor (new Color (0, 0, 0)); if (prev != null) { double scale = Math.Min ((double)width/(double)prev.Width, (double)height/(double)prev.Height); cr.Save (); cr.Translate (-progress * width, 0); cr.Rectangle (0, 0, width, .5 * (height - scale*prev.Height)); cr.Fill (); cr.Rectangle (0, height - .5 * (height - scale*prev.Height), width, .5 * (height - scale*prev.Height)); cr.Fill (); cr.Rectangle (0, 0, .5 * (width - scale*prev.Width), height); cr.Fill (); cr.Rectangle (width - .5 * (width - scale*prev.Width), 0, .5 * (width - scale*prev.Width), height); cr.Fill (); cr.Rectangle (0, 0, width, height); cr.Scale (scale, scale); CairoHelper.SetSourcePixbuf (cr, prev, .5 * ((double)width/scale - prev.Width), .5 * ((double)height/scale - prev.Height)); cr.Fill (); cr.Restore (); } if (next != null) { double scale = Math.Min ((double)width/(double)next.Width, (double)height/(double)next.Height); cr.Save (); cr.Translate (width * (1.0 - progress), 0); cr.Rectangle (0, 0, width, .5 * (height - scale*next.Height)); cr.Fill (); cr.Rectangle (0, height - .5 * (height - scale*next.Height), width, .5 * (height - scale*next.Height)); cr.Fill (); cr.Rectangle (0, 0, .5 * (width - scale*next.Width), height); cr.Fill (); cr.Rectangle (width - .5 * (width - scale*next.Width), 0, .5 * (width - scale*next.Width), height); cr.Fill (); cr.Rectangle (0, 0, width, height); cr.Scale (scale, scale); CairoHelper.SetSourcePixbuf (cr, next, .5 * ((double)width/scale - next.Width), .5 * ((double)height/scale - next.Height)); cr.Fill (); cr.Restore (); } }
private void OnDrawPage(object obj, Gtk.DrawPageArgs args) { PrintContext context = args.Context; Cairo.Context cr = context.CairoContext; double width = context.Width; cr.Rectangle(0, 0, width, headerHeight); cr.SetSourceRGB(0.8, 0.8, 0.8); cr.FillPreserve(); cr.SetSourceRGB(0, 0, 0); cr.LineWidth = 1; cr.Stroke(); Pango.Layout layout = context.CreatePangoLayout(); Pango.FontDescription desc = Pango.FontDescription.FromString("sans 14"); layout.FontDescription = desc; layout.SetText(fileName); layout.Width = (int)width; layout.Alignment = Pango.Alignment.Center; int layoutWidth, layoutHeight; layout.GetSize(out layoutWidth, out layoutHeight); double textHeight = (double)layoutHeight / (double)pangoScale; cr.MoveTo(width / 2, (headerHeight - textHeight) / 2); Pango.CairoHelper.ShowLayout(cr, layout); string pageStr = String.Format("{0}/{1}", args.PageNr + 1, numPages); layout.SetText(pageStr); layout.Alignment = Pango.Alignment.Right; cr.MoveTo(width - 2, (headerHeight - textHeight) / 2); Pango.CairoHelper.ShowLayout(cr, layout); layout = null; layout = context.CreatePangoLayout(); desc = Pango.FontDescription.FromString("mono"); desc.Size = (int)(fontSize * pangoScale); layout.FontDescription = desc; cr.MoveTo(0, headerHeight + headerGap); int line = args.PageNr * linesPerPage; for (int i = 0; i < linesPerPage && line < numLines; i++) { layout.SetText(lines[line]); Pango.CairoHelper.ShowLayout(cr, layout); cr.RelMoveTo(0, fontSize); line++; } (cr as IDisposable).Dispose(); layout = null; }
protected override bool OnExposeEvent(EventExpose evnt) { if (!IsRealized) { return(true); } using (Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window)) { cr.Save(); cr.Color = new Cairo.Color(0, 0, 0, 0); cr.Operator = Operator.Source; cr.Paint(); cr.Restore(); int width, height; GetSizeRequest(out width, out height); double opacity = Math.Min(1, (DateTime.UtcNow - shown_time).TotalMilliseconds / AnimationTime); if (!curtainDown) { opacity = 1 - opacity; } cr.Rectangle(0, 0, width, height); cr.Color = new Cairo.Color(0, 0, 0, CurtainOpacity * opacity); cr.Fill(); (cr.Target as IDisposable).Dispose(); } return(false); }
public void clip(Context ctx) { foreach (Rectangle r in list) ctx.Rectangle(r); ctx.Clip(); }
void DrawFoldSegment(Cairo.Context ctx, double x, double y, bool isOpen, bool isSelected) { var drawArea = new Cairo.Rectangle(System.Math.Floor(x + (Margin.Width - foldSegmentSize) / 2) + 0.5, System.Math.Floor(y + (Editor.LineHeight - foldSegmentSize) / 2) + 0.5, foldSegmentSize, foldSegmentSize); ctx.Rectangle(drawArea); ctx.SetSourceColor(isOpen ? foldBgGC : foldToggleMarkerBackground); ctx.FillPreserve(); ctx.SetSourceColor(isSelected ? foldLineHighlightedGC : foldLineGC); ctx.Stroke(); ctx.DrawLine(isSelected ? foldLineHighlightedGC : foldToggleMarkerGC, drawArea.X + drawArea.Width * 2 / 10, drawArea.Y + drawArea.Height / 2, drawArea.X + drawArea.Width - drawArea.Width * 2 / 10, drawArea.Y + drawArea.Height / 2); if (!isOpen) { ctx.DrawLine(isSelected ? foldLineHighlightedGC : foldToggleMarkerGC, drawArea.X + drawArea.Width / 2, drawArea.Y + drawArea.Height * 2 / 10, drawArea.X + drawArea.Width / 2, drawArea.Y + drawArea.Height - drawArea.Height * 2 / 10); } }
private void PaintZoomScale(Cairo.Context gc, double width, double height, double centerx, double centery) { if (this.drawZoomScale) { gc.Save(); string s = String.Format("x:{0:##0.0} y:{1:##0.0} *:{2:#0.0#}", this.TranslatedX, this.TranslatedY, this.ScaleFactor); int textWidth, textHeight; Pango.Layout layout = new Pango.Layout(this.PangoContext); layout.FontDescription = this.PangoContext.FontDescription.Copy(); layout.FontDescription.Size = Pango.Units.FromDouble(12.0); layout.SetText(s); Size te = GetTextSize(layout); gc.Color = new Cairo.Color(0.0, 0.0, 0.0, 0.6); gc.Rectangle(width - 7.5d - te.Width, height - te.Height - 5.5d, 7.5d + te.Width, 5.5d + te.Height); gc.Fill(); gc.MoveTo(width - 4.5d - te.Width, height - te.Height - 4.5d); gc.Color = new Cairo.Color(1.0, 1.0, 1.0, 0.6); Pango.CairoHelper.ShowLayout(gc, layout); gc.Fill(); gc.Restore(); } }
protected override bool OnExposeEvent(EventExpose ev) { if (!IsRealized) { return(false); } Cairo.Context cr = CairoHelper.Create(GdkWindow); Gdk.Rectangle rect = ev.Area; cr.Rectangle(rect.X, rect.Y, rect.Width, rect.Height); cr.Clip(); paper.Draw(cr, rect); drawStrokes(cr, rect); // Uncomment this to see the clipping region /* cr.Color = new Cairo.Color(0.0,1.0,0.0,0.5); * cr.Rectangle(rect.X, rect.Y, rect.Width, rect.Height); * cr.Stroke();*/ ((IDisposable)cr).Dispose(); return(true); }
protected override void RenderCoverArt(Cairo.Context cr, ImageSurface image) { if (image == null) { return; } Gdk.Rectangle alloc = RenderAllocation; int asr = ArtworkSizeRequest; int reflect = (int)(image.Height * 0.2); int surface_w = image.Width; int surface_h = image.Height + reflect; int x = alloc.X + alloc.Width - asr; int y = alloc.Y; Surface scene = null; if (!surfaces.TryGetValue(image, out scene)) { scene = CreateScene(cr, image, reflect); surfaces.Add(image, scene); } cr.Rectangle(x, y, asr, alloc.Height); cr.Color = BackgroundColor; cr.Fill(); x += (asr - surface_w) / 2; y += surface_h > asr ? 0 : (asr - surface_h) / 2; cr.SetSource(scene, x, y); cr.Paint(); }
public override void Run() { ICollection<double> chapters = this.Theory.Chapters; StripCanvasSize scs = this.Manager.GenerateStripCanvasSize (chapters.Count); double dw = scs.CanvasSize.Width; double dh = scs.CanvasSize.Height; using (PdfSurface surface = new PdfSurface (this.Manager.OutputFile, scs.TotalWidth, scs.TotalHeight)) { using (Context ctx = new Context (surface)) { int index = 0x00; IPoint3 p; foreach (double chapter in chapters) { p = scs.GetCanvasOffset (index); ctx.Save (); ctx.Translate (p.X, p.Y); ctx.Rectangle (0.0d, 0.0d, dw, dh); ctx.Stroke (); this.Theory.Time = chapter; CairoEngine engine = new CairoEngine (this.Theory); engine.Context = ctx; engine.Process (); ctx.Restore (); index++; } } } }
//private double last_invalidate_value = -1; /*private void Invalidate () * { * double current_value = (IsValueUpdatePending ? PendingValue : Value); * * // FIXME: Something is wrong with the updating below causing an * // invalid region when IsValueUpdatePending is true, so when * // that is the case for now, we trigger a full invalidation * if (last_invalidate_value < 0 || IsValueUpdatePending) { * last_invalidate_value = current_value; * InvalidateRender (); * return; * } * * double max = Math.Max (last_invalidate_value, current_value) * RenderSize.Width; * double min = Math.Min (last_invalidate_value, current_value) * RenderSize.Width; * * Rect region = new Rect ( * InvalidationRect.X + min, * InvalidationRect.Y, * (max - min) + 2 * ThrobberSize, * InvalidationRect.Height * ); * * last_invalidate_value = current_value; * InvalidateRender (region); * }*/ /*protected override Rect InvalidationRect { * get { return new Rect ( * -Margin.Left - ThrobberSize / 2, * -Margin.Top, * Allocation.Width + ThrobberSize, * Allocation.Height); * } * }*/ protected override void ClippedRender(Cairo.Context cr) { double throbber_r = ThrobberSize / 2.0; double throbber_x = Math.Round(RenderSize.Width * (IsValueUpdatePending ? PendingValue : Value)); double throbber_y = (Allocation.Height - ThrobberSize) / 2.0 - Margin.Top + throbber_r; double bar_w = RenderSize.Width * Value; Theme.Widget.StyleContext.Save(); Theme.Widget.StyleContext.AddClass("entry"); Theme.Widget.StyleContext.RenderBackground(cr, 0, 0, RenderSize.Width, RenderSize.Height); var color = CairoExtensions.GdkRGBAToCairoColor(Theme.Widget.StyleContext.GetColor(Gtk.StateFlags.Active)); Theme.Widget.StyleContext.Restore(); // TODO get Dark color Color fill_color = CairoExtensions.ColorShade(color, 0.4); Color light_fill_color = CairoExtensions.ColorShade(color, 0.3); fill_color.A = 1.0; light_fill_color.A = 1.0; using (var fill = new LinearGradient(0, 0, 0, RenderSize.Height)) { fill.AddColorStop(0, light_fill_color); fill.AddColorStop(0.5, fill_color); fill.AddColorStop(1, light_fill_color); cr.Rectangle(0, 0, bar_w, RenderSize.Height); cr.SetSource(fill); cr.Fill(); cr.SetSourceColor(fill_color); cr.Arc(throbber_x, throbber_y, throbber_r, 0, Math.PI * 2); cr.Fill(); } }
protected override void CreateActiveTexture(Clutter.CairoTexture texture, int with_state) { texture.Clear(); Cairo.Context context = texture.Create(); double lwidth = 1; double hlwidth = lwidth * 0.5; //Draw outline rectangles: DrawSmallCovers(context, texture.Width, texture.Height, lwidth); //Draw stop icon: double dim = Math.Min(texture.Width * 0.6 - hlwidth, texture.Height * 0.6 - hlwidth); context.Rectangle(texture.Width * 0.4, texture.Height * 0.4, dim, dim); context.LineWidth = lwidth; double sat = (with_state == 0 ? 0.4 : (with_state == 1 ? 0.6 : 0.8)); context.SetSourceRGBA(sat, sat, sat, 1.0); context.FillPreserve(); context.SetSourceRGB(1.0, 1.0, 1.0); context.Stroke(); ((IDisposable)context.Target).Dispose(); ((IDisposable)context).Dispose(); }
public void Render(DrawingArea area, SettingsModel settings) { var width = area.Allocation.Width; var height = area.Allocation.Height; var kaleidoscope = _factory.Get (settings.Type); var rootNode = kaleidoscope.Generate ( settings.GeometyWidth, settings.ImageUri, width, height); ImageSurface surface = new ImageSurface(Format.Argb32, width, height); using (var context = new Context (surface)) { context.Translate(width / 2, height / 2); rootNode.Render (context); } rootNode.Geometry.Dispose (); using (Context context = Gdk.CairoHelper.Create (area.GdkWindow)) { context.Rectangle(0, 0, width, height); context.SetSource(surface); context.Fill(); context.GetTarget ().Dispose (); } surface.Dispose (); }
private void RenderNetwork(Network network, Cairo.Context gc) { lock (network) { Rectangle rect = (Rectangle)network.Properties["rect"]; SizeD titleSize = CalculateNetworkTitleSize(network, gc); Hashtable nodegroups = network.Properties["nodegroups"] as Hashtable; gc.Save(); // Draw network box gc.Color = networkBG; gc.Rectangle(rect); gc.Fill(); // Draw title, 2px/2px offset from top/left corner gc.Color = white; gc.MoveTo(rect.X + 2, rect.Y + 2 /* + titleSize.Height */); Pango.Layout layout = new Pango.Layout(this.PangoContext); layout.FontDescription = this.PangoContext.FontDescription.Copy(); layout.FontDescription.Size = Pango.Units.FromDouble(NetworkNameFontSize); layout.SetText(network.NetworkName); Pango.CairoHelper.ShowLayout(gc, layout); foreach (NodeGroup ng in nodegroups.Values) { RenderNodeGroup(ng, network, gc); } gc.Restore(); RenderConnections(network, gc); } }
static void draw(Cairo.Context gr, int width, int height) { int w, h; ImageSurface image; gr.Scale(width, height); gr.LineWidth = 0.04; gr.Arc(0.5, 0.5, 0.3, 0, 2 * M_PI); gr.Clip(); gr.NewPath(); image = new ImageSurface("data/e.png"); w = image.Width; h = image.Height; gr.Scale(1.0 / w, 1.0 / h); image.Show(gr, 0, 0); image.Destroy(); gr.Arc(0.5, 0.5, 0.3, 0, 2 * M_PI); gr.Clip(); gr.NewPath(); gr.Rectangle(new PointD(0, 0), 1, 1); gr.Fill(); gr.Color = new Color(0, 1, 0, 1); gr.MoveTo(new PointD(0, 0)); gr.LineTo(new PointD(1, 1)); gr.MoveTo(new PointD(1, 0)); gr.LineTo(new PointD(0, 1)); gr.Stroke(); }
public void DrawHist(TimeList<Complex[]> list, double t) { using (Context context = new Context(Surface)) { context.Rectangle(0, 0, Width, Height); context.Color = Background; context.Fill(); int index = list.Index (t); int times = 30; double xl = (double)(Width - 60) / N; double yl = (double)Height / times; Complex[] points; Color c; int ii; for (int i = index; i >= Math.Max(0, index - times); i--) { points = list.Get (i); N = points.Length; ii = index - i; for (int j = 0; j < points.Length; j++) { DrawHistArea (context, xl, yl, ii, j, _valueExtractor(points [j])); } } } DrawExpose (null, null); }
public static void PrintMonthHeader(Cairo.Context cr, int year, int month, bool outputMonthHeaderRect = false) { if (outputMonthHeaderRect) { var MonthHeaderRect = new Rectangle( MarginLeft, MarginUp, ContentWidth, MonthHeader); cr.Rectangle(MonthHeaderRect); } var Month = MonthNames[month]; cr.SetFontSize(MonthHeader * 0.8); var te = cr.TextExtents(Month); cr.MoveTo(MarginLeft - te.XBearing, MarginUp + MonthHeader - ((MonthHeader - te.Height) / 2) - (te.Height + te.YBearing)); cr.ShowText(Month); te = cr.TextExtents(year.ToString()); cr.MoveTo(width - MarginRight - te.Width - te.XBearing, MarginUp + MonthHeader - ((MonthHeader - te.Height) / 2) - (te.Height + te.YBearing)); cr.ShowText(year.ToString()); }
protected override bool OnExposeEvent(Gdk.EventExpose evnt) { bool idle = incoming_track == null && current_track == null; if (!Visible || !IsMapped || (idle && !CanRenderIdle)) { return(true); } Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window); foreach (Gdk.Rectangle damage in evnt.Region.GetRectangles()) { cr.Rectangle(damage.X, damage.Y, damage.Width, damage.Height); cr.Clip(); if (idle) { RenderIdle(cr); } else { RenderAnimation(cr); } cr.ResetClip(); } CairoExtensions.DisposeContext(cr); return(true); }
public override void Draw(Cairo.Context cr, double xPos, double yPos, PrintLayer layer) { if (_regionSettings != null) { xPos += _regionSettings.Indent; if (layer == PrintLayer.Background && _regionSettings.HasBackground) { TextExtents extents = GetExtents(cr); // If there is a background, draw it here. cr.SetSourceRGB(_regionSettings.Background.Red, _regionSettings.Background.Green, _regionSettings.Background.Blue); cr.Rectangle(xPos , yPos - extents.Height - extents.YAdvance , extents.Width - _regionSettings.Indent , extents.Height + extents.YAdvance); cr.Fill(); } else if (layer == PrintLayer.Text) { xPos += _regionSettings.PaddingLeft; yPos -= _regionSettings.PaddingBottom; } } _children.VerticalDraw(cr, xPos, yPos, layer); }
void Draw(Context cr, int width, int height) { cr.LineWidth = 1.0; cr.Color = new Color(1.0, 1.0, 1.0); cr.Rectangle(0, 0, width, height); cr.Fill(); cr.Save(); cr.Scale(scale_factor, scale_factor); try { if(diagram != null) { DiagramRenderer dr = new DiagramRenderer(cr, width, height, diagram); cr.Color = new Color(0.0, 0.0, 0.0); dr.Render(); dr.Draw(); } } catch { error_counter++; } cr.Restore(); }
public virtual void Draw(Context cr, Gdk.Rectangle clip) { cr.Rectangle(clip.X, clip.Y, clip.Width, clip.Height); cr.Color = BackgroundColor; cr.Fill(); cr.Stroke(); }
static void draw(Cairo.Context gr, int width, int height) { gr.Scale(width, height); gr.LineWidth = 0.04; LinearGradient pat; pat = new LinearGradient(0.0, 0.0, 0.0, 1.0); pat.AddColorStop(1, new Color(0, 0, 0, 1)); pat.AddColorStop(0, new Color(1, 1, 1, 1)); gr.Rectangle(new PointD(0, 0), 1, 1 ); gr.Pattern = pat; gr.Fill(); pat.Destroy(); RadialGradient pat2 = new RadialGradient(0.45, 0.4, 0.1, 0.4, 0.4, 0.5); pat2.AddColorStop(0, new Color(1, 1, 1, 1)); pat2.AddColorStop(1, new Color(0, 0, 0, 1)); gr.Pattern = pat2; gr.Arc(0.5, 0.5, 0.3, 0, 2 * M_PI); gr.Fill(); pat2.Destroy(); }
public override void Apply (CanvasItem item, Context cr) { int steps = ShadowSize; double opacity_step = ShadowOpacity / ShadowSize; Color color = new Color (0, 0, 0); double width = Math.Round (item.Allocation.Width); double height = Math.Round (item.Allocation.Height); if (Fill != null) { cr.Rectangle (shadow_size, shadow_size, width - ShadowSize * 2, height - ShadowSize * 2); Fill.Apply (cr); cr.Fill (); } cr.LineWidth = 1.0; for (int i = 0; i < steps; i++) { CairoExtensions.RoundedRectangle (cr, i + 0.5, i + 0.5, (width - 2 * i) - 1, (height - 2 * i) - 1, steps - i); color.A = opacity_step * (i + 1); cr.Color = color; cr.Stroke (); } }
public override void Draw(Cairo.Context cr, double xPos, double yPos, PrintLayer layer) { if (layer == PrintLayer.Text) { cr.SetFont(_fontInfo); yPos -= _extents.YAdvance; if (_fontInfo.Underline == true) { TextExtents extents = GetExtents(cr); cr.Rectangle(xPos , yPos - _fontInfo.UnderlineHeight , extents.Width , _fontInfo.UnderlineHeight); cr.Fill(); yPos -= _fontInfo.UnderlineHeight + 2.0; } cr.MoveTo(xPos, yPos); cr.ShowText(_text); } }
public void clear(Context ctx) { foreach (Rectangle r in list) ctx.Rectangle(r); ctx.Operator = Operator.Clear; ctx.Fill(); ctx.Operator = Operator.Over; }
protected void OnRender(Context cr, int width, int height) { cr.Save(); cr.SetSourceRGBA(1, 0, 0, mTick*0.1); cr.Rectangle(0, 0, width, height); cr.Fill(); cr.Restore(); }
public override void Draw(Context context) { RectangleD rect = DisplayBox; context.LineWidth = LineWidth; context.Rectangle (GdkCairoHelper.CairoRectangle (rect)); context.Color = FillColor; context.FillPreserve (); context.Color = LineColor; context.Stroke (); }
public void clearAndClip(Context ctx) { if (list.Count == 0) return; foreach (Rectangle r in list) ctx.Rectangle(r); ctx.ClipPreserve(); ctx.Operator = Operator.Clear; ctx.Fill(); ctx.Operator = Operator.Over; }
public override void LayoutOutline(Node node, Context context) { ImageNode image = node as ImageNode; ImageSurface surfaceCache = image.Data as ImageSurface; if (surfaceCache == null) { // will improve with CGLayer surfaces surfaceCache = new ImageSurface (image.File); } context.Rectangle (0, 0, image.Width, image.Height); }
public override void BasicDraw (Context context) { RectangleD displayBox = DisplayBox; context.LineWidth = LineWidth; context.Save (); displayBox.OffsetDot5 (); context.Rectangle (GdkCairoHelper.CairoRectangle(displayBox)); context.Restore (); context.Color = FillColor; context.FillPreserve (); context.Color = LineColor; context.Stroke (); }
public override void BasicDrawSelected(Context context) { if (Text != "") { return; } context.LineWidth = LineWidth; Color c = LineColor; c.A = 0.5; context.Color = c; RectangleD r = DisplayBox; r.OffsetDot5(); context.Rectangle(GdkCairoHelper.CairoRectangle(r)); context.Stroke(); }
private ImageSurface copySurfacePart(ImageSurface surf, Gdk.Rectangle dest_rect) { ImageSurface tmp_surface = new ImageSurface (Format.Argb32, dest_rect.Width, dest_rect.Height); using (Context g = new Context (tmp_surface)) { g.Operator = Operator.Source; g.SetSourceSurface (surf, -dest_rect.Left, -dest_rect.Top); g.Rectangle (new Rectangle (0, 0, dest_rect.Width, dest_rect.Height)); g.Fill (); } //Flush to make sure all drawing operations are finished tmp_surface.Flush (); return tmp_surface; }
public override void LayoutOutline(Node node, Context context) { LabelNode label = node as LabelNode; Cairo.Engine engine = node.Canvas.Engine as Cairo.Engine; if (label.ClipInputToTextExtents) { var options = new TextOptions (); options.Color = label.Color.MultiplyAlpha (node.Opacity); options.MaxWidth = label.Width; var size = GetExtents (label.Text, options, engine); double x = label.Width - size.Width; x = (int) (x * label.XAlign); double y = label.Height - size.Height; y = (int) (y * label.YAlign); context.Rectangle (x, y, size.Width, size.Height); } else { context.Rectangle (0, 0, label.Width, label.Height); } }
public void CreatePng () { const int Width = 480; const int Height = 160; const int CheckSize = 10; const int Spacing = 2; // Create an Image-based surface with data stored in ARGB32 format and a context, // "using" is used here to ensure that they are Disposed once we are done using (ImageSurface surface = new ImageSurface (Format.ARGB32, Width, Height)) using (Context cr = new Cairo.Context (surface)) { // Start drawing a checkerboard int i, j, xcount, ycount; xcount = 0; i = Spacing; while (i < Width) { j = Spacing; ycount = xcount % 2; // start with even/odd depending on row while (j < Height) { if (ycount % 2 != 0) cr.SetSourceRGB (1, 0, 0); else cr.SetSourceRGB (1, 1, 1); // If we're outside the clip, this will do nothing. cr.Rectangle (i, j, CheckSize, CheckSize); cr.Fill (); j += CheckSize + Spacing; ++ycount; } i += CheckSize + Spacing; ++xcount; } // Select a font to draw with cr.SelectFontFace ("serif", FontSlant.Normal, FontWeight.Bold); cr.SetFontSize (64.0); // Select a color (blue) cr.SetSourceRGB (0, 0, 1); // Draw cr.MoveTo (20, 100); cr.ShowText ("Hello, World"); surface.WriteToPng ("test.png"); } }
protected void OnCustomWidgetChanged (Gtk.Widget widget) { OnCustomWidgetApply (widget); using (ImageSurface surface = new ImageSurface (Format.ARGB32, 360, 254)) { using (Context gr = new Context (surface)) { gr.Color = new Color (1, 1, 1); gr.Rectangle (0, 0, 360, 254); gr.Fill (); using (Gdk.Pixbuf pixbuf = Gdk.Pixbuf.LoadFromResource ("flower.png")) { DrawImage (gr, pixbuf,0, 0, 360, 254); } } (widget as CustomPrintWidget).PreviewImage.Pixbuf = CreatePixbuf (surface); } }
public override void Render(Context cr) { if (!CanResize) { return; } var selected_color = CairoExtensions.GdkColorToCairoColor (Window.Style.Dark (StateType.Active)); var grad = new LinearGradient (0, 0, 0, Allocation.Height); selected_color.A = 0.4; grad.AddColorStop (0, selected_color); selected_color.A = 1.0; grad.AddColorStop (1, selected_color); cr.Pattern = grad; cr.LineWidth = 1.0; cr.Rectangle (0.5, 0.5, Allocation.Width - 1, Allocation.Height - 1); cr.Stroke (); selected_color.A = 0.5; cr.Color = selected_color; double handle_size = 8; double ty = 0.5 + Allocation.Height - handle_size - 3; double tx = 0.5 + (Window.Direction == TextDirection.Ltr ? Allocation.Width - handle_size - 3 : 3); cr.Translate (tx, ty); for (double i = 0; i < 3; i++) { if (Window.Direction == TextDirection.Ltr) { cr.MoveTo (i * 3, handle_size); cr.LineTo (handle_size, i * 3); } else { cr.MoveTo (0, i * 3); cr.LineTo (handle_size - i * 3, handle_size); } } cr.Stroke (); cr.Translate (-tx, -ty); }
public static Gtk.Image create_big_starred_image(string pic_path) { using (Cairo.ImageSurface img_surface = new ImageSurface(pic_path)) { using (Cairo.ImageSurface surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, img_surface.Width + 2, img_surface.Height + 2)) { using (Cairo.Context context = new Context(surface)) { Gdk.Pixbuf tmp_pixbuf = new Gdk.Pixbuf(pic_path); if (!tmp_pixbuf.HasAlpha) { // img_surface.Format not available... context.Rectangle(0, 0, img_surface.Width+2, img_surface.Height+2); context.Fill(); context.Stroke(); } context.SetSource(img_surface, 1, 1); context.Paint(); // evil hack because the interface to cairo is pretty bad Assembly asm = Assembly.GetCallingAssembly(); Stream s = asm.GetManifestResourceStream("big_star.png"); FileStream fs = new System.IO.FileStream(tmp_image_path, FileMode.Create); for (int i = 0; i < s.Length; ++i) fs.WriteByte((byte)s.ReadByte()); fs.Close(); using (Cairo.ImageSurface star_surface = new ImageSurface(tmp_image_path)) { System.IO.File.Delete(tmp_image_path); context.SetSource(star_surface, img_surface.Width-star_surface.Width, img_surface.Height-star_surface.Height); context.Paint(); surface.WriteToPng(tmp_image_path); Gtk.Image img = new Gtk.Image(tmp_image_path); System.IO.File.Delete(tmp_image_path); return img; } } } } }
private void DrawAxes(Context context, double min, double max) { context.Rectangle(0, 0, Width, Height); context.Color = Background; context.Fill(); context.LineWidth = 1; context.SetSourceRGB(0.0, 0.0, 0.0); context.MoveTo (0, Height / 2); context.LineTo (Width, Height / 2); context.StrokePreserve(); context.MoveTo (Width / 2, 0); context.LineTo (Width / 2, Height); context.StrokePreserve(); KeyValuePair<double, string>[] ax = _axis.AxisSteps (min, max); double y; foreach (var a in ax) { y = a.Key / _axis.YLimUp * Height / 2 + Height / 2; context.MoveTo (Width / 2 - 6, y); context.LineTo (Width / 2 + 6, y); context.StrokePreserve(); context.MoveTo (y, Height / 2 - 6); context.LineTo (y, Height / 2 + 6); context.StrokePreserve(); if (a.Key != 0) { context.MoveTo (Width / 2 - 10, Height - (y - 1)); _axis.Text (context, a.Value, HorizontalTextAlignment.Right); context.MoveTo (y - 1, Height / 2 + 10); _axis.Text (context, a.Value, HorizontalTextAlignment.Center, VerticalTextAlignment.Top); } else { //context.MoveTo (Width / 2 + 5, Height / 2 + 5); //_axis.Text (context, a.Value, HorizontalTextAlignment.Left, VerticalTextAlignment.Top); } } }
public static void Draw(Context grw, RectangleElement rect) { if (rect.Foregraund != null) { grw.SetSourceRGBA ( rect.Foregraund.Red, rect.Foregraund.Green, rect.Foregraund.Blue, rect.Alpha); } grw.Rectangle ( new Rectangle ( rect.LeftBottom.GeometryX, rect.LeftBottom.GeometryY, rect.GeometryWidth, rect.GeometryHeight)); grw.StrokePreserve(); grw.Fill(); }
protected override bool OnExposed(Context cr, Rectangle area) { cr.Save(); if(!base.OnExposed(cr, area)) { cr.Color = new Color(1.0, 0.0, 1.0); cr.Rectangle(new Rectangle(2.0, 2.0, Allocation.Width - 4.0, Allocation.Height - 4.0)); cr.LineWidth = 4.0; cr.LineJoin = LineJoin.Round; cr.Stroke(); cr.SetFontSize(20.0); cr.SelectFontFace("Librarian", FontSlant.Normal, FontWeight.Bold); cr.Translate(0.0, Allocation.Height / 2); cr.ShowText(type.ToString()); cr.Restore(); return true; } cr.Restore(); return true; }
private void Form1_Shown(object sender, EventArgs e) { Debug.WriteLine("Form1_Shown"); surface = new Win32Surface(this.CreateGraphics().GetHdc()); context = new Context(surface); textFormat = DWriteCairo.CreateTextFormat( "Consolas", FontWeight.Normal, FontStyle.Normal, FontStretch.Normal, 12); textFormat.TextAlignment = TextAlignment.Center; float left, top, width, height; // get actual size of the text var measureLayout = DWriteCairo.CreateTextLayout(s, textFormat, 4096, 4096); measureLayout.GetRect(out left, out top, out width, out height); measureLayout.Dispose(); // build text context against the size and format textLayout = DWriteCairo.CreateTextLayout(s, textFormat, (int)Math.Ceiling(width), (int)Math.Ceiling(height)); Debug.WriteLine("showing layout"); Path path = DWriteCairo.RenderLayoutToCairoPath(context, textLayout); context.AppendPath(path); context.Fill(); textLayout.GetRect(out left, out top, out width, out height); textRect = new System.Drawing.RectangleF(left, top, width, height); context.Rectangle(left, top, width, height); context.Stroke(); context.GetTarget().Flush(); }