Browse Source

Implemented StreamGeometryContext.SetFillRule

pull/403/head
Nikita Tsukanov 11 years ago
parent
commit
415c9c6e18
  1. 4
      src/Gtk/Perspex.Cairo/Media/DrawingContext.cs
  2. 12
      src/Gtk/Perspex.Cairo/Media/StreamGeometryContextImpl.cs
  3. 4
      src/Gtk/Perspex.Cairo/Media/StreamGeometryImpl.cs
  4. 8
      src/Perspex.SceneGraph/Media/FillRule.cs
  5. 10
      src/Perspex.SceneGraph/Media/StreamGeometryContext.cs
  6. 1
      src/Perspex.SceneGraph/Perspex.SceneGraph.csproj
  7. 2
      src/Perspex.SceneGraph/Platform/IStreamGeometryContextImpl.cs
  8. 2
      src/Skia/Perspex.Skia/DrawingContextImpl.cs
  9. 2
      src/Skia/Perspex.Skia/MethodTable.cs
  10. 7
      src/Skia/Perspex.Skia/StreamGeometryImpl.cs
  11. 2
      src/Skia/native.url
  12. 7
      src/Windows/Perspex.Direct2D1/Media/StreamGeometryContextImpl.cs

4
src/Gtk/Perspex.Cairo/Media/DrawingContext.cs

@ -148,6 +148,10 @@ namespace Perspex.Cairo.Media
_context.AppendPath(impl.Path);
using (var b = SetBrush(brush, geometry.Bounds.Size))
{
_context.FillRule = impl.FillRule == FillRule.EvenOdd
? Cairo.FillRule.EvenOdd
: Cairo.FillRule.Winding;
if (pen != null)
_context.FillPreserve();
else

12
src/Gtk/Perspex.Cairo/Media/StreamGeometryContextImpl.cs

@ -13,11 +13,13 @@ namespace Perspex.Cairo.Media
public class StreamGeometryContextImpl : IStreamGeometryContextImpl
{
private readonly StreamGeometryImpl _target;
private Point _currentPoint;
public StreamGeometryContextImpl(Cairo.Path path = null)
public StreamGeometryContextImpl(StreamGeometryImpl target, Cairo.Path path)
{
_target = target;
_surf = new Cairo.ImageSurface (Cairo.Format.Argb32, 0, 0);
_surf = new Cairo.ImageSurface (Cairo.Format.Argb32, 0, 0);
_context = new Cairo.Context (_surf);
this.Path = path;
@ -86,6 +88,12 @@ namespace Perspex.Cairo.Media
}
}
public void SetFillRule(FillRule fillRule)
{
_target.FillRule = fillRule;
}
public void Dispose()
{
_context.Dispose ();

4
src/Gtk/Perspex.Cairo/Media/StreamGeometryImpl.cs

@ -14,7 +14,7 @@ namespace Perspex.Cairo.Media
{
public StreamGeometryImpl()
{
_impl = new StreamGeometryContextImpl(null);
_impl = new StreamGeometryContextImpl(this, null);
}
public StreamGeometryImpl(StreamGeometryContextImpl impl)
@ -50,6 +50,8 @@ namespace Perspex.Cairo.Media
}
}
public FillRule FillRule { get; set; }
public IStreamGeometryImpl Clone()
{
return new StreamGeometryImpl(_impl);

8
src/Perspex.SceneGraph/Media/FillRule.cs

@ -0,0 +1,8 @@
namespace Perspex.Media
{
public enum FillRule
{
EvenOdd,
NonZero
}
}

10
src/Perspex.SceneGraph/Media/StreamGeometryContext.cs

@ -28,6 +28,16 @@ namespace Perspex.Media
_impl = impl;
}
/// <summary>
/// Sets path's winding rule (default is EvenOdd). You should call this method before any calls to BeginFigure. If you wonder why, ask Direct2D guys about their design decisions.
/// </summary>
/// <param name="fillRule"></param>
public void SetFillRule(FillRule fillRule)
{
_impl.SetFillRule(fillRule);
}
/// <summary>
/// Draws an arc to the specified point.
/// </summary>

1
src/Perspex.SceneGraph/Perspex.SceneGraph.csproj

@ -67,6 +67,7 @@
<Compile Include="Media\Colors.cs" />
<Compile Include="Media\DashStyle.cs" />
<Compile Include="Media\DrawingContext.cs" />
<Compile Include="Media\FillRule.cs" />
<Compile Include="Media\GradientBrush.cs" />
<Compile Include="Media\GradientSpreadMethod.cs" />
<Compile Include="Media\GradientStop.cs" />

2
src/Perspex.SceneGraph/Platform/IStreamGeometryContextImpl.cs

@ -56,5 +56,7 @@ namespace Perspex.Platform
/// </summary>
/// <param name="isClosed">Whether the figure is closed.</param>
void EndFigure(bool isClosed);
void SetFillRule(FillRule fillRule);
}
}

2
src/Skia/Perspex.Skia/DrawingContextImpl.cs

@ -46,7 +46,7 @@ namespace Perspex.Skia
using (var stroke = pen?.Brush != null ? CreateBrush(pen, size) : null)
{
MethodTable.Instance.DrawGeometry(Handle, impl.Path.Handle, fill != null ? fill.Brush : null,
stroke != null ? stroke.Brush : null);
stroke != null ? stroke.Brush : null, impl.FillRule == FillRule.EvenOdd);
}
Transform = oldTransform;
}

2
src/Skia/Perspex.Skia/MethodTable.cs

@ -67,7 +67,7 @@ namespace Perspex.Skia
public _DisposePath DisposePath;
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void _DrawGeometry(IntPtr ctx, IntPtr path, void* fill, void* stroke);
public delegate void _DrawGeometry(IntPtr ctx, IntPtr path, void* fill, void* stroke, bool useEvenOdd);
public _DrawGeometry DrawGeometry;

7
src/Skia/Perspex.Skia/StreamGeometryImpl.cs

@ -140,6 +140,13 @@ namespace Perspex.Skia
Flag = isClosed
});
}
public void SetFillRule(FillRule fillRule)
{
_geometryImpl.FillRule = fillRule;
}
}
public FillRule FillRule { get; set; }
}
}

2
src/Skia/native.url

@ -1 +1 @@
https://dl.dropboxusercontent.com/u/18301199/Perspex.Skia/abi-0002.zip
https://dl.dropboxusercontent.com/u/18301199/Perspex.Skia/abi-0003.zip

7
src/Windows/Perspex.Direct2D1/Media/StreamGeometryContextImpl.cs

@ -1,8 +1,10 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using Perspex.Media;
using Perspex.Platform;
using SharpDX.Direct2D1;
using SweepDirection = SharpDX.Direct2D1.SweepDirection;
namespace Perspex.Direct2D1.Media
{
@ -66,6 +68,11 @@ namespace Perspex.Direct2D1.Media
_sink.EndFigure(isClosed ? FigureEnd.Closed : FigureEnd.Open);
}
public void SetFillRule(FillRule fillRule)
{
_sink.SetFillMode(fillRule == FillRule.EvenOdd ? FillMode.Alternate : FillMode.Winding);
}
public void Dispose()
{
_sink.Close();

Loading…
Cancel
Save