static void Main(string[] args) { LayoutProperties layoutProp = new LayoutProperties(); if (args.Contains("-images")) { string spritePath = args.ElementAt(Array.IndexOf(args, "-images") + 1); layoutProp.outputSpriteFilePath = spritePath + @"\sprite.png"; string[] filters = { ".png", ".jpg", ".jpeg", ".gif" }; layoutProp.inputFilePaths = (from filter in filters from file in Directory.GetFiles(spritePath) where file.EndsWith(filter) select file).ToArray(); } if (args.Contains("-css")) { layoutProp.cssFilePath = args.ElementAt(Array.IndexOf(args, "-css") + 1); } if (args.Contains("-gui")) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new SpritesForm(layoutProp)); } else { Sprite sprite = new Sprite(layoutProp); sprite.Create(); } }
//Generate button click event. Start generating output image and CSS file. private void buttonGenerate_Click(object sender, EventArgs e) { layoutProp.cssFilePath = textBoxCssFilePath.Text; layoutProp.outputSpriteFilePath = textBoxInputDirectoryPath.Text; Sprite sprite = new Sprite(layoutProp); sprite.Create(); this.Close(); }
private static void GenerateFromConfigFile(string configFile) { try { var config = new SpriteConfigFile(configFile); var layoutProp = config.GenerateLayoutProperties(); var sprite = new Sprite(layoutProp); sprite.Create(); } catch (Exception ex) { var fullError = ex.ToString().Replace("\n", "\n "); Console.WriteLine("ERROR: {0}\n\n {1}", ex.Message, fullError); Environment.ExitCode = 1; } }
/// <summary> /// Generates css/png file if not exist or sprite sources changed /// </summary> private void GenerateIfNotExists() { string fileName; if (FileNameMatches(out fileName)) { var response = HttpContext.Current.Response; string filePath = HttpContext.Current.Server.MapPath("~/" + fileName); string currentHash = SpriteConfig.SpriteSettings.inputFilePaths.GetHashCode().ToString(); string generatedHashPath = _hashPath; string generatedHash = null; if (File.Exists(generatedHashPath)) { generatedHash = File.ReadAllText(generatedHashPath); } //if there is nothing generated yet, or what is generated shouldn't change if (!File.Exists(filePath) || (!string.IsNullOrEmpty(generatedHash) && currentHash != generatedHash)) { var sprite = new Sprite(SpriteConfig.SpriteSettings); sprite.Create(); File.WriteAllText(generatedHashPath, currentHash); } } }
//Generate button click event. Start generating output image and CSS file. private void buttonGenerate_Click(object sender, EventArgs e) { layoutProp.outputSpriteFilePath = textBoxOutputImageFilePath.Text; layoutProp.outputCssFilePath = textBoxOutputCSSFilePath.Text; layoutProp.distanceBetweenImages = (int)numericUpDownDistanceBetweenImages.Value; layoutProp.marginWidth = (int)numericUpDownMarginWidth.Value; Sprite sprite = new Sprite(layoutProp); sprite.Create(); //Sprite sprite = new Sprite(inputFilePaths, textBoxOutputImageFilePath.Text, textBoxOutputCSSFilePath.Text, layout, // (int)numericUpDownDistanceBetweenImages.Value, (int)numericUpDownMarginWidth.Value, imagesInRow, imagesInColumn); this.Close(); }