Changeset - 2f97b4ec280b
[Not reviewed]
default
0 1 0
Jason Maltzen - 6 years ago 2018-05-18 00:19:38
jason@hiddenachievement.com
Use value from HSV for determining whether text should be white or black in exported wiki format recipes.
1 file changed with 57 insertions and 8 deletions:
0 comments (0 inline, 0 general)
PlayerProfile.cs
Show inline comments
...
 
@@ -508,7 +508,57 @@ namespace DesertPaintLab
 
        {
 
            ExportWikiFormat(writer, this.ribbonRecipes);
 
        }
 
        
 

	
 
        static public PaintColor RgbToHsv(PaintColor color)
 
        {
 
            float h = 0;
 
            float s = 0;
 
            float r = color.Red / 255.0f;
 
            float g = color.Green / 255.0f;
 
            float b = color.Blue / 255.0f;
 
            float cmax = Math.Max(Math.Max(r, g), b);
 
            float cmin = Math.Min(Math.Min(r, g), b);
 
            float cd = cmax - cmin;
 
            if (cd == 0)
 
            {
 
                h = 0;
 
            }
 
            else if (cmax == r)
 
            {
 
                h = (((g - b) / cd) % 6) / 6f;
 
            }
 
            else if (cmax == g)
 
            {
 
                h = (((b - r) / cd) + 2) / 6f;
 
            }
 
            else
 
            {
 
                h = (((r - g) / cd) + 4) / 6f;
 
            }
 

	
 
            if (cmax == 0)
 
            {
 
                s = 0;
 
            }
 
            else
 
            {
 
                s = cd / cmax;
 
            }
 

	
 
            if (h < 0)
 
            {
 
                h = 1 + h;
 
            }
 

	
 
            if (h >= 1)
 
            {
 
                h = 0;
 
            }
 

	
 

	
 
            return new PaintColor((byte)(h * 255), (byte)(s * 255), (byte)(cmax * 255));
 
        }
 

	
 
        public void ExportWikiFormat(TextWriter writer, SortedDictionary<string, PaintRecipe> recipeDict)
 
        {
 
            PaintRecipe recipe;
...
 
@@ -522,17 +572,16 @@ namespace DesertPaintLab
 
                    writer.WriteLine("|-");
 
                    string colorLine = "| ";
 
                    colorLine += "style=\"font-weight: bold; background-color: #" + color.Red.ToString("X2") + color.Green.ToString("X2") + color.Blue.ToString("X2") + ";";
 
                    float rPortion = color.Red / 255.0f;
 
                    float gPortion = color.Green / 255.0f;
 
                    float bPortion = color.Blue / 255.0f;
 
                    float maxColor = Math.Max(rPortion, Math.Max(gPortion, bPortion));
 
                    float minColor = Math.Min(rPortion, Math.Min(gPortion, bPortion));
 
                    float luminance = (maxColor - minColor) * 0.5f;
 
                    if (luminance < 0.5f)
 
                    PaintColor hsvColor = RgbToHsv(color);
 
                    if (hsvColor.Blue < 200) // value
 
                    {
 
                        // dark color gets light text
 
                        colorLine += " color: #FFFFFF;";
 
                    }
 
                    else
 
                    {
 
                        colorLine += "color: #000000;";
 
                    }
 
                    colorLine += "\" | " + color.Name + " || ";
 
                    if (recipeDict.TryGetValue(color.Name, out recipe))
 
                    {
0 comments (0 inline, 0 general)