1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Windows.Media;
|
---|
6 |
|
---|
7 | namespace Microsoft.Research.DynamicDataDisplay
|
---|
8 | {
|
---|
9 | public static class BrushHelper
|
---|
10 | {
|
---|
11 | /// <summary>
|
---|
12 | /// Creates a SolidColorBrush with random hue of its color.
|
---|
13 | /// </summary>
|
---|
14 | /// <returns>A SolicColorBrush with random hue of its color.</returns>
|
---|
15 | public static SolidColorBrush CreateBrushWithRandomHue()
|
---|
16 | {
|
---|
17 | return new SolidColorBrush { Color = ColorHelper.CreateColorWithRandomHue() };
|
---|
18 | }
|
---|
19 |
|
---|
20 | /// <summary>
|
---|
21 | /// Makes SolidColorBrush transparent.
|
---|
22 | /// </summary>
|
---|
23 | /// <param name="brush">The brush.</param>
|
---|
24 | /// <param name="alpha">The alpha, [0..255]</param>
|
---|
25 | /// <returns></returns>
|
---|
26 | public static SolidColorBrush MakeTransparent(this SolidColorBrush brush, int alpha)
|
---|
27 | {
|
---|
28 | Color color = brush.Color;
|
---|
29 | color.A = (byte)alpha;
|
---|
30 |
|
---|
31 | return new SolidColorBrush(color);
|
---|
32 | }
|
---|
33 |
|
---|
34 | /// <summary>
|
---|
35 | /// Makes SolidColorBrush transparent.
|
---|
36 | /// </summary>
|
---|
37 | /// <param name="brush">The brush.</param>
|
---|
38 | /// <param name="alpha">The alpha, [0.0 .. 1.0].</param>
|
---|
39 | /// <returns></returns>
|
---|
40 | public static SolidColorBrush MakeTransparent(this SolidColorBrush brush, double opacity)
|
---|
41 | {
|
---|
42 | return MakeTransparent(brush, (int)(opacity * 255));
|
---|
43 | }
|
---|
44 |
|
---|
45 | public static SolidColorBrush ChangeLightness(this SolidColorBrush brush, double lightnessFactor)
|
---|
46 | {
|
---|
47 | Color color = brush.Color;
|
---|
48 | HsbColor hsbColor = HsbColor.FromArgbColor(color);
|
---|
49 | hsbColor.Brightness *= lightnessFactor;
|
---|
50 |
|
---|
51 | if (hsbColor.Brightness > 1.0) hsbColor.Brightness = 1.0;
|
---|
52 |
|
---|
53 | SolidColorBrush result = new SolidColorBrush(hsbColor.ToArgbColor());
|
---|
54 | return result;
|
---|
55 | }
|
---|
56 |
|
---|
57 | public static SolidColorBrush ChangeSaturation(this SolidColorBrush brush, double saturationFactor)
|
---|
58 | {
|
---|
59 | Color color = brush.Color;
|
---|
60 | HsbColor hsbColor = HsbColor.FromArgbColor(color);
|
---|
61 | hsbColor.Saturation *= saturationFactor;
|
---|
62 |
|
---|
63 | if (hsbColor.Saturation > 1.0) hsbColor.Saturation = 1.0;
|
---|
64 |
|
---|
65 | SolidColorBrush result = new SolidColorBrush(hsbColor.ToArgbColor());
|
---|
66 | return result;
|
---|
67 | }
|
---|
68 | }
|
---|
69 | }
|
---|