void pictureBox_Paint(object sender, PaintEventArgs e) { var galaxy = GalaxyMap.Instance.Galaxy; if (galaxy != null) { e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; var mapSize = Image.Size.Scale(ZoomFactor); if (selectedPlanetDrawing != null) { e.Graphics.DrawEllipse( selectionPen, (int)(selectedPlanetDrawing.Position.X * mapSize.Width - SelectionCircleSize / 2), (int)(selectedPlanetDrawing.Position.Y * mapSize.Height - SelectionCircleSize / 2), SelectionCircleSize, SelectionCircleSize); } var linkImageMaker = new LinkImageGenerator(mapSize, galaxy, "links/"); Directory.GetFiles(linkImageMaker.ImagePath).ForEach(File.Delete); foreach (var link in galaxy.Links) { var points = link.PlanetIDs.Select(id => galaxy.GetPlanet(id).Position.Scale(mapSize).ToPoint()).ToArray(); using (var p = new Pen(Color.Green, 2)) { e.Graphics.DrawLine(p, points[0], points[1]); } } GalaxyMap.Instance.PlanetDrawings.ForEach(p => p.Draw(e.Graphics, mapSize)); GalaxyMap.Instance.PlanetDrawings.ForEach(p => p.Label.Draw(e.Graphics, mapSize)); } }
private void exportLinksButton_Click(object sender, EventArgs e) { var imagePath = "..\\WebSite\\galaxy\\galaxy.jpg"; var mapSize = Image.FromFile(imagePath).Size; var dumpPath = "..\\WebSite\\links"; var path = Path.GetFullPath(dumpPath); Directory.CreateDirectory(dumpPath); Directory.GetFiles(path).ForEach(File.Delete); var linkImageGenerator = new LinkImageGenerator(mapSize, GalaxyMap.Instance.Galaxy, path); linkImageGenerator.GenerateImages(); }
public void GetImageBounds1() { Galaxy gal = new Galaxy(); Planet a = new Planet(0, 0.1f, 0.1f); Planet b = new Planet(1, 0.2f, 0.2f); gal.Planets = new List <Planet> { a, b }; var size = new Size(100, 100); var l = new LinkImageGenerator(size, gal, Directory.GetCurrentDirectory()) { Padding = 2 }; var bounds = l.GetImageBounds(new Link(0, 1)); var side = (int)Math.Round(0.2f * 100 - 0.1f * 100 + 2 * 2); var point = (int)Math.Round(0.1f * 100 - 2); Assert.AreEqual(new Rectangle(point, point, side, side), bounds); }
void pictureBox_Paint(object sender, PaintEventArgs e) { var galaxy = GalaxyMap.Instance.Galaxy; if (galaxy != null) { e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; var mapSize = Image.Size.Scale(ZoomFactor); if (selectedPlanetDrawing != null) { e.Graphics.DrawEllipse( selectionPen, (int)(selectedPlanetDrawing.Position.X*mapSize.Width - SelectionCircleSize/2), (int)(selectedPlanetDrawing.Position.Y*mapSize.Height - SelectionCircleSize/2), SelectionCircleSize, SelectionCircleSize); } var linkImageMaker = new LinkImageGenerator(mapSize, galaxy, "links/"); Directory.GetFiles(linkImageMaker.ImagePath).ForEach(File.Delete); foreach (var link in galaxy.Links) { var points = link.PlanetIDs.Select(id => galaxy.GetPlanet(id).Position.Scale(mapSize).ToPoint()).ToArray(); using (var p = new Pen(Color.Green, 2)) { e.Graphics.DrawLine(p, points[0], points[1]); } } GalaxyMap.Instance.PlanetDrawings.ForEach(p => p.Draw(e.Graphics, mapSize)); GalaxyMap.Instance.PlanetDrawings.ForEach(p => p.Label.Draw(e.Graphics, mapSize)); } }