/// <summary> /// Sets color and size. /// </summary> /// <remarks> /// Creates a new gradient brush /// if and only if a change in color or size made this necessary. /// </remarks> /// <param name="size"></param> /// <param name="color"></param> public void Update(SizeD size, Color color) { if (!size.Equals(this.size) || !color.Equals(this.color)) { // color or size have changed: update the gradient brush brush = new LinearGradientBrush(new Point(), new PointF((float) (size.Width/3), (float) (size.Height/3)), Color.FromArgb((byte) Math.Max(0, color.A - 50), (byte) Math.Min(255, color.R*1.7), (byte) Math.Min(255, color.G*1.7), (byte) Math.Min(255, color.B*1.7)), Color.FromArgb((byte) Math.Max(0, color.A - 50), (byte) Math.Min(255, color.R*1.4), (byte) Math.Min(255, color.G*1.4), (byte) Math.Min(255, color.B*1.4))) { WrapMode = WrapMode.TileFlipXY }; } this.size = size; this.color = color; }
public void EqualsEpsilon() { Assert.IsTrue(SizeD.Equals(sizeD, new SizeD(1.1, 1.9), 0.2)); Assert.IsTrue(SizeF.Equals(sizeF, new SizeF(1.1f, 1.9f), 0.2f)); }