Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Shared Files/Resources/reportparts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
<ReportPart Name="CoverageTableActiveSortColour" SelectedThemeColourName="EnvironmentColors.SystemHighlightColorKey" />
<ReportPart Name="CoverageTableInactiveSortColour" SelectedThemeColourName="EnvironmentColors.ToolWindowTextColorKey" />
<ReportPart Name="CoverageTableExpandCollapseIconColour" SelectedThemeColourName="EnvironmentColors.ToolWindowTextColorKey" />
<ReportPart Name="CoverageTableRowHoverBackgroundColour" SelectedThemeColourName="EnvironmentColors.ToolWindowBackgroundColorKey" />
<ReportPart Name="CoverageTableRowHoverBackgroundColour" SelectedThemeColourName="EnvironmentColors.ToolWindowTextColorKey" />
<ReportPart Name="CoverageTableRowHoverColour" SelectedThemeColourName="EnvironmentColors.ToolWindowBackgroundColorKey" />
<ReportPart Name="TabBackgroundColour" SelectedThemeColourName="EnvironmentColors.FileTabBackgroundColorKey" />
<ReportPart Name="DivHeaderBackgroundColour" SelectedThemeColourName="EnvironmentColors.ToolWindowBackgroundColorKey" />
<ReportPart Name="HeaderFontColour" SelectedThemeColourName="EnvironmentColors.FileTabTextColorKey" />
Expand Down
337 changes: 337 additions & 0 deletions SharedProject/Core/ReportGenerator/ColourUtilities/LighnessApplier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,337 @@
using System;

