Browse Source

Renamed Origin -> RelativePoint.

pull/145/head
Steven Kirk 11 years ago
parent
commit
b4eca729fb
  1. 2
      src/Perspex.SceneGraph/IVisual.cs
  2. 2
      src/Perspex.SceneGraph/Perspex.SceneGraph.csproj
  3. 41
      src/Perspex.SceneGraph/RelativePoint.cs
  4. 18
      src/Perspex.SceneGraph/RelativeRect.cs
  5. 6
      src/Perspex.SceneGraph/Visual.cs
  6. 20
      tests/Perspex.RenderTests/Media/VisualBrushTests.cs

2
src/Perspex.SceneGraph/IVisual.cs

@ -58,7 +58,7 @@ namespace Perspex
/// <summary> /// <summary>
/// Gets or sets the transform origin of the scene graph node. /// Gets or sets the transform origin of the scene graph node.
/// </summary> /// </summary>
Origin TransformOrigin { get; set; } RelativePoint TransformOrigin { get; set; }
/// <summary> /// <summary>
/// Gets the scene graph node's child nodes. /// Gets the scene graph node's child nodes.

2
src/Perspex.SceneGraph/Perspex.SceneGraph.csproj

@ -98,7 +98,7 @@
<Compile Include="Media\Transform.cs" /> <Compile Include="Media\Transform.cs" />
<Compile Include="Media\TileBrush.cs" /> <Compile Include="Media\TileBrush.cs" />
<Compile Include="Media\VisualBrush.cs" /> <Compile Include="Media\VisualBrush.cs" />
<Compile Include="Origin.cs" /> <Compile Include="RelativePoint.cs" />
<Compile Include="Platform\IFormattedTextImpl.cs" /> <Compile Include="Platform\IFormattedTextImpl.cs" />
<Compile Include="Platform\IBitmapImpl.cs" /> <Compile Include="Platform\IBitmapImpl.cs" />
<Compile Include="Platform\IGeometryImpl.cs" /> <Compile Include="Platform\IGeometryImpl.cs" />

41
src/Perspex.SceneGraph/Origin.cs → src/Perspex.SceneGraph/RelativePoint.cs

