From b4eca729fb43289a4ad3032bd4de95d2f91ea264 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 16 Sep 2015 02:27:07 +0200 Subject: [PATCH] Renamed Origin -> RelativePoint. --- src/Perspex.SceneGraph/IVisual.cs | 2 +- .../Perspex.SceneGraph.csproj | 2 +- .../{Origin.cs => RelativePoint.cs} | 41 ++++++++++--------- src/Perspex.SceneGraph/RelativeRect.cs | 18 ++++---- src/Perspex.SceneGraph/Visual.cs | 6 +-- .../Media/VisualBrushTests.cs | 20 ++++----- 6 files changed, 45 insertions(+), 44 deletions(-) rename src/Perspex.SceneGraph/{Origin.cs => RelativePoint.cs} (52%) diff --git a/src/Perspex.SceneGraph/IVisual.cs b/src/Perspex.SceneGraph/IVisual.cs index 559ac21745..76ab95e6e6 100644 --- a/src/Perspex.SceneGraph/IVisual.cs +++ b/src/Perspex.SceneGraph/IVisual.cs @@ -58,7 +58,7 @@ namespace Perspex /// /// Gets or sets the transform origin of the scene graph node. /// - Origin TransformOrigin { get; set; } + RelativePoint TransformOrigin { get; set; } /// /// Gets the scene graph node's child nodes. diff --git a/src/Perspex.SceneGraph/Perspex.SceneGraph.csproj b/src/Perspex.SceneGraph/Perspex.SceneGraph.csproj index 8841e9a7de..660cbe38d7 100644 --- a/src/Perspex.SceneGraph/Perspex.SceneGraph.csproj +++ b/src/Perspex.SceneGraph/Perspex.SceneGraph.csproj @@ -98,7 +98,7 @@ - + diff --git a/src/Perspex.SceneGraph/Origin.cs b/src/Perspex.SceneGraph/RelativePoint.cs similarity index 52% rename from src/Perspex.SceneGraph/Origin.cs rename to src/Perspex.SceneGraph/RelativePoint.cs index 591a2379eb..a0f368bdf2 100644 --- a/src/Perspex.SceneGraph/Origin.cs +++ b/src/Perspex.SceneGraph/RelativePoint.cs @@ -4,12 +4,13 @@ namespace Perspex { /// - /// Defines the reference point units of an . + /// Defines the reference point units of an or + /// . /// - public enum OriginUnit + public enum RelativeUnit { /// - /// The origin's point is a percentage. + /// The point is expressed as a percentage of the containing element's size. /// Percent, @@ -20,59 +21,59 @@ namespace Perspex } /// - /// Defines an origin for a . + /// Defines a point that may be defined relative to a containing element. /// - public struct Origin + public struct RelativePoint { /// - /// The default origin, which is the center of the control. + /// A point at the center of the containing element. /// - public static readonly Origin Default = new Origin(0.5, 0.5, OriginUnit.Percent); + public static readonly RelativePoint Center = new RelativePoint(0.5, 0.5, RelativeUnit.Percent); private Point _point; - private readonly OriginUnit _unit; + private readonly RelativeUnit _unit; /// - /// Initializes a new instance of the struct. + /// Initializes a new instance of the struct. /// /// The X point. /// The Y point - /// The origin unit. - public Origin(double x, double y, OriginUnit unit) + /// The unit. + public RelativePoint(double x, double y, RelativeUnit unit) : this(new Point(x, y), unit) { } /// - /// Initializes a new instance of the struct. + /// Initializes a new instance of the struct. /// - /// The origin point. - /// The origin unit. - public Origin(Point point, OriginUnit unit) + /// The point. + /// The unit. + public RelativePoint(Point point, RelativeUnit unit) { _point = point; _unit = unit; } /// - /// Gets the origin point. + /// Gets the point. /// public Point Point => _point; /// - /// Gets the origin unit. + /// Gets the unit. /// - public OriginUnit Unit => _unit; + public RelativeUnit Unit => _unit; /// - /// Converts an into pixels. + /// Converts a into pixels. /// /// The size of the visual. /// The origin point in pixels. public Point ToPixels(Size size) { - return _unit == OriginUnit.Pixels ? + return _unit == RelativeUnit.Pixels ? _point : new Point(_point.X * size.Width, _point.Y * size.Height); } diff --git a/src/Perspex.SceneGraph/RelativeRect.cs b/src/Perspex.SceneGraph/RelativeRect.cs index 26afd7d1bb..02b5d63143 100644 --- a/src/Perspex.SceneGraph/RelativeRect.cs +++ b/src/Perspex.SceneGraph/RelativeRect.cs @@ -4,14 +4,14 @@ namespace Perspex { /// - /// Defines a rectangle that may be defined relative to another rectangle. + /// Defines a rectangle that may be defined relative to a containing element. /// public struct RelativeRect { /// /// A rectangle that represents 100% of an area. /// - public static readonly RelativeRect Fill = new RelativeRect(0, 0, 1, 1, OriginUnit.Percent); + public static readonly RelativeRect Fill = new RelativeRect(0, 0, 1, 1, RelativeUnit.Percent); /// /// Initializes a new instance of the structure. @@ -21,7 +21,7 @@ namespace Perspex /// The width. /// The height. /// The unit of the rect. - public RelativeRect(double x, double y, double width, double height, OriginUnit unit) + public RelativeRect(double x, double y, double width, double height, RelativeUnit unit) { Rect = new Rect(x, y, width, height); Unit = unit; @@ -32,7 +32,7 @@ namespace Perspex /// /// The rectangle. /// The unit of the rect. - public RelativeRect(Rect rect, OriginUnit unit) + public RelativeRect(Rect rect, RelativeUnit unit) { Rect = rect; Unit = unit; @@ -43,7 +43,7 @@ namespace Perspex /// /// The size of the rectangle. /// The unit of the rect. - public RelativeRect(Size size, OriginUnit unit) + public RelativeRect(Size size, RelativeUnit unit) { Rect = new Rect(size); Unit = unit; @@ -55,7 +55,7 @@ namespace Perspex /// The position of the rectangle. /// The size of the rectangle. /// The unit of the rect. - public RelativeRect(Point position, Size size, OriginUnit unit) + public RelativeRect(Point position, Size size, RelativeUnit unit) { Rect = new Rect(position, size); Unit = unit; @@ -67,7 +67,7 @@ namespace Perspex /// The top left position of the rectangle. /// The bottom right position of the rectangle. /// The unit of the rect. - public RelativeRect(Point topLeft, Point bottomRight, OriginUnit unit) + public RelativeRect(Point topLeft, Point bottomRight, RelativeUnit unit) { Rect = new Rect(topLeft, bottomRight); Unit = unit; @@ -76,7 +76,7 @@ namespace Perspex /// /// Gets the unit of the rectangle. /// - public OriginUnit Unit { get; } + public RelativeUnit Unit { get; } /// /// Gets the rectangle. @@ -90,7 +90,7 @@ namespace Perspex /// The origin point in pixels. public Rect ToPixels(Size size) { - return Unit == OriginUnit.Pixels ? + return Unit == RelativeUnit.Pixels ? Rect : new Rect( Rect.X * size.Width, diff --git a/src/Perspex.SceneGraph/Visual.cs b/src/Perspex.SceneGraph/Visual.cs index 3ede93a78c..a3733eb756 100644 --- a/src/Perspex.SceneGraph/Visual.cs +++ b/src/Perspex.SceneGraph/Visual.cs @@ -61,8 +61,8 @@ namespace Perspex /// /// Defines the property. /// - public static readonly PerspexProperty TransformOriginProperty = - PerspexProperty.Register(nameof(TransformOrigin), defaultValue: Origin.Default); + public static readonly PerspexProperty TransformOriginProperty = + PerspexProperty.Register(nameof(TransformOrigin), defaultValue: RelativePoint.Center); /// /// Defines the property. @@ -172,7 +172,7 @@ namespace Perspex /// /// Gets the transform origin of the scene graph node. /// - public Origin TransformOrigin + public RelativePoint TransformOrigin { get { return GetValue(TransformOriginProperty); } set { SetValue(TransformOriginProperty, value); } diff --git a/tests/Perspex.RenderTests/Media/VisualBrushTests.cs b/tests/Perspex.RenderTests/Media/VisualBrushTests.cs index 5bff4198cb..d05b3cf13e 100644 --- a/tests/Perspex.RenderTests/Media/VisualBrushTests.cs +++ b/tests/Perspex.RenderTests/Media/VisualBrushTests.cs @@ -288,7 +288,7 @@ namespace Perspex.Direct2D1.RenderTests.Media { Fill = new VisualBrush { - SourceRect = new RelativeRect(40, 40, 100, 100, OriginUnit.Pixels), + SourceRect = new RelativeRect(40, 40, 100, 100, RelativeUnit.Pixels), Visual = new Border { Width = 180, @@ -329,7 +329,7 @@ namespace Perspex.Direct2D1.RenderTests.Media { Fill = new VisualBrush { - DestinationRect = new RelativeRect(92, 92, 92, 92, OriginUnit.Pixels), + DestinationRect = new RelativeRect(92, 92, 92, 92, RelativeUnit.Pixels), Visual = new Border { Width = 180, @@ -370,8 +370,8 @@ namespace Perspex.Direct2D1.RenderTests.Media { Fill = new VisualBrush { - SourceRect = new RelativeRect(40, 40, 100, 100, OriginUnit.Pixels), - DestinationRect = new RelativeRect(92, 92, 92, 92, OriginUnit.Pixels), + SourceRect = new RelativeRect(40, 40, 100, 100, RelativeUnit.Pixels), + DestinationRect = new RelativeRect(92, 92, 92, 92, RelativeUnit.Pixels), Visual = new Border { Width = 180, @@ -412,8 +412,8 @@ namespace Perspex.Direct2D1.RenderTests.Media { Fill = new VisualBrush { - SourceRect = new RelativeRect(0.22, 0.22, 0.56, 0.56, OriginUnit.Percent), - DestinationRect = new RelativeRect(0.5, 0.5, 0.5, 0.5, OriginUnit.Percent), + SourceRect = new RelativeRect(0.22, 0.22, 0.56, 0.56, RelativeUnit.Percent), + DestinationRect = new RelativeRect(0.5, 0.5, 0.5, 0.5, RelativeUnit.Percent), Visual = new Border { Width = 180, @@ -456,7 +456,7 @@ namespace Perspex.Direct2D1.RenderTests.Media { Stretch = Stretch.None, TileMode = TileMode.Tile, - DestinationRect = new RelativeRect(0.25, 0.25, 0.5, 0.5, OriginUnit.Percent), + DestinationRect = new RelativeRect(0.25, 0.25, 0.5, 0.5, RelativeUnit.Percent), Visual = new Border { Width = 92, @@ -543,7 +543,7 @@ namespace Perspex.Direct2D1.RenderTests.Media { Stretch = Stretch.None, TileMode = TileMode.FlipX, - DestinationRect = new RelativeRect(0, 0, 0.5, 0.5, OriginUnit.Percent), + DestinationRect = new RelativeRect(0, 0, 0.5, 0.5, RelativeUnit.Percent), Visual = new Border { Width = 92, @@ -586,7 +586,7 @@ namespace Perspex.Direct2D1.RenderTests.Media { Stretch = Stretch.None, TileMode = TileMode.FlipY, - DestinationRect = new RelativeRect(0, 0, 0.5, 0.5, OriginUnit.Percent), + DestinationRect = new RelativeRect(0, 0, 0.5, 0.5, RelativeUnit.Percent), Visual = new Border { Width = 92, @@ -629,7 +629,7 @@ namespace Perspex.Direct2D1.RenderTests.Media { Stretch = Stretch.None, TileMode = TileMode.FlipXY, - DestinationRect = new RelativeRect(0, 0, 0.5, 0.5, OriginUnit.Percent), + DestinationRect = new RelativeRect(0, 0, 0.5, 0.5, RelativeUnit.Percent), Visual = new Border { Width = 92,