16 changed files with 288 additions and 98 deletions
@ -0,0 +1,94 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Windows; |
||||||
|
using System.Windows.Media; |
||||||
|
namespace ICSharpCode.Reporting.BaseClasses |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Description of ExtensionMethodes.
|
||||||
|
/// Copy from D:\git_Sharpdevelop_Reporting\src\AddIns\Misc\Reports\ICSharpCode.Reports.Core\Project\WPF\ExtensionMethodes.cs
|
||||||
|
/// </summary>
|
||||||
|
/// <see cref="D:\git_Sharpdevelop_Reporting\src\AddIns\Misc\Reports\ICSharpCode.Reports.Core\Project\WPF\ExtensionMethodes.cs"
|
||||||
|
|
||||||
|
internal static class ExtensionMethodes |
||||||
|
{ |
||||||
|
#region Collections
|
||||||
|
|
||||||
|
public static void ForEach<T>(this IEnumerable<T> input, Action<T> action) |
||||||
|
{ |
||||||
|
if (input == null) |
||||||
|
throw new ArgumentNullException("input"); |
||||||
|
foreach (T element in input) { |
||||||
|
action(element); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region system.drawing -> Wpf
|
||||||
|
|
||||||
|
public static Point ToWpf(this System.Drawing.Point p) |
||||||
|
{ |
||||||
|
return new Point(p.X, p.Y); |
||||||
|
} |
||||||
|
|
||||||
|
public static Size ToWpf(this System.Drawing.Size s) |
||||||
|
{ |
||||||
|
return new Size(s.Width, s.Height); |
||||||
|
} |
||||||
|
|
||||||
|
public static Rect ToWpf(this System.Drawing.Rectangle rect) |
||||||
|
{ |
||||||
|
return new Rect(rect.Location.ToWpf(), rect.Size.ToWpf()); |
||||||
|
} |
||||||
|
|
||||||
|
public static System.Windows.Media.Color ToWpf(this System.Drawing.Color c) |
||||||
|
{ |
||||||
|
return System.Windows.Media.Color.FromArgb(c.A, c.R, c.G, c.B); |
||||||
|
} |
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region DPI independence
|
||||||
|
public static Rect TransformToDevice(this Rect rect, Visual visual) |
||||||
|
{ |
||||||
|
Matrix matrix = PresentationSource.FromVisual(visual).CompositionTarget.TransformToDevice; |
||||||
|
return Rect.Transform(rect, matrix); |
||||||
|
} |
||||||
|
|
||||||
|
public static Rect TransformFromDevice(this Rect rect, Visual visual) |
||||||
|
{ |
||||||
|
Matrix matrix = PresentationSource.FromVisual(visual).CompositionTarget.TransformFromDevice; |
||||||
|
return Rect.Transform(rect, matrix); |
||||||
|
} |
||||||
|
|
||||||
|
public static Size TransformToDevice(this Size size, Visual visual) |
||||||
|
{ |
||||||
|
Matrix matrix = PresentationSource.FromVisual(visual).CompositionTarget.TransformToDevice; |
||||||
|
return new Size(size.Width * matrix.M11, size.Height * matrix.M22); |
||||||
|
} |
||||||
|
|
||||||
|
public static Size TransformFromDevice(this Size size, Visual visual) |
||||||
|
{ |
||||||
|
Matrix matrix = PresentationSource.FromVisual(visual).CompositionTarget.TransformFromDevice; |
||||||
|
return new Size(size.Width * matrix.M11, size.Height * matrix.M22); |
||||||
|
} |
||||||
|
|
||||||
|
public static Point TransformToDevice(this Point point, Visual visual) |
||||||
|
{ |
||||||
|
Matrix matrix = PresentationSource.FromVisual(visual).CompositionTarget.TransformToDevice; |
||||||
|
return new Point(point.X * matrix.M11, point.Y * matrix.M22); |
||||||
|
} |
||||||
|
|
||||||
|
public static Point TransformFromDevice(this Point point, Visual visual) |
||||||
|
{ |
||||||
|
Matrix matrix = PresentationSource.FromVisual(visual).CompositionTarget.TransformFromDevice; |
||||||
|
return new Point(point.X * matrix.M11, point.Y * matrix.M22); |
||||||
|
} |
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue