-
-
Notifications
You must be signed in to change notification settings - Fork 107
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 #56 from sthewissen/fix-shadows
Fixes #42
- Loading branch information
Showing
5 changed files
with
128 additions
and
112 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
51 changes: 0 additions & 51 deletions
51
src/Xamarin.Forms.PancakeView.Multi/Platforms/Android/PolygonUtils.cs
This file was deleted.
Oops, something went wrong.
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
67 changes: 67 additions & 0 deletions
67
src/Xamarin.Forms.PancakeView.Multi/Platforms/Android/ShapeUtils.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,67 @@ | ||
using System; | ||
using Android.Graphics; | ||
|
||
namespace Xamarin.Forms.PancakeView.Droid | ||
{ | ||
public static class ShapeUtils | ||
{ | ||
public static Path CreateRoundedRectPath(float rectWidth, float rectHeight, float topLeft, float topRight, float bottomRight, float bottomLeft) | ||
{ | ||
var path = new Path(); | ||
var radii = new[] { topLeft, topLeft, | ||
topRight, topRight, | ||
bottomRight, bottomRight, | ||
bottomLeft, bottomLeft }; | ||
|
||
path.AddRoundRect(new RectF(0, 0, rectWidth, rectHeight), radii, Path.Direction.Ccw); | ||
path.Close(); | ||
|
||
return path; | ||
} | ||
|
||
public static Path CreatePolygonPath(double rectWidth, double rectHeight, int sides, double cornerRadius = 0.0, double rotationOffset = 0.0) | ||
{ | ||
var offsetRadians = rotationOffset * Math.PI / 180; | ||
|
||
var path = new Path(); | ||
var theta = 2 * Math.PI / sides; | ||
|
||
// depends on the rotation | ||
var width = (-cornerRadius + Math.Min(rectWidth, rectHeight)) / 2; | ||
var center = new Point(rectWidth / 2, rectHeight / 2); | ||
|
||
var radius = width + cornerRadius - (Math.Cos(theta) * cornerRadius) / 2; | ||
|
||
var angle = offsetRadians; | ||
var corner = new Point(center.X + (radius - cornerRadius) * Math.Cos(angle), center.Y + (radius - cornerRadius) * Math.Sin(angle)); | ||
path.MoveTo((float)(corner.X + cornerRadius * Math.Cos(angle + theta)), (float)(corner.Y + cornerRadius * Math.Sin(angle + theta))); | ||
|
||
for (var i = 0; i < sides; i++) | ||
{ | ||
angle += theta; | ||
corner = new Point(center.X + (radius - cornerRadius) * Math.Cos(angle), center.Y + (radius - cornerRadius) * Math.Sin(angle)); | ||
var tip = new Point(center.X + radius * Math.Cos(angle), center.Y + radius * Math.Sin(angle)); | ||
var start = new Point(corner.X + cornerRadius * Math.Cos(angle - theta), corner.Y + cornerRadius * Math.Sin(angle - theta)); | ||
var end = new Point(corner.X + cornerRadius * Math.Cos(angle + theta), corner.Y + cornerRadius * Math.Sin(angle + theta)); | ||
|
||
path.LineTo(start.X, start.Y); | ||
path.QuadTo(tip.X, tip.Y, end.X, end.Y); | ||
} | ||
|
||
path.Close(); | ||
|
||
return path; | ||
} | ||
|
||
public class Point | ||
{ | ||
public float X { get; set; } | ||
public float Y { get; set; } | ||
public Point(double X, double Y) | ||
{ | ||
this.X = (float)X; | ||
this.Y = (float)Y; | ||
} | ||
} | ||
} | ||
} |