protected override Gdk.Rectangle OnMouseMove (Context g, Color strokeColor, ImageSurface surface, int x, int y, int lastX, int lastY) { // Cairo does not support a single-pixel-long single-pixel-wide line if (x == lastX && y == lastY && g.LineWidth == 1 && PintaCore.Workspace.ActiveWorkspace.PointInCanvas (new PointD(x,y))) { surface.Flush (); ColorBgra source = surface.GetColorBgraUnchecked (x, y); source = UserBlendOps.NormalBlendOp.ApplyStatic (source, strokeColor.ToColorBgra ()); surface.SetColorBgra (source, x, y); surface.MarkDirty (); return new Gdk.Rectangle (x - 1, y - 1, 3, 3); } g.MoveTo (lastX + 0.5, lastY + 0.5); g.LineTo (x + 0.5, y + 0.5); g.StrokePreserve (); Gdk.Rectangle dirty = g.FixedStrokeExtents ().ToGdkRectangle (); // For some reason (?!) we need to inflate the dirty // rectangle for small brush widths in zoomed images dirty.Inflate (1, 1); return dirty; }
protected override Gdk.Rectangle OnMouseMove (Context g, Color strokeColor, ImageSurface surface, int x, int y, int lastX, int lastY) { int dx = x - lastX; int dy = y - lastY; double px = Math.Cos (theta) * dx - Math.Sin (theta) * dy; double py = Math.Sin (theta) * dx + Math.Cos (theta) * dy; g.MoveTo (lastX - px, lastY - py); g.LineTo (lastX + px, lastY + py); g.LineTo (x + px, y + py); g.LineTo (x - px, y - py); g.LineTo (lastX - px, lastY - py); g.StrokePreserve (); return g.FixedStrokeExtents ().ToGdkRectangle (); }
protected override Gdk.Rectangle OnMouseMove (Context g, Color strokeColor, ImageSurface surface, int x, int y, int lastX, int lastY) { int line_width = (int)g.LineWidth; int size; // we want a minimum size of 2 for the splatter (except for when the brush width is 1), since a splatter of size 1 is very small if (line_width == 1) { size = 1; } else { size = Random.Next (2, line_width); } Rectangle r = new Rectangle (x - Random.Next (-15, 15), y - Random.Next (-15, 15), size, size); double rx = r.Width / 2; double ry = r.Height / 2; double cx = r.X + rx; double cy = r.Y + ry; double c1 = 0.552285; g.Save (); g.MoveTo (cx + rx, cy); g.CurveTo (cx + rx, cy - c1 * ry, cx + c1 * rx, cy - ry, cx, cy - ry); g.CurveTo (cx - c1 * rx, cy - ry, cx - rx, cy - c1 * ry, cx - rx, cy); g.CurveTo (cx - rx, cy + c1 * ry, cx - c1 * rx, cy + ry, cx, cy + ry); g.CurveTo (cx + c1 * rx, cy + ry, cx + rx, cy + c1 * ry, cx + rx, cy); g.ClosePath (); Rectangle dirty = g.FixedStrokeExtents (); g.Fill (); g.Restore (); return dirty.ToGdkRectangle (); }
public static Gdk.Rectangle GetBounds(this Path path) { Rectangle rect; using (Context g = new Context (PintaCore.Layers.CurrentLayer.Surface)) { g.AppendPath (path); // We don't want the bounding box to include a stroke width // of 1, but setting it to 0 returns an empty rectangle. Set // it to a sufficiently small width and rounding takes care of it g.LineWidth = .01; rect = g.FixedStrokeExtents (); } int x = (int)Math.Round (rect.X); int y = (int)Math.Round (rect.Y); int w = (int)Math.Round (rect.Width); int h = (int)Math.Round (rect.Height); return new Gdk.Rectangle (x, y, w, h); }