<commit_before>using System;
using Eto.Drawing;
using sd = System.Drawing;

#if DESKTOP
using MonoMac.CoreGraphics;
using MonoMac.ImageIO;

namespace Eto.Platform.Mac.Drawing
#else
using MonoTouch.CoreGraphics;
using MonoTouch.ImageIO;

namespace Eto.Platform.iOS.Drawing
#endif
{
	/// <summary>
	/// Handler for <see cref="ITextureBrush"/>
	/// </summary>
	/// <copyright>(c) 2012 by <NAME></copyright>
	/// <license type="BSD-3">See LICENSE for full terms</license>
	public class TextureBrushHandler : BrushHandler, ITextureBrush
	{
		class BrushObject
		{
			CGImage image;
			CGAffineTransform transform;
			float [] alpha = new float[] { 1f };
			CGPattern pattern;

			public void Apply (GraphicsHandler graphics)
			{
				using (var patternSpace = CGColorSpace.CreatePattern (null)) {
					graphics.Control.SetFillColorSpace (patternSpace);
				}
				graphics.Control.SetFillPattern (pattern, alpha);
			}
			
			public CGImage Image
			{
				get { return image; }
				set
				{
					image = value;
					SetPattern ();
				}
			}

			public float Opacity
			{
				get { return alpha[0]; }
				set { alpha[0] = value; }
			}
			
			public CGAffineTransform Transform
			{
				get { return transform; }
				set {
					transform = value;
					transform.Scale (1f, -1f);
					SetPattern ();
				}
			}

			void DrawPattern (CGContext context)
			{
				var destRect = new sd.RectangleF(0, 0, image.Width, image.Height);
				context.TranslateCTM (0, image.Height / 2);
				context.ScaleCTM (1f, -1f);
				context.TranslateCTM (0, -image.Height / 2);
				context.DrawImage (destRect, image);
			}

			void SetPattern ()
			{
				pattern = new CGPattern(new sd.RectangleF(0, 0, image.Width, image.Height), transform, image.Width, image.Height, CGPatternTiling.ConstantSpacing, true, DrawPattern);
			}
		}

		public object Create (Image image, float opacity)
		{
			return new BrushObject {
				Image = image.ToCG (),
				Opacity = opacity
			};
		}

		public IMatrix GetTransform (TextureBrush widget)
		{
			return ((BrushObject)widget.ControlObject).Transform.ToEto ();
		}

		public void SetTransform (TextureBrush widget, IMatrix transform)
		{
			((BrushObject)widget.ControlObject).Transform = transform.ToCG ();
		}
<commit_msg>Fix Mac TextureBrush.Transform. (There still seems to be a bug in the Mac TextureBrush, but this probably a step in the right direction.)<commit_after>using System;
using Eto.Drawing;
using sd = System.Drawing;

#if DESKTOP
using MonoMac.CoreGraphics;
using MonoMac.ImageIO;

namespace Eto.Platform.Mac.Drawing
#else
using MonoTouch.CoreGraphics;
using MonoTouch.ImageIO;

namespace Eto.Platform.iOS.Drawing
#endif
{
	/// <summary>
	/// Handler for <see cref="ITextureBrush"/>
	/// </summary>
	/// <copyright>(c) 2012 by <NAME></copyright>
	/// <license type="BSD-3">See LICENSE for full terms</license>
	public class TextureBrushHandler : BrushHandler, ITextureBrush
	{
		class BrushObject
		{
			CGImage image;
			CGAffineTransform transform = CGAffineTransform.MakeIdentity();
			float [] alpha = new float[] { 1f };
			CGPattern pattern;

			public void Apply (GraphicsHandler graphics)
			{
				using (var patternSpace = CGColorSpace.CreatePattern (null)) {
					graphics.Control.SetFillColorSpace (patternSpace);
				}
				graphics.Control.SetFillPattern (pattern, alpha);
			}
			
			public CGImage Image
			{
				get { return image; }
				set
				{
					image = value;
					SetPattern ();
				}
			}

			public float Opacity
			{
				get { return alpha[0]; }
				set { alpha[0] = value; }
			}
			
			public CGAffineTransform Transform
			{
				get { return transform; }
				set {
					transform = value;					
					SetPattern ();
				}
			}

			void DrawPattern (CGContext context)
			{
				var destRect = new sd.RectangleF(0, 0, image.Width, image.Height);
				context.TranslateCTM (0, image.Height / 2);
				context.ScaleCTM (1f, -1f);
				context.TranslateCTM (0, -image.Height / 2);
				context.DrawImage (destRect, image);
			}

			void SetPattern ()
			{
				var t = transform;
				t.Scale(1f, -1f);
				pattern = new CGPattern(new sd.RectangleF(0, 0, image.Width, image.Height), t, image.Width, image.Height, CGPatternTiling.ConstantSpacing, true, DrawPattern);
			}
		}

		public object Create (Image image, float opacity)
		{
			return new BrushObject {
				Image = image.ToCG (),
				Opacity = opacity
			};
		}

		public IMatrix GetTransform (TextureBrush widget)
		{
			return ((BrushObject)widget.ControlObject).Transform.ToEto ();
		}

		public void SetTransform (TextureBrush widget, IMatrix transform)
		{
			((BrushObject)widget.ControlObject).Transform = transform.ToCG ();
		}

{'fraction_non_alphanumeric': 0.11554214270316879, 'fraction_numerical': 0.008622547962923045, 'mean_word_length': 3.1281138790035588, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '931791', 'n_tokens_mistral': 1832, 'n_tokens_neox': 1451, 'n_words': 373}