| ofs | hex dump | ascii |
|---|
| 0000 | 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 01 90 00 00 02 14 08 06 00 00 00 34 76 7a | .PNG........IHDR.............4vz |
| 0020 | 9f 00 00 00 01 73 52 47 42 00 ae ce 1c e9 00 00 00 04 67 41 4d 41 00 00 b1 8f 0b fc 61 05 00 00 | .....sRGB.........gAMA......a... |
| 0040 | 00 09 70 48 59 73 00 00 40 f3 00 00 40 f3 01 72 63 37 d4 00 00 00 58 74 45 58 74 43 6f 70 79 72 | ..pHYs..@...@..rc7....XtEXtCopyr |
| 0060 | 69 67 68 74 00 43 43 30 20 50 75 62 6c 69 63 20 44 6f 6d 61 69 6e 20 44 65 64 69 63 61 74 69 6f | ight.CC0.Public.Domain.Dedicatio |
| 0080 | 6e 20 68 74 74 70 3a 2f 2f 63 72 65 61 74 69 76 65 63 6f 6d 6d 6f 6e 73 2e 6f 72 67 2f 70 75 62 | n.http://creativecommons.org/pub |
| 00a0 | 6c 69 63 64 6f 6d 61 69 6e 2f 7a 65 72 6f 2f 31 2e 30 2f c6 e3 bd f9 00 00 00 19 74 45 58 74 53 | licdomain/zero/1.0/........tEXtS |
| 00c0 | 6f 66 74 77 61 72 65 00 70 61 69 6e 74 2e 6e 65 74 20 34 2e 30 2e 31 37 33 6e 9f 63 00 00 ff 1c | oftware.paint.net.4.0.173n.c.... |
| 00e0 | 49 44 41 54 78 5e ec 9d 07 b8 1d 55 d5 fe ff 7e d2 41 9a 28 20 0a 02 16 54 04 45 6c a8 14 bb a8 | IDATx^.....U...~.A.(....T.El.... |
| 0100 | 9f 15 fd ac a8 a4 dd f4 4a 7a 6e 7a 6f 90 84 54 4a 08 81 00 01 42 02 04 02 09 bd 88 22 8a 82 0a | ........Jznzo..TJ....B......"... |
| 0120 | 16 f0 fb 94 12 12 d2 fb 3d f3 7f d7 5a 7b ed d9 7b 66 cf 9c 39 f7 9e 5b 02 67 9e e7 7d 4e ca bd | ........=...Z{..{f..9..[.g..}N.. |
| 0140 | e7 cc ec b2 7e fb 5d 6b cf 9c ff 57 3b 6a 47 ed a8 1d b5 a3 76 d4 8e da 51 3b 6a 47 ed a8 1d b5 | ....~.]k...W;jG.....v...Q;jG.... |
| 0160 | a3 76 d4 8e da 51 3b 6a 47 ed a8 1d b5 a3 76 d4 8e da 51 3b 6a 47 ed a8 1d b5 a3 76 d4 8e da // 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.Windows;
using System.Windows.Media;
namespace Tango.Scripting.Editors.Utils
{
/// <summary>
/// Contains static helper methods for aligning stuff on a whole number of pixels.
/// </summary>
public static class PixelSnapHelpers
{
/// <summary>
/// Gets the pixel size on the screen containing visual.
/// This method does not take transforms on visual into account.
/// </summary>
public static Size GetPixelSize(Visual visual)
{
if (visual == null)
throw new ArgumentNullException("visual");
PresentationSource source = PresentationSource.FromVisual(visual);
if (source != null) {
Matrix matrix = source.CompositionTarget.TransformFromDevice;
return new Size(matrix.M11, matrix.M22);
} else {
return new Size(1, 1);
}
}
/// <summary>
/// Aligns <paramref name="value"/> on the next middle of a pixel.
/// </summary>
/// <param name="value">The value that should be aligned</param>
/// <param name="pixelSize">The size of one pixel</param>
public static double PixelAlign(double value, double pixelSize)
{
// 0 -> 0.5
// 0.1 -> 0.5
// 0.5 -> 0.5
// 0.9 -> 0.5
// 1 -> 1.5
return pixelSize * (Math.Round((value / pixelSize) + 0.5) - 0.5);
}
/// <summary>
/// Aligns the borders of rect on the middles of pixels.
/// </summary>
public static Rect PixelAlign(Rect rect, Size pixelSize)
{
rect.X = PixelAlign(rect.X, pixelSize.Width);
rect.Y = PixelAlign(rect.Y, pixelSize.Height);
rect.Width = Round(rect.Width, pixelSize.Width);
rect.Height = Round(rect.Height, pixelSize.Height);
return rect;
}
/// <summary>
/// Rounds <paramref name="point"/> to whole number of pixels.
/// </summary>
public static Point Round(Point point, Size pixelSize)
{
return new Point(Round(point.X, pixelSize.Width), Round(point.Y, pixelSize.Height));
}
/// <summary>
/// Rounds val to whole number of pixels.
/// </summary>
public static Rect Round(Rect rect, Size pixelSize)
{
return new Rect(Round(rect.X, pixelSize.Width), Round(rect.Y, pixelSize.Height),
Round(rect.Width, pixelSize.Width), Round(rect.Height, pixelSize.Height));
}
/// <summary>
/// Rounds <paramref name="value"/> to a whole number of pixels.
/// </summary>
public static double Round(double value, double pixelSize)
{
return pixelSize * Math.Round(value / pixelSize);
}
/// <summary>
/// Rounds <paramref name="value"/> to an whole odd number of pixels.
/// </summary>
public static double RoundToOdd(double value, double pixelSize)
{
return Round(value - pixelSize, pixelSize * 2) + pixelSize;
}
}
}
|