예제 #1
0
        public XDocument Update(string baseColourHex)
        {
            baseColourHex = baseColourHex.Trim('#');
            if (baseColourHex.Length == 8)
                baseColourHex = baseColourHex.Substring(2);

            var output = new XDocument(_document);

            var baseColour = new HSLColor(baseColourHex);
            var dictionary = output.Element(XamlPresentationNamespace + "ResourceDictionary");

            var themeResources = (XElement)dictionary.FirstNode;
            foreach (var x in themeResources.Elements())
            {
                var brushKey = x.Attribute(XamlRootNamespace + "Key");
                if (brushKey == null)
                    continue;

                var key = brushKey.Value;
                if (key == "HighContrast")
                    continue;

                foreach (var brush in Brushes[key])
                {
                    var y = x.Elements().FirstOrDefault(i => i.Attribute(XamlRootNamespace + "Key").Value == brush.Key);
                    if (y == null)
                        continue;

                    var attribute = y.Attribute("Color");
                    if (attribute == null)
                        continue;

                    var newColour = new HSLColor(baseColour.Hue, baseColour.Saturation, baseColour.Luminosity + brush.Value);
                    attribute.SetValue(attribute.Value.Substring(0, 3) + newColour.ToHex());
                }
            }

            return output;
        }
예제 #2
0
파일: Program.cs 프로젝트: shiftkey/HAMMER
        static void Main(string[] args)
        {
            HSLColor baseColour;
            PantsArgs appArgs;

            string inputFile;
            var resolvedInputFilePath = ProgramFilesx86() + DefaultInputFile;

            // verify the input arguments
            var output = "Generic.xaml";
            try
            {
                appArgs = args.As<PantsArgs>();
                inputFile = string.IsNullOrEmpty(appArgs.InputFile)
                                        ? resolvedInputFilePath
                                        : appArgs.InputFile;

                if (!string.IsNullOrEmpty(appArgs.OutputFile))
                    output = appArgs.OutputFile;

                baseColour = new HSLColor(appArgs.Colour);
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine();
                Console.WriteLine(AppArgs.HelpFor<PantsArgs>());
                WaitForInput();

                return;
            }

            // check that the input file exists
            if (!File.Exists(inputFile))
            {
                Console.WriteLine("Default generic.xaml file '{0}' could not be found.", inputFile);
                Console.WriteLine("You must specify a value for the /inputfile parameter to continue.");
                Console.WriteLine("You can grab a version from https://raw.github.com/Code52/HAMMER/master/SampleData/generic.xaml and add it to this folder...");
                WaitForInput();

                return;
            }

            var doc = XDocument.Load(inputFile);
            var dictionary = doc.Element(XamlPresentationNamespace + "ResourceDictionary");

            if (dictionary == null)
            {
                Console.WriteLine("Error: Input file '{0}' does not contain a resource dictionary", inputFile);
                WaitForInput();

                return;
            }

            var themeResources = (XElement)dictionary.FirstNode;
            foreach (var x in themeResources.Elements())
            {
                var brushKey = x.Attribute(XamlRootNamespace + "Key");
                if (brushKey == null)
                    continue;

                var key = brushKey.Value;
                if (key == "HighContrast")
                    continue;

                /* Generate dictionary code */
                if (appArgs.Generate)
                    Console.WriteLine("{{\"{0}\", new Dictionary<string, double>{{", key);

                foreach (var brush in Brushes[key])
                {
                    var y = x.Elements().FirstOrDefault(i => i.Attribute(XamlRootNamespace + "Key").Value == brush.Key);
                    if (y == null)
                        continue;

                    var attribute = y.Attribute("Color");
                    if (attribute == null)
                        continue;

                    /* Generate dictionary code */
                    if (appArgs.Generate)
                    {
                        var c = new HSLColor(attribute.Value.Substring(3));
                        Console.WriteLine("{{\"{0}\", {1}}},", brush, c.Luminosity - BaseLuminosity);
                    }

                    var newColour = new HSLColor(baseColour.Hue, baseColour.Saturation, baseColour.Luminosity + brush.Value);
                    attribute.SetValue(newColour.ToHex());
                }

                /* Generate dictionary code */
                if (appArgs.Generate)
                    Console.WriteLine("}}");
            }

            doc.Save(output);

            Console.WriteLine("Completed");
            Console.WriteLine("Output file is at '{0}'", Path.GetFullPath(output));
            Console.WriteLine("Press any key to finish");
            WaitForInput();
        }
예제 #3
0
파일: HSLColor.cs 프로젝트: Code52/HAMMER
 private static double GetTemp2(HSLColor hslColor)
 {
     double temp2;
     if (hslColor._luminosity < 0.5)  //<=??
         temp2 = hslColor._luminosity * (1.0 + hslColor._saturation);
     else
         temp2 = hslColor._luminosity + hslColor._saturation - (hslColor._luminosity * hslColor._saturation);
     return temp2;
 }