// ----------------------------------------------------------------------- // // Copyright 2013 MIT Licence. See licence.md for more information. // // ----------------------------------------------------------------------- namespace Perspex.Direct2D1 { using SharpDX; using SharpDX.Direct2D1; public static class PrimitiveExtensions { public static Rect ToPerspex(this RectangleF r) { return new Rect(r.X, r.Y, r.Width, r.Height); } public static RectangleF ToSharpDX(this Rect r) { return new RectangleF((float)r.X, (float)r.Y, (float)r.Width, (float)r.Height); } public static Vector2 ToSharpDX(this Perspex.Point p) { return new Vector2((float)p.X, (float)p.Y); } /// /// Converts a brush to Direct2D. /// /// The brush to convert. /// The Direct2D brush. public static SharpDX.Direct2D1.Brush ToDirect2D(this Perspex.Media.Brush brush, RenderTarget target) { Perspex.Media.SolidColorBrush solidColorBrush = brush as Perspex.Media.SolidColorBrush; if (solidColorBrush != null) { return new SharpDX.Direct2D1.SolidColorBrush(target, solidColorBrush.Color.ToDirect2D()); } else { // TODO: Implement other brushes. return new SharpDX.Direct2D1.SolidColorBrush(target, new Color4()); } } /// /// Converts a Perspex to Direct2D. /// /// The color to convert. /// The Direct2D color. public static Color4 ToDirect2D(this Perspex.Media.Color color) { return new Color4( (float)(color.R / 255.0), (float)(color.G / 255.0), (float)(color.B / 255.0), (float)(color.A / 255.0)); } /// /// Converts a Perspex to a Direct2D /// /// The . /// The . public static Matrix3x2 ToDirect2D(this Perspex.Matrix matrix) { return new Matrix3x2( (float)matrix.M11, (float)matrix.M12, (float)matrix.M21, (float)matrix.M22, (float)matrix.OffsetX, (float)matrix.OffsetY); } /// /// Converts a Direct2D to a Perspex . /// /// /// a . public static Perspex.Matrix ToPerspex(this Matrix3x2 matrix) { return new Perspex.Matrix( matrix.M11, matrix.M12, matrix.M21, matrix.M22, matrix.M31, matrix.M32); } /// /// Converts a Perspex to a Direct2D /// /// The . /// The . public static RectangleF ToDirect2D(this Rect rect) { return new RectangleF( (float)rect.X, (float)rect.Y, (float)rect.Width, (float)rect.Height); } } }