Exemplo n.º 1
0
        private void SetControlsFromSettings(CramSettings settings)
        {
            if (settings == null)
                throw new ArgumentNullException("settings");

            // TODO: Show errors if images don't load

            List<string> errored = new List<string>();
            RemoveAllInputImages();
            foreach (string s in settings.SourceImages)
            {
                if (!AddInputImage(s))
                    errored.Add(s);
            }

            if (errored.Count > 0)
            {
                StringBuilder builder = new StringBuilder();
                builder.Append(String.Format("Error loading {0} images:", errored.Count));
                foreach (string s in errored)
                {
                    builder.Append(String.Format("\n{0}", s));
                }
                MessageBox.Show(builder.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            specificCKMode.Checked = (settings.ColorKeyMode == ColorKeyMode.Manual);
            automaticCKMode.Checked = (settings.ColorKeyMode == ColorKeyMode.Automatic);
            disableCKMode.Checked = (settings.ColorKeyMode == ColorKeyMode.Disabled);
            colorKeyColor = settings.ColorKeyColor;

            spritePageSizeCombo.Text = String.Format("{0}x{1}",
                                                        settings.PageSize.Width,
                                                        settings.PageSize.Height);

            backgroundColor = Color.FromArgb(255,
                                            settings.BackgroundColor.R,
                                            settings.BackgroundColor.G,
                                            settings.BackgroundColor.B);
            alphaUpDown.Value = settings.BackgroundColor.A;

            borderSizeUpDown.Value = settings.Border;

            enableFallbackCheck.Checked = settings.AllowFallbacks;
            fallbackPagesUpDown.Value = settings.MaxFallbacks;

            fallbackSizes = settings.FallbackSizes;
            UpdateFallbackList();

            cropCheck.Checked = settings.Crop;
            uniqueCheck.Checked = settings.Unique;
            rotateCheck.Checked = settings.Rotate;

            outputFilenameEdit.Text = settings.XmlFilename;

            shortNameMode.Checked = (settings.PathMode == PathMode.Short);
            fullPathMode.Checked = (settings.PathMode == PathMode.Full);
            relativePathMode.Checked = (settings.PathMode == PathMode.Relative);

            relativePathEdit.Text = settings.RelativePathBase;

            cleanCheck.Checked = settings.Clean;

            RecalculateInputImageStats();
            UpdateUI();
        }
Exemplo n.º 2
0
        public static int Run(string[] stringArgs)
        {
            CramSettings settings = new CramSettings();

            Queue<String> queue = new Queue<String>(stringArgs);
            bool outputSpecified = false;

            while (queue.Count > 0)
            {
                string arg = queue.Dequeue();
                switch (arg)
                {
                    case "-o":
                        {
                            if (queue.Count == 0 || queue.Peek().StartsWith("-"))
                                Bail("Missing parameter for -o");
                            settings.XmlFilename = queue.Dequeue();
                            outputSpecified = true;
                        }
                        break;

                    case "-colorkey":
                        {
                            if (queue.Count == 0 || queue.Peek().StartsWith("-"))
                                Bail("Missing parameter for -colorkey");
                            string param = queue.Dequeue();
                            Color specificColor;
                            if (param == "auto")
                            {
                                settings.ColorKeyMode = ColorKeyMode.Automatic;
                            }
                            else if (param == "none")
                            {
                                settings.ColorKeyMode = ColorKeyMode.Disabled;
                            }
                            else if (Util.ParseColor(param, out specificColor))
                            {
                                settings.ColorKeyMode = ColorKeyMode.Manual;
                                settings.ColorKeyColor = specificColor;
                            }
                            else
                                Bail("Invalid parameter for -colorkey: {0}", param);
                        }
                        break;

                    case "-size":
                        {
                            if (queue.Count == 0 || queue.Peek().StartsWith("-"))
                                Bail("Missing parameter for -size");
                            string param = queue.Dequeue();
                            if (!Util.ParseSize(param, out settings.PageSize))
                                Bail("Invalid parameter for -size: {0}", param);
                        }
                        break;

                    case "-bg":
                        {
                            if (queue.Count == 0 || queue.Peek().StartsWith("-"))
                                Bail("Missing parameter for -bg");
                            string param = queue.Dequeue();
                            if (!Util.ParseColor(param, out settings.BackgroundColor))
                                Bail("Invalid parameter for -bg: {0}", param);
                        }
                        break;

                    case "-border":
                        {
                            if (queue.Count == 0 || queue.Peek().StartsWith("-"))
                                Bail("Missing parameter for -border");
                            string param = queue.Dequeue();
                            int size;
                            if (!Int32.TryParse(param, out size) || size < 0)
                                Bail("Invalid parameter for -border: {0}", param);
                            settings.Border = size;
                        }
                        break;

                    case "-fallbacks":
                        {
                            if (queue.Count == 0 || queue.Peek().StartsWith("-"))
                                Bail("Missing parameter for -fallbacks");
                            string param = queue.Dequeue();
                            int size;
                            if (!Int32.TryParse(param, out size) || size < 0)
                                Bail("Invalid parameter for -fallbacks: {0}", param);
                            if (size == 0)
                            {
                                settings.AllowFallbacks = false;
                                settings.MaxFallbacks = 0;
                            }
                            else
                            {
                                settings.AllowFallbacks = true;
                                settings.MaxFallbacks = size;
                            }
                        }
                        break;

                    case "-fbsizes":
                        {
                            if (queue.Count == 0 || queue.Peek().StartsWith("-"))
                                Bail("Missing parameter for -fbsizes");
                            string param = queue.Dequeue();
                            if (!Util.ParseSizeList(param, out settings.FallbackSizes) || settings.FallbackSizes.Count < 0)
                                Bail("Invalid parameter for -fbsizes: {0}", param);
                        }
                        break;

                    case "-crop":
                        settings.Crop = true;
                        break;

                    case "-rotate":
                        settings.Rotate = true;
                        break;

                    case "-unique":
                        settings.Unique = true;
                        break;

                    case "-?":
                    case "-help":
                    case "-h":
                    case "--help":
                        ShowUsage();
                        System.Environment.Exit(0);
                        break;

                    case "-v":
                    case "-version":
                        Console.WriteLine("Sprite Crammer {0}", VersionInfo.Version);
                        Console.WriteLine("Copyright (C) 2008 Scott Hilbert");
                        Console.WriteLine("http://www.shilbert.com/");
                        System.Environment.Exit(0);
                        break;

                    case "-ipath":
                        {
                            if (queue.Count == 0 || queue.Peek().StartsWith("-"))
                                Bail("Missing parameter for -ipath");
                            string param = queue.Dequeue();
                            string paramLower = param.ToLower();
                            if (paramLower == "short")
                                settings.PathMode = PathMode.Short;
                            else if (paramLower == "full")
                                settings.PathMode = PathMode.Full;
                            else if (paramLower.StartsWith("rel:") && param.Length > 4)
                            {
                                settings.PathMode = PathMode.Relative;
                                settings.RelativePathBase = param.Substring(4);
                            }
                            else
                                Bail("Invalid parameter for -ipath: {0}", param);
                        }
                        break;

                    case "-config":
                        {
                            if (queue.Count == 0 || queue.Peek().StartsWith("-"))
                                Bail("Missing parameter for -config");
                            string param = queue.Dequeue();
                            settings = CramSettings.Load(param);
                            outputSpecified = true;
                            if (settings == null)
                                Bail("Cannot load config file: {0}", param);
                        }
                        break;

                    case "-clean":
                        settings.Clean = true;
                        break;

                    default:
                        if (arg.StartsWith("-"))
                        {
                            Console.WriteLine("Unknown option: {0}", arg);
                            System.Environment.Exit(0);
                        }
                        else
                            settings.SourceImages.Add(arg);
                        break;
                }
            }

            settings.FallbackSizes.Sort(Util.CompareFallbackSizes);

            if (!outputSpecified)
            {
                BailWithUsage("No output file specified. Use -o to specify output file path.");
            }

            SpriteCrammer crammer = new SpriteCrammer();
            crammer.Settings = settings;
            crammer.LogEvent += new ProgressLog(crammer_LogEvent);

            bool result = crammer.Run();

            return result ? 0 : 1;
        }
Exemplo n.º 3
0
        private bool GetSettingsFromControls(out CramSettings settings)
        {
            settings = new CramSettings();

            foreach (ListViewItem item in inputImageList.Items)
            {
                InputImageTag tag = (InputImageTag)item.Tag;
                settings.SourceImages.Add(tag.Filename);
            }

            if (specificCKMode.Checked)
            {
                settings.ColorKeyMode = ColorKeyMode.Manual;
                settings.ColorKeyColor = colorKeyColor;
            }
            else if (automaticCKMode.Checked)
            {
                settings.ColorKeyMode = ColorKeyMode.Automatic;
                settings.ColorKeyColor = colorKeyColor;
            }
            else
            {
                settings.ColorKeyMode = ColorKeyMode.Disabled;
                settings.ColorKeyColor = colorKeyColor;
            }

            if (!Util.ParseSize(spritePageSizeCombo.Text, out settings.PageSize))
            {
                MessageBox.Show(String.Format("Invalid sprite page size: \"{0}\"", spritePageSizeCombo.Text));
                return false;
            }

            settings.BackgroundColor =
                Color.FromArgb((int)alphaUpDown.Value, backgroundColor.R, backgroundColor.G, backgroundColor.B);

            settings.Border = (int)borderSizeUpDown.Value;

            settings.AllowFallbacks = enableFallbackCheck.Checked;
            settings.MaxFallbacks = (int)fallbackPagesUpDown.Value;
            settings.FallbackSizes = fallbackSizes;

            settings.Crop = cropCheck.Checked;
            settings.Unique = uniqueCheck.Checked;
            settings.Rotate = rotateCheck.Checked;

            settings.XmlFilename = outputFilenameEdit.Text;

            if (shortNameMode.Checked)
            {
                settings.PathMode = PathMode.Short;
                settings.RelativePathBase = "";
            }
            else if (fullPathMode.Checked)
            {
                settings.PathMode = PathMode.Full;
                settings.RelativePathBase = "";
            }
            else //if (relativePathMode.Checked)
            {
                settings.PathMode = PathMode.Relative;
                settings.RelativePathBase = relativePathEdit.Text;
            }

            settings.Clean = cleanCheck.Checked;

            return true;
        }