118
public static Rectangle DrawPolygonal (this Context g, PointD[] points, Color color)
120
Random rand=new Random();
123
g.MoveTo (points [0]);
124
foreach (var point in points) {
125
g.LineTo (point.X - rand.NextDouble()*0, point.Y);
131
Rectangle dirty = g.StrokeExtents ();
140
public static Rectangle FillPolygonal (this Context g, PointD[] points, Color color)
144
g.MoveTo (points [0]);
145
foreach (var point in points)
150
Rectangle dirty = g.StrokeExtents ();
118
158
public static Rectangle FillStrokedRectangle (this Context g, Rectangle r, Color fill, Color stroke, int lineWidth)
416
public static Rectangle DrawLine (this Context g, PointD p1, PointD p2, Color color, int lineWidth)
418
// Put it on a pixel line
420
p1 = new PointD (p1.X - 0.5, p1.Y - 0.5);
424
g.MoveTo (p1.X, p1.Y);
425
g.LineTo (p2.X, p2.Y);
428
g.LineWidth = lineWidth;
429
g.LineCap = LineCap.Square;
431
Rectangle dirty = g.StrokeExtents ();
376
439
public static void DrawPixbuf (this Context g, Gdk.Pixbuf pixbuf, Point dest)
452
515
return new Color (dstPtr->R / 255f, dstPtr->G / 255f, dstPtr->B / 255f, dstPtr->A / 255f);
518
public unsafe static void SetPixel (this Cairo.ImageSurface surf, int x, int y, Color color)
520
ColorBgra* dstPtr = (ColorBgra*)surf.DataPtr;
522
dstPtr += (x) + (y * surf.Width);
524
dstPtr->R = (byte)(color.R * 255);
525
dstPtr->G = (byte)(color.G * 255);
526
dstPtr->B = (byte)(color.B * 255);
527
dstPtr->A = (byte)(color.A * 255);
530
public unsafe static ColorBgra GetColorBgra (this Cairo.ImageSurface surf, int x, int y)
532
ColorBgra* dstPtr = (ColorBgra*)surf.DataPtr;
534
dstPtr += (x) + (y * surf.Width);
539
public static ColorBgra ToColorBgra (this Cairo.Color color)
541
ColorBgra c = new ColorBgra ();
543
c.R = (byte)(color.R * 255);
544
c.G = (byte)(color.G * 255);
545
c.B = (byte)(color.B * 255);
546
c.A = (byte)(color.A * 255);
551
public static Cairo.Color ToCairoColor (this ColorBgra color)
553
Cairo.Color c = new Cairo.Color ();
555
c.R = color.R / 255d;
556
c.G = color.G / 255d;
557
c.B = color.B / 255d;
558
c.A = color.A / 255d;
563
public static Gdk.Color ToGdkColor (this ColorBgra color)
565
Gdk.Color c = new Gdk.Color (color.R, color.G, color.B);
455
570
public static string ToString2 (this Cairo.Color c)
457
572
return string.Format ("R: {0} G: {1} B: {2} A: {3}", c.R, c.G, c.B, c.A);
484
public static Rectangle GetBounds (this Path path)
599
public static Gdk.Rectangle GetBounds (this Path path)
488
603
using (Context g = new Context (PintaCore.Layers.CurrentLayer.Surface)) {
489
604
g.AppendPath (PintaCore.Layers.SelectionPath);
606
// We don't want the bounding box to include a stroke width
607
// of 1, but setting it to 0 returns an empty rectangle. Set
608
// it to a sufficiently small width and rounding takes care of it
490
610
rect = g.StrokeExtents ();
493
return new Rectangle (rect.X, rect.Y, rect.Width - rect.X, rect.Height - rect.Y);
613
return new Gdk.Rectangle ((int)rect.X, (int)rect.Y, (int)rect.Width - (int)rect.X, (int)rect.Height - (int)rect.Y);
496
616
public static Gdk.Color ToGdkColor (this Cairo.Color color)
518
643
ColorBgra* dstPtr = (ColorBgra*)surf.DataPtr;
520
645
dstPtr += (x) + (y * surf.Width);
650
public static unsafe ColorBgra* GetPointAddressUnchecked (this ImageSurface surf, ColorBgra* srcDataPtr, int srcWidth, int x, int y)
652
ColorBgra* dstPtr = srcDataPtr;
654
dstPtr += (x) + (y * srcWidth);
659
public static unsafe ColorBgra GetPointUnchecked (this ImageSurface surf, int x, int y)
661
ColorBgra* dstPtr = (ColorBgra*)surf.DataPtr;
663
dstPtr += (x) + (y * surf.Width);
668
// This isn't really an extension method, since it doesn't use
669
// the passed in argument, but it's nice to have the same calling
670
// convention as the uncached version. If you can use this one
671
// over the other, it is much faster in tight loops (like effects).
672
public static unsafe ColorBgra GetPointUnchecked (this ImageSurface surf, ColorBgra* srcDataPtr, int srcWidth, int x, int y)
674
ColorBgra* dstPtr = srcDataPtr;
676
dstPtr += (x) + (y * srcWidth);
681
public static unsafe ColorBgra* GetRowAddressUnchecked (this ImageSurface surf, int y)
683
ColorBgra* dstPtr = (ColorBgra*)surf.DataPtr;
685
dstPtr += y * surf.Width;
690
public static unsafe ColorBgra* GetRowAddressUnchecked (this ImageSurface surf, ColorBgra* srcDataPtr, int srcWidth, int y)
692
ColorBgra* dstPtr = srcDataPtr;
694
dstPtr += y * srcWidth;
699
public static unsafe ColorBgra *GetPointAddress (this ImageSurface surf, int x, int y)
701
if (x < 0 || x >= surf.Width)
702
throw new ArgumentOutOfRangeException ("x", "Out of bounds: x=" + x.ToString ());
704
return surf.GetPointAddressUnchecked (x, y);
707
public static unsafe ColorBgra* GetPointAddress (this ImageSurface surf, Gdk.Point point)
709
return surf.GetPointAddress (point.X, point.Y);
712
public static Gdk.Rectangle GetBounds (this ImageSurface surf)
714
return new Gdk.Rectangle (0, 0, surf.Width, surf.Height);
717
public static Gdk.Size GetSize (this ImageSurface surf)
719
return new Gdk.Size (surf.Width, surf.Height);