@ -4,12 +4,13 @@
namespace Perspex namespace Perspex
{ {
/// <summary> /// <summary>
/// Defines the reference point units of an <see cref="Origin"/>. /// Defines the reference point units of an <see cref="RelativePoint"/> or
/// <see cref="RelativeRect"/>.
/// </summary> /// </summary>
public enum OriginUnit public enum RelativeUnit
{ {
/// <summary> /// <summary>
/// The origin's point is a percentage. /// The point is expressed as a percentage of the containing element's size.
/// </summary> /// </summary>
Percent, Percent,
@ -20,59 +21,59 @@ namespace Perspex
} }
/// <summary> /// <summary>
/// Defines an origin for a <see cref="Perspex.Media.Transform"/>. /// Defines a point that may be defined relative to a containing element.
/// </summary> /// </summary>
public struct Origin public struct RelativePoint
{ {
/// <summary> /// <summary>
/// The default origin, which is the center of the control. /// A point at the center of the containing element.
/// </summary> /// </summary>
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 Point _point;
private readonly OriginUnit _unit; private readonly RelativeUnit _unit;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Origin"/> struct. /// Initializes a new instance of the <see cref="RelativePoint"/> struct.
/// </summary> /// </summary>
/// <param name="x">The X point.</param> /// <param name="x">The X point.</param>
/// <param name="y">The Y point</param> /// <param name="y">The Y point</param>
/// <param name="unit">The origin unit.</param> /// <param name="unit">The unit.</param>
public Origin(double x, double y, OriginUnit unit) public RelativePoint(double x, double y, RelativeUnit unit)
: this(new Point(x, y), unit) : this(new Point(x, y), unit)
{ {
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Origin"/> struct. /// Initializes a new instance of the <see cref="RelativePoint"/> struct.
/// </summary> /// </summary>
/// <param name="point">The origin point.</param> /// <param name="point">The point.</param>
/// <param name="unit">The origin unit.</param> /// <param name="unit">The unit.</param>
public Origin(Point point, OriginUnit unit) public RelativePoint(Point point, RelativeUnit unit)
{ {
_point = point; _point = point;
_unit = unit; _unit = unit;
} }
/// <summary> /// <summary>
/// Gets the origin point. /// Gets the point.
/// </summary> /// </summary>
public Point Point => _point; public Point Point => _point;
/// <summary> /// <summary>
/// Gets the origin unit. /// Gets the unit.
/// </summary> /// </summary>
public OriginUnit Unit => _unit; public RelativeUnit Unit => _unit;
/// <summary> /// <summary>
/// Converts an <see cref="Origin"/> into pixels. /// Converts a <see cref="RelativePoint"/> into pixels.
/// </summary> /// </summary>
/// <param name="size">The size of the visual.</param> /// <param name="size">The size of the visual.</param>
/// <returns>The origin point in pixels.</returns> /// <returns>The origin point in pixels.</returns>
public Point ToPixels(Size size) public Point ToPixels(Size size)
{ {
return _unit == OriginUnit.Pixels ? return _unit == RelativeUnit.Pixels ?
_point : _point :
new Point(_point.X * size.Width, _point.Y * size.Height); new Point(_point.X * size.Width, _point.Y * size.Height);
} }

18
src/Perspex.SceneGraph/RelativeRect.cs

@ -4,14 +4,14 @@
namespace Perspex namespace Perspex
{ {
/// <summary> /// <summary>
/// Defines a rectangle that may be defined relative to another rectangle. /// Defines a rectangle that may be defined relative to a containing element.
/// </summary> /// </summary>
public struct RelativeRect public struct RelativeRect
{ {
/// <summary> /// <summary>
/// A rectangle that represents 100% of an area. /// A rectangle that represents 100% of an area.
/// </summary> /// </summary>
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);
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="RelativeRect"/> structure. /// Initializes a new instance of the <see cref="RelativeRect"/> structure.
@ -21,7 +21,7 @@ namespace Perspex
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
/// <param name="height">The height.</param> /// <param name="height">The height.</param>
/// <param name="unit">The unit of the rect.</param> /// <param name="unit">The unit of the rect.</param>
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); Rect = new Rect(x, y, width, height);
Unit = unit; Unit = unit;
@ -32,7 +32,7 @@ namespace Perspex
/// </summary> /// </summary>
/// <param name="rect">The rectangle.</param> /// <param name="rect">The rectangle.</param>
/// <param name="unit">The unit of the rect.</param> /// <param name="unit">The unit of the rect.</param>
public RelativeRect(Rect rect, OriginUnit unit) public RelativeRect(Rect rect, RelativeUnit unit)
{ {
Rect = rect; Rect = rect;
Unit = unit; Unit = unit;
@ -43,7 +43,7 @@ namespace Perspex
/// </summary> /// </summary>
/// <param name="size">The size of the rectangle.</param> /// <param name="size">The size of the rectangle.</param>
/// <param name="unit">The unit of the rect.</param> /// <param name="unit">The unit of the rect.</param>
public RelativeRect(Size size, OriginUnit unit) public RelativeRect(Size size, RelativeUnit unit)
{ {
Rect = new Rect(size); Rect = new Rect(size);
Unit = unit; Unit = unit;
@ -55,7 +55,7 @@ namespace Perspex
/// <param name="position">The position of the rectangle.</param> /// <param name="position">The position of the rectangle.</param>
/// <param name="size">The size of the rectangle.</param> /// <param name="size">The size of the rectangle.</param>
/// <param name="unit">The unit of the rect.</param> /// <param name="unit">The unit of the rect.</param>
public RelativeRect(Point position, Size size, OriginUnit unit) public RelativeRect(Point position, Size size, RelativeUnit unit)
{ {
Rect = new Rect(position, size); Rect = new Rect(position, size);
Unit = unit; Unit = unit;
@ -67,7 +67,7 @@ namespace Perspex
/// <param name="topLeft">The top left position of the rectangle.</param> /// <param name="topLeft">The top left position of the rectangle.</param>
/// <param name="bottomRight">The bottom right position of the rectangle.</param> /// <param name="bottomRight">The bottom right position of the rectangle.</param>
/// <param name="unit">The unit of the rect.</param> /// <param name="unit">The unit of the rect.</param>
public RelativeRect(Point topLeft, Point bottomRight, OriginUnit unit) public RelativeRect(Point topLeft, Point bottomRight, RelativeUnit unit)
{ {
Rect = new Rect(topLeft, bottomRight); Rect = new Rect(topLeft, bottomRight);
Unit = unit; Unit = unit;
@ -76,7 +76,7 @@ namespace Perspex
/// <summary> /// <summary>
/// Gets the unit of the rectangle. /// Gets the unit of the rectangle.
/// </summary> /// </summary>
public OriginUnit Unit { get; } public RelativeUnit Unit { get; }
/// <summary> /// <summary>
/// Gets the rectangle. /// Gets the rectangle.
@ -90,7 +90,7 @@ namespace Perspex
/// <returns>The origin point in pixels.</returns> /// <returns>The origin point in pixels.</returns>
public Rect ToPixels(Size size) public Rect ToPixels(Size size)
{ {
return Unit == OriginUnit.Pixels ? return Unit == RelativeUnit.Pixels ?
Rect : Rect :
new Rect( new Rect(
Rect.X * size.Width, Rect.X * size.Width,

6
src/Perspex.SceneGraph/Visual.cs

@ -61,8 +61,8 @@ namespace Perspex
/// <summary> /// <summary>
/// Defines the <see cref="TransformOrigin"/> property. /// Defines the <see cref="TransformOrigin"/> property.
/// </summary> /// </summary>
public static readonly PerspexProperty<Origin> TransformOriginProperty = public static readonly PerspexProperty<RelativePoint> TransformOriginProperty =
PerspexProperty.Register<Visual, Origin>(nameof(TransformOrigin), defaultValue: Origin.Default); PerspexProperty.Register<Visual, RelativePoint>(nameof(TransformOrigin), defaultValue: RelativePoint.Center);
/// <summary> /// <summary>
/// Defines the <see cref="ZIndex"/> property. /// Defines the <see cref="ZIndex"/> property.
@ -172,7 +172,7 @@ namespace Perspex
/// <summary> /// <summary>
/// Gets the transform origin of the scene graph node. /// Gets the transform origin of the scene graph node.
/// </summary> /// </summary>
public Origin TransformOrigin public RelativePoint TransformOrigin
{ {
get { return GetValue(TransformOriginProperty); } get { return GetValue(TransformOriginProperty); }
set { SetValue(TransformOriginProperty, value); } set { SetValue(TransformOriginProperty, value); }

20
tests/Perspex.RenderTests/Media/VisualBrushTests.cs

@ -288,7 +288,7 @@ namespace Perspex.Direct2D1.RenderTests.Media
{ {
Fill = new VisualBrush Fill = new VisualBrush
{ {
SourceRect = new RelativeRect(40, 40, 100, 100, OriginUnit.Pixels), SourceRect = new RelativeRect(40, 40, 100, 100, RelativeUnit.Pixels),
Visual = new Border Visual = new Border
{ {
Width = 180, Width = 180,
@ -329,7 +329,7 @@ namespace Perspex.Direct2D1.RenderTests.Media
{ {
Fill = new VisualBrush Fill = new VisualBrush
{ {
DestinationRect = new RelativeRect(92, 92, 92, 92, OriginUnit.Pixels), DestinationRect = new RelativeRect(92, 92, 92, 92, RelativeUnit.Pixels),
Visual = new Border Visual = new Border
{ {
Width = 180, Width = 180,
@ -370,8 +370,8 @@ namespace Perspex.Direct2D1.RenderTests.Media
{ {
Fill = new VisualBrush Fill = new VisualBrush
{ {
SourceRect = new RelativeRect(40, 40, 100, 100, OriginUnit.Pixels), SourceRect = new RelativeRect(40, 40, 100, 100, RelativeUnit.Pixels),
DestinationRect = new RelativeRect(92, 92, 92, 92, OriginUnit.Pixels), DestinationRect = new RelativeRect(92, 92, 92, 92, RelativeUnit.Pixels),
Visual = new Border Visual = new Border
{ {
Width = 180, Width = 180,
@ -412,8 +412,8 @@ namespace Perspex.Direct2D1.RenderTests.Media
{ {
Fill = new VisualBrush Fill = new VisualBrush
{ {
SourceRect = new RelativeRect(0.22, 0.22, 0.56, 0.56, 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, OriginUnit.Percent), DestinationRect = new RelativeRect(0.5, 0.5, 0.5, 0.5, RelativeUnit.Percent),
Visual = new Border Visual = new Border
{ {
Width = 180, Width = 180,
@ -456,7 +456,7 @@ namespace Perspex.Direct2D1.RenderTests.Media
{ {
Stretch = Stretch.None, Stretch = Stretch.None,
TileMode = TileMode.Tile, 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 Visual = new Border
{ {
Width = 92, Width = 92,
@ -543,7 +543,7 @@ namespace Perspex.Direct2D1.RenderTests.Media
{ {
Stretch = Stretch.None, Stretch = Stretch.None,
TileMode = TileMode.FlipX, 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 Visual = new Border
{ {
Width = 92, Width = 92,
@ -586,7 +586,7 @@ namespace Perspex.Direct2D1.RenderTests.Media
{ {
Stretch = Stretch.None, Stretch = Stretch.None,
TileMode = TileMode.FlipY, 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 Visual = new Border
{ {
Width = 92, Width = 92,
@ -629,7 +629,7 @@ namespace Perspex.Direct2D1.RenderTests.Media
{ {
Stretch = Stretch.None, Stretch = Stretch.None,
TileMode = TileMode.FlipXY, 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 Visual = new Border
{ {
Width = 92, Width = 92,

Loading…
Cancel
Save