Browse Source

Merge branch 'master' into visualbrush

pull/111/head
Steven Kirk 11 years ago
parent
commit
d24b8ad3f9
  1. 32
      src/Gtk/Perspex.Cairo/Media/DrawingContext.cs
  2. 14
      src/Windows/Perspex.Direct2D1/Media/BrushImpl.cs
  3. 4
      src/Windows/Perspex.Direct2D1/Media/DrawingContext.cs
  4. 6
      src/Windows/Perspex.Direct2D1/Media/LinearGradientBrushImpl.cs
  5. 17
      src/Windows/Perspex.Direct2D1/Media/SolidColorBrushImpl.cs

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

@ -101,7 +101,9 @@ namespace Perspex.Cairo.Media
/// <param name="p1">The second point of the line.</param>
public void DrawLine(Pen pen, Perspex.Point p1, Perspex.Point p2)
{
this.SetBrush(pen.Brush);
var size = new Rect(p1, p2).Size;
this.SetBrush(pen.Brush, size);
this.context.LineWidth = pen.Thickness;
this.context.MoveTo(p1.ToCairo());
this.context.LineTo(p2.ToCairo());
@ -149,7 +151,7 @@ namespace Perspex.Cairo.Media
if (brush != null)
{
this.SetBrush(brush);
this.SetBrush(brush, geometry.Bounds.Size);
if (pen != null)
this.context.FillPreserve();
@ -160,7 +162,7 @@ namespace Perspex.Cairo.Media
if (pen != null)
{
this.SetPen(pen);
this.SetPen(pen, geometry.Bounds.Size);
this.context.Stroke();
}
}
@ -173,7 +175,7 @@ namespace Perspex.Cairo.Media
/// <param name="rect">The rectangle bounds.</param>
public void DrawRectange(Pen pen, Rect rect, float cornerRadius)
{
this.SetPen(pen);
this.SetPen(pen, rect.Size);
this.context.Rectangle(rect.ToCairo());
this.context.Stroke();
}
@ -187,7 +189,7 @@ namespace Perspex.Cairo.Media
public void DrawText(Brush foreground, Point origin, FormattedText text)
{
var layout = ((FormattedTextImpl)text.PlatformImpl).Layout;
this.SetBrush(foreground);
this.SetBrush(foreground, new Size(0, 0));
this.context.MoveTo(origin.X, origin.Y);
Pango.CairoHelper.ShowLayout(this.context, layout);
@ -200,7 +202,7 @@ namespace Perspex.Cairo.Media
/// <param name="rect">The rectangle bounds.</param>
public void FillRectange(Perspex.Media.Brush brush, Rect rect, float cornerRadius)
{
this.SetBrush(brush);
this.SetBrush(brush, rect.Size);
this.context.Rectangle(rect.ToCairo());
this.context.Fill();
}
@ -244,9 +246,10 @@ namespace Perspex.Cairo.Media
});
}
private void SetBrush(Brush brush)
private void SetBrush(Brush brush, Size destinationSize)
{
var solid = brush as SolidColorBrush;
var linearGradientBrush = brush as LinearGradientBrush;
if (solid != null)
{
@ -256,11 +259,22 @@ namespace Perspex.Cairo.Media
solid.Color.B / 255.0,
solid.Color.A / 255.0);
}
else if (linearGradientBrush != null)
{
Cairo.LinearGradient g = new Cairo.LinearGradient(linearGradientBrush.StartPoint.X * destinationSize.Width, linearGradientBrush.StartPoint.Y * destinationSize.Height, linearGradientBrush.EndPoint.X * destinationSize.Width, linearGradientBrush.EndPoint.Y * destinationSize.Height);
foreach (var s in linearGradientBrush.GradientStops)
g.AddColorStopRgb(s.Offset, new Cairo.Color(s.Color.R, s.Color.G, s.Color.B, s.Color.A));
g.Extend = Cairo.Extend.Pad;
this.context.SetSource(g);
}
}
private void SetPen(Pen pen)
private void SetPen(Pen pen, Size destinationSize)
{
this.SetBrush(pen.Brush);
this.SetBrush(pen.Brush, destinationSize);
this.context.LineWidth = pen.Thickness;
}
}

14
src/Windows/Perspex.Direct2D1/Media/BrushImpl.cs

@ -1,19 +1,23 @@
using System;
// -----------------------------------------------------------------------
// <copyright file="BrushImpl.cs" company="Steven Kirk">
// Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Direct2D1.Media
{
using System;
public abstract class BrushImpl : IDisposable
{
public SharpDX.Direct2D1.Brush PlatformBrush { get; set; }
public BrushImpl(Perspex.Media.Brush brush, SharpDX.Direct2D1.RenderTarget target, Size destinationSize)
{
}
public virtual void Dispose()
{
if (this.PlatformBrush != null)
{
this.PlatformBrush.Dispose();
}
}
}
}

4
src/Windows/Perspex.Direct2D1/Media/DrawingContext.cs

@ -293,7 +293,7 @@ namespace Perspex.Direct2D1.Media
if (solidColorBrush != null)
{
return new SolidColorBrushImpl(solidColorBrush, this.renderTarget, destinationSize);
return new SolidColorBrushImpl(solidColorBrush, this.renderTarget);
}
else if (linearGradientBrush != null)
{
@ -305,7 +305,7 @@ namespace Perspex.Direct2D1.Media
}
else
{
return new SolidColorBrushImpl(null, this.renderTarget, destinationSize);
return new SolidColorBrushImpl(null, this.renderTarget);
}
}
}

6
src/Windows/Perspex.Direct2D1/Media/LinearGradientBrushImpl.cs

@ -8,8 +8,10 @@
public class LinearGradientBrushImpl : BrushImpl
{
public LinearGradientBrushImpl(Perspex.Media.LinearGradientBrush brush, SharpDX.Direct2D1.RenderTarget target, Size destinationSize)
: base(brush, target, destinationSize)
public LinearGradientBrushImpl(
Perspex.Media.LinearGradientBrush brush,
SharpDX.Direct2D1.RenderTarget target,
Size destinationSize)
{
if (brush != null)
{

17
src/Windows/Perspex.Direct2D1/Media/SolidColorBrushImpl.cs

@ -1,15 +1,14 @@
namespace Perspex.Direct2D1.Media
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// -----------------------------------------------------------------------
// <copyright file="SolidColorBrushImpl.cs" company="Steven Kirk">
// Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Direct2D1.Media
{
public class SolidColorBrushImpl : BrushImpl
{
public SolidColorBrushImpl(Perspex.Media.SolidColorBrush brush, SharpDX.Direct2D1.RenderTarget target, Size destinationSize)
: base(brush, target, destinationSize)
public SolidColorBrushImpl(Perspex.Media.SolidColorBrush brush, SharpDX.Direct2D1.RenderTarget target)
{
this.PlatformBrush = new SharpDX.Direct2D1.SolidColorBrush(target, brush?.Color.ToDirect2D() ?? new SharpDX.Color4());
}

Loading…
Cancel
Save