Browse Source

Use context.Save/Restore

droid
Nikita Tsukanov 11 years ago
parent
commit
d03f5ce725
  1. 11
      src/Gtk/Perspex.Cairo/Media/DrawingContext.cs

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

@ -4,6 +4,7 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Reactive.Disposables; using System.Reactive.Disposables;
using System.Runtime.InteropServices;
using Perspex.Cairo.Media.Imaging; using Perspex.Cairo.Media.Imaging;
using Perspex.Media; using Perspex.Media;
@ -200,6 +201,8 @@ namespace Perspex.Cairo.Media
} }
} }
private static Random Random = new Random();
/// <summary> /// <summary>
/// Pushes a clip rectange. /// Pushes a clip rectange.
/// </summary> /// </summary>
@ -207,10 +210,13 @@ namespace Perspex.Cairo.Media
/// <returns>A disposable used to undo the clip rectangle.</returns> /// <returns>A disposable used to undo the clip rectangle.</returns>
public IDisposable PushClip(Rect clip) public IDisposable PushClip(Rect clip)
{ {
_context.Save();
uint fill = 0x90000000 | (unchecked((uint) Random.Next(int.MinValue, int.MaxValue)));
FillRectangle(new SolidColorBrush(fill), clip, 0);
_context.Rectangle(clip.ToCairo()); _context.Rectangle(clip.ToCairo());
_context.Clip(); _context.Clip();
return Disposable.Create(() => _context.ResetClip()); return Disposable.Create(() => _context.Restore());
} }
/// <summary> /// <summary>
@ -238,11 +244,12 @@ namespace Perspex.Cairo.Media
/// <returns>A disposable used to undo the transformation.</returns> /// <returns>A disposable used to undo the transformation.</returns>
public IDisposable PushTransform(Matrix matrix) public IDisposable PushTransform(Matrix matrix)
{ {
_context.Save();
_context.Transform(matrix.ToCairo()); _context.Transform(matrix.ToCairo());
return Disposable.Create(() => return Disposable.Create(() =>
{ {
_context.Transform(matrix.Invert().ToCairo()); _context.Restore();
}); });
} }

Loading…
Cancel
Save