private void ChangeImage(string file) { if (file == "") { currentimage = ""; pixbuf = null; return; } try { pixbuf = new Pixbuf(tilesetdir + "/" + file); if (pixbuf.Width % TileSet.TILE_WIDTH != 0 || pixbuf.Height % TileSet.TILE_HEIGHT != 0) { Console.WriteLine("Warning: Image Width or Height is not a multiple of 32"); } } catch (Exception e) { ShowException(e); return; } currentimage = new FileInfo(file).Name; TilesX = pixbuf.Width / TileSet.TILE_WIDTH; TilesY = pixbuf.Height / TileSet.TILE_HEIGHT; SelectionArray = new bool[TilesX * TilesY]; Tiles = new Tile[TilesX * TilesY]; // search tileset for tiles with matching image foreach (Tile tile in tileset.Tiles) { if (tile == null) { continue; } if (tile.Images.Count == 0) { continue; } ImageRegion region = (ImageRegion)tile.Images[0]; if (region.ImageFile == currentimage) { int px = region.Region.X / TileSet.TILE_WIDTH; int py = region.Region.Y / TileSet.TILE_HEIGHT; int i = py * TilesX + px; if (i < 0 || i >= Tiles.Length) { Console.WriteLine("Invalid Imageregion at tile " + tile.ID); continue; } if (Tiles[i] != null) { Console.WriteLine("Multiple tiles for region " + px * TileSet.TILE_WIDTH + " , " + py * TileSet.TILE_HEIGHT); continue; } Tiles[i] = tile; } } /* DrawingArea.Allocation * = new Gdk.Rectangle(0, 0, pixbuf.Width, pixbuf.Height);*/ DrawingArea.WidthRequest = pixbuf.Width; DrawingArea.HeightRequest = pixbuf.Height; DrawingArea.QueueResize(); }