Ejemplo n.º 1
0
 protected FlagLayer(FlagLayer other)
 {
     this.Image   = (other.Image == null)?null:(Bitmap)other.Image.Clone();
     this.MaxCres = other.MaxCres;
     this.Mirror  = other.Mirror;
     this.Flip    = other.Flip;
     this.Prob    = other.Prob;
 }
Ejemplo n.º 2
0
        public static FlagLayer[] FromString(string line, string imagePath)
        {
            //%crest	,mirror	,flip	,prob	,res_crst	,file
            //,	,	,100	,350	,big_circle_384.png


            string[] tokens = line.Split(",".ToCharArray(), StringSplitOptions.None);
            if (tokens.Length == 7)
            {
                bool      isCrest = tokens[0].Trim() == "1";
                FlagLayer fl      = isCrest ? new CrestLayer() : new FlagLayer();

                fl.Mirror  = tokens[1].Trim() == "1";
                fl.Flip    = tokens[2].Trim() == "1";
                fl.Prob    = int.Parse(tokens[3].Trim());
                fl.MaxCres = 0;
                if (!string.IsNullOrWhiteSpace(tokens[4]))
                {
                    int newCrestSize = int.Parse(tokens[4]);
                    fl.MaxCres = (fl.MaxCres == 0) ? newCrestSize :
                                 Math.Min(newCrestSize, fl.MaxCres);
                }
                fl.Priority = int.Parse(tokens[5].Trim());

                string imageFile = Misc.ToSystemPathFormat(Path.Combine(imagePath, tokens[6].Trim()));

                //look for wildcards
                if (imageFile.Any(C => "?*".Contains(C)))
                {
                    //find final dir (becaue the path token may specify a releative directory(
                    string dir     = Path.GetDirectoryName(imageFile);
                    string pattern = Misc.ToSystemPathFormat(Path.GetFileName(imageFile));


                    string[]         files  = Directory.GetFiles(dir, pattern, SearchOption.AllDirectories);
                    List <FlagLayer> layers = new List <FlagLayer>();
                    foreach (string file in files)
                    {
                        FlagLayer fl2 = (FlagLayer)fl.Clone();
                        fl2.loadImage(file);
                        layers.Add(fl2);
                    }

                    return(layers.ToArray());
                }
                else
                {
                    fl.loadImage(imageFile);

                    return(new FlagLayer[] { fl });
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
        public static FlagGenerator FromFile(string configFile)
        {
            FlagGenerator gen = new FlagGenerator();

            gen.ConfigFile = configFile;
            var lines = File.ReadAllLines(configFile);

            foreach (string line in lines.Where(L => !L.Trim().StartsWith("%")))
            {
                FlagLayer[] fl = FlagLayer.FromString(line, gen.FilePath);
                gen.Layers.AddRange(fl);
            }

            return(gen);
        }