23 changed files with 590 additions and 8 deletions
@ -0,0 +1,67 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="CairoPlatform.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Cairo |
|||
{ |
|||
using System; |
|||
using global::Cairo; |
|||
using Perspex.Cairo.Media; |
|||
using Perspex.Cairo.Media.Imaging; |
|||
using Perspex.Platform; |
|||
using Perspex.Threading; |
|||
using Splat; |
|||
|
|||
public class CairoPlatform : IPlatformRenderInterface |
|||
{ |
|||
private static CairoPlatform instance = new CairoPlatform(); |
|||
|
|||
private static TextService textService = new TextService(); |
|||
|
|||
public static void Initialize() |
|||
{ |
|||
var locator = Locator.CurrentMutable; |
|||
locator.Register(() => instance, typeof(IPlatformRenderInterface)); |
|||
locator.Register(() => textService, typeof(ITextService)); |
|||
//locator.Register(() => d2d1Factory, typeof(SharpDX.Direct2D1.Factory));
|
|||
//locator.Register(() => dwFactory, typeof(SharpDX.DirectWrite.Factory));
|
|||
//locator.Register(() => imagingFactory, typeof(SharpDX.WIC.ImagingFactory));
|
|||
} |
|||
|
|||
public ITextService TextService |
|||
{ |
|||
get { /*return textService;*/ throw new NotImplementedException(); } |
|||
} |
|||
|
|||
public IBitmapImpl CreateBitmap(int width, int height) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
//return new BitmapImpl(imagingFactory, width, height);
|
|||
} |
|||
|
|||
public IRenderer CreateRenderer(IntPtr handle, double width, double height) |
|||
{ |
|||
return new Renderer(handle, width, height); |
|||
} |
|||
|
|||
public IRenderTargetBitmapImpl CreateRenderTargetBitmap(int width, int height) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
//return new RenderTargetBitmapImpl(imagingFactory, d2d1Factory, width, height);
|
|||
} |
|||
|
|||
public IStreamGeometryImpl CreateStreamGeometry() |
|||
{ |
|||
throw new NotImplementedException(); |
|||
//return new StreamGeometryImpl();
|
|||
} |
|||
|
|||
public IBitmapImpl LoadBitmap(string fileName) |
|||
{ |
|||
ImageSurface result = new ImageSurface(fileName); |
|||
return new BitmapImpl(result); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,151 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="DrawingContext.cs" company="Steven Kirk">
|
|||
// Copyright 2013 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Cairo.Media |
|||
{ |
|||
using System; |
|||
using System.Reactive.Disposables; |
|||
using global::Cairo; |
|||
using Perspex.Media; |
|||
using IBitmap = Perspex.Media.Imaging.IBitmap; |
|||
using Matrix = Perspex.Matrix; |
|||
|
|||
/// <summary>
|
|||
/// Draws using Direct2D1.
|
|||
/// </summary>
|
|||
public class DrawingContext : IDrawingContext, IDisposable |
|||
{ |
|||
/// <summary>
|
|||
/// The cairo context.
|
|||
/// </summary>
|
|||
private Context context; |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="DrawingContext"/> class.
|
|||
/// </summary>
|
|||
/// <param name="surface">The target surface.</param>
|
|||
public DrawingContext(Surface surface) |
|||
{ |
|||
this.context = new Context(surface); |
|||
} |
|||
|
|||
public Matrix CurrentTransform |
|||
{ |
|||
get { throw new NotImplementedException(); } |
|||
set { throw new NotImplementedException(); } |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Ends a draw operation.
|
|||
/// </summary>
|
|||
public void Dispose() |
|||
{ |
|||
this.context.Dispose(); |
|||
} |
|||
|
|||
public void DrawImage(IBitmap bitmap, double opacity, Rect sourceRect, Rect destRect) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Draws a line.
|
|||
/// </summary>
|
|||
/// <param name="pen">The stroke pen.</param>
|
|||
/// <param name="p1">The first point of the line.</param>
|
|||
/// <param name="p1">The second point of the line.</param>
|
|||
public void DrawLine(Pen pen, Perspex.Point p1, Perspex.Point p2) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Draws a geometry.
|
|||
/// </summary>
|
|||
/// <param name="brush">The fill brush.</param>
|
|||
/// <param name="pen">The stroke pen.</param>
|
|||
/// <param name="geometry">The geometry.</param>
|
|||
public void DrawGeometry(Perspex.Media.Brush brush, Perspex.Media.Pen pen, Perspex.Media.Geometry geometry) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Draws the outline of a rectangle.
|
|||
/// </summary>
|
|||
/// <param name="pen">The pen.</param>
|
|||
/// <param name="rect">The rectangle bounds.</param>
|
|||
public void DrawRectange(Pen pen, Rect rect) |
|||
{ |
|||
this.SetPen(pen); |
|||
this.context.Rectangle(rect.X, rect.Y, rect.Width, rect.Height); |
|||
this.context.Stroke(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Draws text.
|
|||
/// </summary>
|
|||
/// <param name="foreground">The foreground brush.</param>
|
|||
/// <param name="rect">The output rectangle.</param>
|
|||
/// <param name="text">The text.</param>
|
|||
public void DrawText(Perspex.Media.Brush foreground, Rect rect, FormattedText text) |
|||
{ |
|||
// TODO: Implement
|
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Draws a filled rectangle.
|
|||
/// </summary>
|
|||
/// <param name="brush">The brush.</param>
|
|||
/// <param name="rect">The rectangle bounds.</param>
|
|||
public void FillRectange(Perspex.Media.Brush brush, Rect rect) |
|||
{ |
|||
this.SetBrush(brush); |
|||
this.context.Rectangle(rect.X, rect.Y, rect.Width, rect.Height); |
|||
this.context.Fill(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Pushes a clip rectange.
|
|||
/// </summary>
|
|||
/// <param name="clip">The clip rectangle.</param>
|
|||
/// <returns>A disposable used to undo the clip rectangle.</returns>
|
|||
public IDisposable PushClip(Rect clip) |
|||
{ |
|||
return Disposable.Empty; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Pushes a matrix transformation.
|
|||
/// </summary>
|
|||
/// <param name="matrix">The matrix</param>
|
|||
/// <returns>A disposable used to undo the transformation.</returns>
|
|||
public IDisposable PushTransform(Matrix matrix) |
|||
{ |
|||
return Disposable.Empty; |
|||
} |
|||
|
|||
private void SetBrush(Brush brush) |
|||
{ |
|||
var solid = brush as SolidColorBrush; |
|||
|
|||
if (solid != null) |
|||
{ |
|||
this.context.SetSourceRGBA( |
|||
solid.Color.R / 255.0, |
|||
solid.Color.G / 255.0, |
|||
solid.Color.B / 255.0, |
|||
solid.Color.A / 255.0); |
|||
} |
|||
} |
|||
|
|||
private void SetPen(Pen pen) |
|||
{ |
|||
this.SetBrush(pen.Brush); |
|||
this.context.LineWidth = pen.Thickness; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="BitmapImpl.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Cairo.Media.Imaging |
|||
{ |
|||
using System; |
|||
using global::Cairo; |
|||
using Perspex.Platform; |
|||
|
|||
public class BitmapImpl : IBitmapImpl |
|||
{ |
|||
private ImageSurface surface; |
|||
|
|||
public BitmapImpl(ImageSurface surface) |
|||
{ |
|||
this.surface = surface; |
|||
} |
|||
|
|||
public int PixelWidth |
|||
{ |
|||
get { return this.surface.Width; } |
|||
} |
|||
|
|||
public int PixelHeight |
|||
{ |
|||
get { return this.surface.Height; } |
|||
} |
|||
|
|||
public void Save(string fileName) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,40 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="TextService.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Cairo.Media |
|||
{ |
|||
using System; |
|||
using System.Linq; |
|||
using Perspex.Media; |
|||
using Perspex.Platform; |
|||
|
|||
public class TextService : ITextService |
|||
{ |
|||
public TextService() |
|||
{ |
|||
} |
|||
|
|||
public int GetCaretIndex(FormattedText text, Point point, Size constraint) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public Point GetCaretPosition(FormattedText text, int caretIndex, Size constraint) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public double[] GetLineHeights(FormattedText text, Size constraint) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public Size Measure(FormattedText text, Size constraint) |
|||
{ |
|||
return new Size(100, 30); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,110 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> |
|||
<PropertyGroup> |
|||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
|||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
|||
<ProjectGuid>{FB05AC90-89BA-4F2F-A924-F37875FB547C}</ProjectGuid> |
|||
<OutputType>Library</OutputType> |
|||
<AppDesignerFolder>Properties</AppDesignerFolder> |
|||
<RootNamespace>Perspex.Cairo</RootNamespace> |
|||
<AssemblyName>Perspex.Cairo</AssemblyName> |
|||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> |
|||
<FileAlignment>512</FileAlignment> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
|||
<DebugSymbols>true</DebugSymbols> |
|||
<DebugType>full</DebugType> |
|||
<Optimize>false</Optimize> |
|||
<OutputPath>bin\Debug\</OutputPath> |
|||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
|||
<DebugType>pdbonly</DebugType> |
|||
<Optimize>true</Optimize> |
|||
<OutputPath>bin\Release\</OutputPath> |
|||
<DefineConstants>TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
</PropertyGroup> |
|||
<ItemGroup> |
|||
<Reference Include="Mono.Cairo"> |
|||
<HintPath>..\..\Dependencies\Mono.Cairo.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="Splat"> |
|||
<HintPath>..\..\packages\Splat.1.5.1\lib\Net45\Splat.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="System" /> |
|||
<Reference Include="System.Core" /> |
|||
<Reference Include="System.Reactive.Core, Version=2.2.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> |
|||
<SpecificVersion>False</SpecificVersion> |
|||
<HintPath>..\..\packages\Rx-Core.2.2.5\lib\net45\System.Reactive.Core.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="System.Reactive.Interfaces, Version=2.2.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> |
|||
<SpecificVersion>False</SpecificVersion> |
|||
<HintPath>..\..\packages\Rx-Interfaces.2.2.5\lib\net45\System.Reactive.Interfaces.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="System.Xml.Linq" /> |
|||
<Reference Include="System.Data.DataSetExtensions" /> |
|||
<Reference Include="Microsoft.CSharp" /> |
|||
<Reference Include="System.Data" /> |
|||
<Reference Include="System.Xml" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<Compile Include="CairoPlatform.cs" /> |
|||
<Compile Include="Media\DrawingContext.cs" /> |
|||
<Compile Include="Media\Imaging\BitmapImpl.cs" /> |
|||
<Compile Include="Media\TextService.cs" /> |
|||
<Compile Include="Properties\AssemblyInfo.cs" /> |
|||
<Compile Include="Renderer.cs" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\Perspex.Base\Perspex.Base.csproj"> |
|||
<Project>{b09b78d8-9b26-48b0-9149-d64a2f120f3f}</Project> |
|||
<Name>Perspex.Base</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\Perspex.SceneGraph\Perspex.SceneGraph.csproj"> |
|||
<Project>{eb582467-6abb-43a1-b052-e981ba910e3a}</Project> |
|||
<Name>Perspex.SceneGraph</Name> |
|||
</ProjectReference> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<None Include="packages.config" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<Content Include="libcairo-2.dll"> |
|||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
|||
</Content> |
|||
<Content Include="libfontconfig-1.dll"> |
|||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
|||
</Content> |
|||
<Content Include="libfreetype-6.dll"> |
|||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
|||
</Content> |
|||
<Content Include="libiconv-2.dll"> |
|||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
|||
</Content> |
|||
<Content Include="liblzma-5.dll"> |
|||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
|||
</Content> |
|||
<Content Include="libpixman-1-0.dll"> |
|||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
|||
</Content> |
|||
<Content Include="libpng15-15.dll"> |
|||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
|||
</Content> |
|||
<Content Include="libxml2-2.dll"> |
|||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
|||
</Content> |
|||
</ItemGroup> |
|||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
|||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
|||
Other similar extension points exist, see Microsoft.Common.targets. |
|||
<Target Name="BeforeBuild"> |
|||
</Target> |
|||
<Target Name="AfterBuild"> |
|||
</Target> |
|||
--> |
|||
</Project> |
|||
@ -0,0 +1,36 @@ |
|||
using System.Reflection; |
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
|
|||
// General Information about an assembly is controlled through the following
|
|||
// set of attributes. Change these attribute values to modify the information
|
|||
// associated with an assembly.
|
|||
[assembly: AssemblyTitle("Perspex.Cairo")] |
|||
[assembly: AssemblyDescription("")] |
|||
[assembly: AssemblyConfiguration("")] |
|||
[assembly: AssemblyCompany("")] |
|||
[assembly: AssemblyProduct("Perspex.Cairo")] |
|||
[assembly: AssemblyCopyright("Copyright © 2014")] |
|||
[assembly: AssemblyTrademark("")] |
|||
[assembly: AssemblyCulture("")] |
|||
|
|||
// Setting ComVisible to false makes the types in this assembly not visible
|
|||
// to COM components. If you need to access a type in this assembly from
|
|||
// COM, set the ComVisible attribute to true on that type.
|
|||
[assembly: ComVisible(false)] |
|||
|
|||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
|||
[assembly: Guid("f999ba8b-64e7-40cc-98a4-003f1852d2a3")] |
|||
|
|||
// Version information for an assembly consists of the following four values:
|
|||
//
|
|||
// Major Version
|
|||
// Minor Version
|
|||
// Build Number
|
|||
// Revision
|
|||
//
|
|||
// You can specify all the values or you can default the Build and Revision Numbers
|
|||
// by using the '*' as shown below:
|
|||
// [assembly: AssemblyVersion("1.0.*")]
|
|||
[assembly: AssemblyVersion("1.0.0.0")] |
|||
[assembly: AssemblyFileVersion("1.0.0.0")] |
|||
@ -0,0 +1,104 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="Renderer.cs" company="Steven Kirk">
|
|||
// Copyright 2013 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Cairo |
|||
{ |
|||
using System; |
|||
using Perspex.Platform; |
|||
using Splat; |
|||
using global::Cairo; |
|||
using System.Runtime.InteropServices; |
|||
using Perspex.Cairo.Media; |
|||
using Matrix = Perspex.Matrix; |
|||
|
|||
public class Renderer : IRenderer |
|||
{ |
|||
/// <summary>
|
|||
/// The target cairo surface.
|
|||
/// </summary>
|
|||
private Surface surface; |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Renderer"/> class.
|
|||
/// </summary>
|
|||
/// <param name="hwnd">The window handle.</param>
|
|||
/// <param name="width">The width of the window.</param>
|
|||
/// <param name="height">The height of the window.</param>
|
|||
public Renderer(IntPtr hwnd, double width, double height) |
|||
{ |
|||
surface = new Win32Surface(GetDC(hwnd)); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Renderer"/> class.
|
|||
/// </summary>
|
|||
/// <param name="surface">The target surface.</param>
|
|||
public Renderer(Surface surface) |
|||
{ |
|||
this.surface = surface; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Renders the specified visual.
|
|||
/// </summary>
|
|||
/// <param name="visual">The visual to render.</param>
|
|||
public void Render(IVisual visual) |
|||
{ |
|||
using (DrawingContext context = new DrawingContext(this.surface)) |
|||
{ |
|||
this.Render(visual, context); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Resizes the renderer.
|
|||
/// </summary>
|
|||
/// <param name="width">The new width.</param>
|
|||
/// <param name="height">The new height.</param>
|
|||
public void Resize(int width, int height) |
|||
{ |
|||
var s = this.surface.CreateSimilar(Content.ColorAlpha, width, height); |
|||
this.surface.Dispose(); |
|||
this.surface = s; |
|||
} |
|||
|
|||
[DllImport("user32.dll")] |
|||
private static extern IntPtr GetDC(IntPtr hWnd); |
|||
|
|||
/// <summary>
|
|||
/// Renders the specified visual.
|
|||
/// </summary>
|
|||
/// <param name="visual">The visual to render.</param>
|
|||
/// <param name="context">The drawing context.</param>
|
|||
private void Render(IVisual visual, DrawingContext context) |
|||
{ |
|||
if (visual.IsVisible && visual.Opacity > 0) |
|||
{ |
|||
Matrix transform = Matrix.Identity; |
|||
|
|||
if (visual.RenderTransform != null) |
|||
{ |
|||
Matrix current = context.CurrentTransform; |
|||
Matrix offset = Matrix.Translation(visual.TransformOrigin.ToPixels(visual.Bounds.Size)); |
|||
transform = -current * -offset * visual.RenderTransform.Value * offset * current; |
|||
} |
|||
|
|||
transform *= Matrix.Translation(visual.Bounds.Position); |
|||
|
|||
using (context.PushClip(visual.Bounds)) |
|||
using (context.PushTransform(transform)) |
|||
{ |
|||
visual.Render(context); |
|||
|
|||
foreach (var child in visual.VisualChildren) |
|||
{ |
|||
this.Render(child, context); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,6 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<packages> |
|||
<package id="Rx-Core" version="2.2.5" targetFramework="net45" /> |
|||
<package id="Rx-Interfaces" version="2.2.5" targetFramework="net45" /> |
|||
<package id="Splat" version="1.5.1" targetFramework="net45" /> |
|||
</packages> |
|||
Binary file not shown.
Loading…
Reference in new issue