Gdk.Rectangle GetTileBounds (int tileIndex)
{
int horizTileCount = (int)Math.Ceiling((float)render_bounds.Width
/ (float)settings.TileWidth);
int x = ((tileIndex % horizTileCount) * settings.TileWidth) + render_bounds.X;
int y = ((tileIndex / horizTileCount) * settings.TileHeight) + render_bounds.Y;
int w = Math.Min(settings.TileWidth, render_bounds.Right - x);
int h = Math.Min(settings.TileHeight, render_bounds.Bottom - y);
return new Gdk.Rectangle (x, y, w, h);
}