Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

SKRegion: Add constructors and methods for easier interaction with SKRectI and SKPath #788

Merged
merged 1 commit into from Mar 13, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to鈥
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -20,6 +20,18 @@ public SKRegion(SKRegion region)
{
}

public SKRegion(SKRectI rect)
: this(SkiaApi.sk_region_new2(region.Handle), true)
{
SetRect(rect);
}

public SKRegion(SKPath path)
: this(SKRectI.Ceiling(path.Bounds))
{
SetPath(path);
}

public SKRectI Bounds {
get {
SkiaApi.sk_region_get_bounds (Handle, out var rect);
@@ -44,6 +56,16 @@ public bool Contains(int x, int y)
return SkiaApi.sk_region_contains2(Handle, x, y);
}

public bool Intersects(SKPath path)
{
if (path == null)
throw new ArgumentNullException(nameof(path));
using (SKRegion pathRegion = new SKRegion(path, true))
{
return SkiaApi.sk_region_intersects(Handle, pathRegion.Handle);
}
}

public bool Intersects(SKRegion region)
{
if (region == null)
@@ -80,18 +102,13 @@ public bool SetPath(SKPath path, SKRegion clip)
public bool SetPath(SKPath path)
{
if (path == null)
throw new ArgumentNullException (nameof (path));
throw new ArgumentNullException(nameof(path));

using (var clip = new SKRegion()) {
var rect = path.Bounds;
if (!rect.IsEmpty) {
var recti = new SKRectI (
(int)rect.Left,
(int)rect.Top,
(int)Math.Ceiling (rect.Right),
(int)Math.Ceiling (rect.Bottom));
clip.SetRect (recti);
}
using (var clip = new SKRegion())
{
var rect = SKRectI.Ceiling(path.Bounds);
if (!rect.IsEmpty)
clip.SetRect(rect);

return SkiaApi.sk_region_set_path(Handle, path.Handle, clip.Handle);
}
@@ -111,5 +128,13 @@ public bool Op(SKRegion region, SKRegionOperation op)
{
return SkiaApi.sk_region_op2(Handle, region.Handle, op);
}

public bool Op(SKPath path, SKRegionOperation op)
{
using (SKRegion pathRegion = new SKRegion(path, true))
{
return SkiaApi.sk_region_op2(Handle, pathRegion.Handle, op);
}
}
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can鈥檛 perform that action at this time.