// ----------------------------------------------------------------------- // // Copyright 2014 MIT Licence. See licence.md for more information. // // ----------------------------------------------------------------------- namespace Perspex { /// /// Defines the reference point units of an . /// public enum OriginUnit { /// /// The origin's point is a percentage. /// Percent, /// /// The origin's point is in pixels. /// Pixels, } /// /// Defines an origin for a . /// public struct Origin { /// /// The default origin, which is the center of the control. /// public static readonly Origin Default = new Origin(0.5, 0.5, OriginUnit.Percent); private Point point; private OriginUnit unit; /// /// Initializes a new instance of the struct. /// /// The X point. /// The Y point /// The origin unit. public Origin(double x, double y, OriginUnit unit) : this(new Point(x, y), unit) { } /// /// Initializes a new instance of the struct. /// /// The origin point. /// The origin unit. public Origin(Point point, OriginUnit unit) { this.point = point; this.unit = unit; } /// /// Gets the origin point. /// public Point Point { get { return this.point; } } /// /// Gets the origin unit. /// public OriginUnit Unit { get { return this.unit; } } /// /// Converts an into pixels. /// /// The size of the visual. /// The origin point in pixels. public Point ToPixels(Size size) { return this.unit == OriginUnit.Pixels ? this.point : new Point(this.point.X * size.Width, this.point.Y * size.Height); } } }