forked from dotnet/maui
-
Notifications
You must be signed in to change notification settings - Fork 7
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 #66 from Clancey/jon/dev
Started work on shape support on UWP. (Not completely, pivoting to w…
- Loading branch information
Showing
9 changed files
with
262 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using Windows.Foundation; | ||
using Windows.UI.Xaml.Media; | ||
using WCanvas = Windows.UI.Xaml.Controls.Canvas; | ||
using WPath = Windows.UI.Xaml.Shapes.Path; | ||
|
||
namespace HotUI.UWP.Controls | ||
{ | ||
public class HUIShapeView : WCanvas | ||
{ | ||
private Shape _shape; | ||
private WPath _path; | ||
private Size _size; | ||
|
||
public HUIShapeView() | ||
{ | ||
|
||
} | ||
|
||
public Shape Shape | ||
{ | ||
get => _shape; | ||
set | ||
{ | ||
_shape = value; | ||
UpdateShape(); | ||
} | ||
} | ||
|
||
public View View { get; set; } | ||
|
||
protected override Size ArrangeOverride(Size finalSize) | ||
{ | ||
_size = base.ArrangeOverride(finalSize); | ||
UpdateShape(); | ||
return _size; | ||
} | ||
|
||
private void UpdateShape() | ||
{ | ||
if (_path != null) | ||
{ | ||
Children.Remove(_path); | ||
_path = null; | ||
} | ||
|
||
if (_shape != null) | ||
{ | ||
if (_size.Width <= 0 || _size.Height <= 0) return; | ||
|
||
var bounds = new RectangleF(0, 0, (float)_size.Width, (float)_size.Height); | ||
var path = _shape.PathForBounds(bounds); | ||
_path = new WPath() | ||
{ | ||
Data = path.AsPathGeometry(), | ||
Stroke = new SolidColorBrush(_shape.GetColor(View, Color.Black).ToColor()), | ||
StrokeThickness = _shape.GetStroke(View,1) | ||
}; | ||
Children.Add(_path); | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,28 +1,123 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using HotUI.Graphics; | ||
using System; | ||
using Windows.UI.Xaml.Media; | ||
using UWPSize = Windows.Foundation.Size; | ||
using UWPColor = Windows.UI.Color; | ||
|
||
namespace HotUI.UWP | ||
{ | ||
public static class GraphicsExtensions | ||
{ | ||
public static Task<ImageSource> LoadImage(this string source) | ||
{ | ||
public static UWPColor ToColor(this Color target) | ||
{ | ||
throw new NotImplementedException(); | ||
return UWPColor.FromArgb( | ||
(byte)(255 * target.A), | ||
(byte)(255 * target.R), | ||
(byte)(255 * target.G), | ||
(byte)(255 * target.B)); | ||
} | ||
|
||
private static Task<ImageSource> LoadImageAsync(string urlString) | ||
public static PathGeometry AsPathGeometry(this PathF target) | ||
{ | ||
throw new NotImplementedException(); | ||
var geometry = new PathGeometry(); | ||
PathFigure figure = null; | ||
|
||
} | ||
var pointIndex = 0; | ||
var arcAngleIndex = 0; | ||
var arcClockwiseIndex = 0; | ||
|
||
private static Task<ImageSource> LoadFileAsync(string filePath) | ||
{ | ||
throw new NotImplementedException(); | ||
foreach (var operation in target.PathOperations) | ||
{ | ||
if (operation == PathOperation.MoveTo) | ||
{ | ||
figure = new PathFigure(); | ||
geometry.Figures.Add(figure); | ||
figure.StartPoint = target[pointIndex++].ToPoint(); | ||
} | ||
else if (operation == PathOperation.Line) | ||
{ | ||
var lineSegment = new LineSegment { Point = target[pointIndex++].ToPoint() }; | ||
figure.Segments.Add(lineSegment); | ||
} | ||
else if (operation == PathOperation.Quad) | ||
{ | ||
var quadSegment = new QuadraticBezierSegment | ||
{ | ||
Point1 = target[pointIndex++].ToPoint(), | ||
Point2 = target[pointIndex++].ToPoint() | ||
}; | ||
figure.Segments.Add(quadSegment); | ||
} | ||
else if (operation == PathOperation.Cubic) | ||
{ | ||
var cubicSegment = new BezierSegment() | ||
{ | ||
Point1 = target[pointIndex++].ToPoint(), | ||
Point2 = target[pointIndex++].ToPoint(), | ||
Point3 = target[pointIndex++].ToPoint(), | ||
}; | ||
figure.Segments.Add(cubicSegment); | ||
} | ||
else if (operation == PathOperation.Arc) | ||
{ | ||
var topLeft = target[pointIndex++]; | ||
var bottomRight = target[pointIndex++]; | ||
var startAngle = target.GetArcAngle(arcAngleIndex++); | ||
var endAngle = target.GetArcAngle(arcAngleIndex++); | ||
var clockwise = target.IsArcClockwise(arcClockwiseIndex++); | ||
|
||
while (startAngle < 0) | ||
{ | ||
startAngle += 360; | ||
} | ||
|
||
while (endAngle < 0) | ||
{ | ||
endAngle += 360; | ||
} | ||
|
||
var sweep = GraphicsOperations.GetSweep(startAngle, endAngle, clockwise); | ||
var absSweep = Math.Abs(sweep); | ||
|
||
var rectX = topLeft.X; | ||
var rectY = topLeft.Y; | ||
var rectWidth = bottomRight.X - topLeft.X; | ||
var rectHeight = bottomRight.Y - topLeft.Y; | ||
|
||
var startPoint = GraphicsOperations.OvalAngleToPoint(rectX, rectY, rectWidth, rectHeight, -startAngle); | ||
var endPoint = GraphicsOperations.OvalAngleToPoint(rectX, rectY, rectWidth, rectHeight, -endAngle); | ||
|
||
if (figure == null) | ||
{ | ||
figure = new PathFigure(); | ||
geometry.Figures.Add(figure); | ||
figure.StartPoint = startPoint.ToPoint(); | ||
} | ||
else | ||
{ | ||
var lineSegment = new LineSegment() | ||
{ | ||
Point = startPoint.ToPoint() | ||
}; | ||
figure.Segments.Add(lineSegment); | ||
} | ||
|
||
var arcSegment = new ArcSegment() | ||
{ | ||
Point = endPoint.ToPoint(), | ||
Size = new UWPSize(rectWidth / 2, rectHeight / 2), | ||
SweepDirection = clockwise ? SweepDirection.Clockwise : SweepDirection.Counterclockwise, | ||
IsLargeArc = absSweep >= 180, | ||
}; | ||
figure.Segments.Add(arcSegment); | ||
} | ||
else if (operation == PathOperation.Close) | ||
{ | ||
figure.IsClosed = true; | ||
} | ||
} | ||
|
||
return geometry; | ||
} | ||
} | ||
} |
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,37 @@ | ||
| ||
|
||
// ReSharper disable ClassNeverInstantiated.Global | ||
// ReSharper disable MemberCanBePrivate.Global | ||
|
||
using HotUI.UWP.Controls; | ||
|
||
namespace HotUI.UWP.Handlers | ||
{ | ||
public class ShapeViewHandler : AbstractControlHandler<ShapeView, HUIShapeView> | ||
{ | ||
public static readonly PropertyMapper<ShapeView> Mapper = new PropertyMapper<ShapeView>(ViewHandler.Mapper) | ||
{ | ||
[nameof(HotUI.ShapeView.Shape)] = MapShapeProperty, | ||
}; | ||
|
||
|
||
public ShapeViewHandler() : base(Mapper) | ||
{ | ||
|
||
} | ||
|
||
protected override HUIShapeView CreateView() => new HUIShapeView(); | ||
|
||
protected override void DisposeView(HUIShapeView nativeView) | ||
{ | ||
|
||
} | ||
|
||
public static void MapShapeProperty(IViewHandler viewHandler, ShapeView virtualView) | ||
{ | ||
var nativeView = (HUIShapeView) viewHandler.NativeView; | ||
nativeView.View = virtualView; | ||
nativeView.Shape = virtualView.Shape; | ||
} | ||
} | ||
} |
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
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