Beispiel #1
0
        public TextureResource GetTileTexture(Guid uid)
        {
            if (!Contains(uid))
            {
                return(null);
            }

            if (_tileSource == null)
            {
                return(null);
            }

            Rectangle src = new Rectangle(_locations[uid].X * TileWidth, _locations[uid].Y * TileHeight, TileWidth, TileHeight);

            return(_tileSource.Crop(src));
        }
Beispiel #2
0
        public void ImportMerge(TextureResource image, TileImportOptions options)
        {
            int tilesWide = (image.Width - options.MarginX) / (TileWidth + options.SpaceX);
            int tilesHigh = (image.Height - options.MarginY) / (TileHeight + options.SpaceY);

            Dictionary <string, Tile> existingHashes = new Dictionary <string, Tile>();
            Dictionary <string, Tile> newHashes      = new Dictionary <string, Tile>();

            using (SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider()) {
                foreach (Tile tile in _tiles)
                {
                    TextureResource tileTex = Tiles.GetTileTexture(tile.Uid);
                    string          hash    = Convert.ToBase64String(sha1.ComputeHash(tileTex.RawData));
                    existingHashes[hash] = tile;
                }

                for (int y = 0; y < tilesHigh; y++)
                {
                    for (int x = 0; x < tilesWide; x++)
                    {
                        Rectangle srcLoc = new Rectangle(
                            options.MarginX + x * (TileWidth + options.SpaceX),
                            options.MarginY + y * (TileHeight + options.SpaceY),
                            TileWidth, TileHeight);

                        TextureResource tileTex = image.Crop(srcLoc);
                        string          hash    = Convert.ToBase64String(sha1.ComputeHash(tileTex.RawData));

                        if (options.ImportPolicty == TileImportPolicy.SourceUnique && newHashes.ContainsKey(hash))
                        {
                            continue;
                        }
                        else if (options.ImportPolicty == TileImportPolicy.SetUnique && existingHashes.ContainsKey(hash))
                        {
                            continue;
                        }

                        Tile newTile = _tiles.Add(tileTex);

                        existingHashes[hash] = newTile;
                        newHashes[hash]      = newTile;
                    }
                }
            }
        }
Beispiel #3
0
        public static Bitmap CreateBitmap(this TextureResource self)
        {
            if (self == null)
            {
                return(null);
            }

            TextureResource tex = self.Crop(self.Bounds);

            tex.Apply(c => { return(new TFColor(c.B, c.G, c.R, c.A)); });

            Bitmap bmp = new Bitmap(tex.Width, tex.Height, PixelFormat.Format32bppArgb);

            Rectangle  rect    = new Rectangle(0, 0, tex.Width, tex.Height);
            BitmapData bmpData = bmp.LockBits(rect, ImageLockMode.WriteOnly, bmp.PixelFormat);

            IntPtr ptr = bmpData.Scan0;

            Marshal.Copy(tex.RawData, 0, ptr, tex.RawData.Length);

            bmp.UnlockBits(bmpData);

            return(bmp);
        }
Beispiel #4
0
 public PatternBrush(TextureResource pattern, double opacity)
 {
     Pattern = pattern.Crop(pattern.Bounds);
     Opacity = opacity;
 }
Beispiel #5
0
 public PatternBrush(TextureResource pattern, double opacity)
 {
     Pattern = pattern.Crop(pattern.Bounds);
     Opacity = opacity;
 }