namespace FineCodeCoverage.Engine.ReportGenerator
{
/*
Conversions from https://www.codeproject.com/Articles/19045/Manipulating-colors-in-NET-Part-1#hsb
This is potentially better https://github.com/tompazourek/Colourful/

*/
public struct RGB
{
/// <summary>
/// Gets an empty RGB structure;
/// </summary>
public static readonly RGB Empty = new RGB();

private int red;
private int green;
private int blue;

public static bool operator ==(RGB item1, RGB item2)
{
return (
item1.Red == item2.Red
&& item1.Green == item2.Green
&& item1.Blue == item2.Blue
);
}

public static bool operator !=(RGB item1, RGB item2)
{
return (
item1.Red != item2.Red
|| item1.Green != item2.Green
|| item1.Blue != item2.Blue
);
}

/// <summary>
/// Gets or sets red value.
/// </summary>
public int Red
{
get
{
return red;
}
set
{
red = (value > 255) ? 255 : ((value < 0) ? 0 : value);
}
}

/// <summary>
/// Gets or sets red value.
/// </summary>
public int Green
{
get
{
return green;
}
set
{
green = (value > 255) ? 255 : ((value < 0) ? 0 : value);
}
}

/// <summary>
/// Gets or sets red value.
/// </summary>
public int Blue
{
get
{
return blue;
}
set
{
blue = (value > 255) ? 255 : ((value < 0) ? 0 : value);
}
}

public RGB(int R, int G, int B)
{
this.red = (R > 255) ? 255 : ((R < 0) ? 0 : R);
this.green = (G > 255) ? 255 : ((G < 0) ? 0 : G);
this.blue = (B > 255) ? 255 : ((B < 0) ? 0 : B);
}

public override bool Equals(Object obj)
{
if (obj == null || GetType() != obj.GetType()) return false;

return (this == (RGB)obj);
}

public override int GetHashCode()
{
return Red.GetHashCode() ^ Green.GetHashCode() ^ Blue.GetHashCode();
}
}
public static class ColorConversion
{
/// <summary>
/// Converts HSL to RGB.
/// </summary>
/// <param name="h">Hue, must be in [0, 360].</param>
/// <param name="s">Saturation, must be in [0, 1].</param>
/// <param name="l">Luminance, must be in [0, 1].</param>
public static RGB HSLtoRGB(double h, double s, double l)
{
if (s == 0)
{
// achromatic color (gray scale)
return new RGB(
Convert.ToInt32(Double.Parse(String.Format("{0:0.00}",
l * 255.0))),
Convert.ToInt32(Double.Parse(String.Format("{0:0.00}",
l * 255.0))),
Convert.ToInt32(Double.Parse(String.Format("{0:0.00}",
l * 255.0)))
);
}
else
{
double q = (l < 0.5) ? (l * (1.0 + s)) : (l + s - (l * s));
double p = (2.0 * l) - q;

double Hk = h / 360.0;
double[] T = new double[3];
T[0] = Hk + (1.0 / 3.0); // Tr
T[1] = Hk; // Tb
T[2] = Hk - (1.0 / 3.0); // Tg

for (int i = 0; i < 3; i++)
{
if (T[i] < 0) T[i] += 1.0;
if (T[i] > 1) T[i] -= 1.0;

if ((T[i] * 6) < 1)
{
T[i] = p + ((q - p) * 6.0 * T[i]);
}
else if ((T[i] * 2.0) < 1) //(1.0/6.0)<=T[i] && T[i]<0.5
{
T[i] = q;
}
else if ((T[i] * 3.0) < 2) // 0.5<=T[i] && T[i]<(2.0/3.0)
{
T[i] = p + (q - p) * ((2.0 / 3.0) - T[i]) * 6.0;
}
else T[i] = p;
}

return new RGB(
Convert.ToInt32(Double.Parse(String.Format("{0:0.00}",
T[0] * 255.0))),
Convert.ToInt32(Double.Parse(String.Format("{0:0.00}",
T[1] * 255.0))),
Convert.ToInt32(Double.Parse(String.Format("{0:0.00}",
T[2] * 255.0)))
);
}
}

public static HSL RGBtoHSL(int red, int green, int blue)
{
double h = 0, s = 0, l = 0;

// normalize red, green, blue values
double r = (double)red / 255.0;
double g = (double)green / 255.0;
double b = (double)blue / 255.0;

double max = Math.Max(r, Math.Max(g, b));
double min = Math.Min(r, Math.Min(g, b));

// hue
if (max == min)
{
h = 0; // undefined
}
else if (max == r && g >= b)
{
h = 60.0 * (g - b) / (max - min);
}
else if (max == r && g < b)
{
h = 60.0 * (g - b) / (max - min) + 360.0;
}
else if (max == g)
{
h = 60.0 * (b - r) / (max - min) + 120.0;
}
else if (max == b)
{
h = 60.0 * (r - g) / (max - min) + 240.0;
}

// luminance
l = (max + min) / 2.0;

// saturation
if (l == 0 || max == min)
{
s = 0;
}
else if (0 < l && l <= 0.5)
{
s = (max - min) / (max + min);
}
else if (l > 0.5)
{
s = (max - min) / (2 - (max + min)); //(max-min > 0)?
}

return new HSL(
Double.Parse(String.Format("{0:0.##}", h)),
Double.Parse(String.Format("{0:0.##}", s)),
Double.Parse(String.Format("{0:0.##}", l))
);
}
}

public struct HSL
{
/// <summary>
/// Gets an empty HSL structure;
/// </summary>
public static readonly HSL Empty = new HSL();

private double hue;
private double saturation;
private double luminance;

public static bool operator ==(HSL item1, HSL item2)
{
return (
item1.Hue == item2.Hue
&& item1.Saturation == item2.Saturation
&& item1.Luminance == item2.Luminance
);
}

public static bool operator !=(HSL item1, HSL item2)
{
return (
item1.Hue != item2.Hue
|| item1.Saturation != item2.Saturation
|| item1.Luminance != item2.Luminance
);
}

/// <summary>
/// Gets or sets the hue component.
/// </summary>
public double Hue
{
get
{
return hue;
}
set
{
hue = (value > 360) ? 360 : ((value < 0) ? 0 : value);
}
}

/// <summary>
/// Gets or sets saturation component.
/// </summary>
public double Saturation
{
get
{
return saturation;
}
set
{
saturation = (value > 1) ? 1 : ((value < 0) ? 0 : value);
}
}

/// <summary>
/// Gets or sets the luminance component.
/// </summary>
public double Luminance
{
get
{
return luminance;
}
set
{
luminance = (value > 1) ? 1 : ((value < 0) ? 0 : value);
}
}

/// <summary>
/// Creates an instance of a HSL structure.
/// </summary>
/// <param name="h">Hue value.</param>
/// <param name="s">Saturation value.</param>
/// <param name="l">Lightness value.</param>
public HSL(double h, double s, double l)
{
this.hue = (h > 360) ? 360 : ((h < 0) ? 0 : h);
this.saturation = (s > 1) ? 1 : ((s < 0) ? 0 : s);
this.luminance = (l > 1) ? 1 : ((l < 0) ? 0 : l);
}

public override bool Equals(Object obj)
{
if (obj == null || GetType() != obj.GetType()) return false;

return (this == (HSL)obj);
}

public override int GetHashCode()
{
return Hue.GetHashCode() ^ Saturation.GetHashCode() ^
Luminance.GetHashCode();
}
}
public static class LightenssApplier
{
public static System.Drawing.Color Swap(System.Drawing.Color lightnessColor, System.Drawing.Color applyToColor)
{
var hsl = ColorConversion.RGBtoHSL(lightnessColor.R, lightnessColor.G, lightnessColor.B);
var hsl2 = ColorConversion.RGBtoHSL(applyToColor.R, applyToColor.G, applyToColor.B);
hsl2.Luminance = hsl.Luminance;
var rgb = ColorConversion.HSLtoRGB(hsl2.Hue, hsl2.Saturation, hsl2.Luminance);
return System.Drawing.Color.FromArgb(rgb.Red, rgb.Green, rgb.Blue);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;

namespace FineCodeCoverage.Engine.ReportGenerator
{
internal static class LuminanceContrastColourExtensions
{
public static double Contrast(this System.Drawing.Color color, System.Drawing.Color color2)
{
var l1 = color.Luminance();
var l2 = color2.Luminance();
return l1 > l2 ? (l1 + 0.05) / (l2 + 0.05) : (l2 + 0.05) / (l1 + 0.05);

}

public static double Luminance(this System.Drawing.Color color)
{
return Luminance(color.R, color.G, color.B);
}

private static double Luminance(int r, int g, int b)
{
var lr = LuminanceX(r);
var lg = LuminanceX(g);
var lb = LuminanceX(b);
return 0.2126 * lr + 0.7152 * lg + 0.0722 * lb;

}

private static double LuminanceX(int x)
{
x /= 255;
return x <= 0.03928 ? x / 12.92 : Math.Pow((x + 0.055) / 1.055, 2.4);

}
}
}
1 change: 1 addition & 0 deletions SharedProject/Core/ReportGenerator/IReportColours.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ internal interface IReportColours
Color CoverageTableInactiveSortColour { get; }

Color CoverageTableRowHoverBackgroundColour { get; }
Color CoverageTableRowHoverColour { get; }

Color DivHeaderBackgroundColour { get; }

Expand Down
Loading