-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from ChasakisD/feature-shapes
Add Circle Shape
- Loading branch information
Showing
12 changed files
with
155 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/XamarinBackgroundKit.Android/PathProviders/CirclePathProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using Android.Graphics; | ||
using XamarinBackgroundKit.Shapes; | ||
|
||
namespace XamarinBackgroundKit.Android.PathProviders | ||
{ | ||
public class CirclePathProvider : BasePathProvider<Circle> | ||
{ | ||
public override bool IsBorderSupported => true; | ||
|
||
public override void CreatePath(Path path, Circle shape, int width, int height) | ||
{ | ||
var radius = Math.Min(width, height) / 2f; | ||
|
||
path.AddCircle(width / 2f, height / 2f, radius, Path.Direction.Ccw); | ||
} | ||
|
||
public override void CreateBorderedPath(Path path, Circle shape, int width, int height, int strokeWidth) | ||
{ | ||
var radius = (Math.Min(width, height) - strokeWidth) / 2f; | ||
|
||
path.AddCircle(width / 2f, height / 2f, radius, Path.Direction.Ccw); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/XamarinBackgroundKit.iOS/PathProviders/CirclePathProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System; | ||
using CoreGraphics; | ||
using UIKit; | ||
using XamarinBackgroundKit.Shapes; | ||
|
||
namespace XamarinBackgroundKit.iOS.PathProviders | ||
{ | ||
public class CirclePathProvider : BasePathProvider<Circle> | ||
{ | ||
public override bool IsBorderSupported => true; | ||
|
||
public override void CreatePath(Circle shape, CGRect bounds) | ||
{ | ||
using (var bezierPath = GetCirclePath(bounds)) | ||
{ | ||
Path = bezierPath.CGPath; | ||
} | ||
} | ||
|
||
public override void CreateBorderedPath(Circle shape, CGRect bounds, double strokeWidth) | ||
{ | ||
using (var bezierPath = GetCirclePath(bounds, (float)strokeWidth)) | ||
{ | ||
BorderPath = bezierPath.CGPath; | ||
} | ||
} | ||
|
||
private static UIBezierPath GetCirclePath(CGRect bounds, float borderWidth = 0f) | ||
{ | ||
var startX = bounds.Left; | ||
var endX = bounds.Right; | ||
var startY = bounds.Top; | ||
var endY = bounds.Bottom; | ||
|
||
var delta = (float)Math.Abs(bounds.Width - bounds.Height) / 2f; | ||
|
||
if (bounds.Width > bounds.Height) | ||
{ | ||
startX += delta; | ||
endX -= 2 * delta; | ||
} | ||
else if (bounds.Width < bounds.Height) | ||
{ | ||
startY += delta; | ||
endY -= 2 * delta; | ||
} | ||
|
||
var croppedBounds = new CGRect( | ||
startX, startY, endX, endY); | ||
|
||
var strokedCroppedBounds = croppedBounds.Inset( | ||
borderWidth, borderWidth); | ||
|
||
var radius = ((float)Math.Min(bounds.Width, bounds.Height) - borderWidth) / 2; | ||
|
||
return UIBezierPath.FromRoundedRect(strokedCroppedBounds, radius); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
namespace XamarinBackgroundKit.Shapes | ||
{ | ||
public class Circle : BaseShape { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters