private void Load(List <TerrainPatch> patches) { if (patches.Count < 1) { return; } var patchSize = TerrainPatch.DefaultSize; var ids = patches.Select(p => p.Id).ToList(); var minline = ids.Min(p => p.Y); var maxline = ids.Max(p => p.Y); var minsample = ids.Min(p => p.X); var maxsample = ids.Max(p => p.X); PatchBounds = new Rectangle(minsample, minline, maxsample - minsample + 1, maxline - minline + 1); _patchArray = new TerrainPatch[PatchBounds.Height, PatchBounds.Width]; for (var line = 0; line < PatchBounds.Height; line++) { for (var sample = 0; sample < PatchBounds.Width; sample++) { _patchArray[line, sample] = new TerrainPatch { Line = (line + PatchBounds.Top) * patchSize, Sample = (sample + PatchBounds.Left) * patchSize, Height = patchSize, Width = patchSize, Step = 1 } } } ; pnlTiles.Size = new Size(PatchBounds.Width * patchSize, PatchBounds.Height * patchSize); _transform = new DisplayTransform { OffsetX = -PatchBounds.Left * patchSize, OffsetY = -PatchBounds.Top * patchSize, Scale = 1f }; pnlScroll.Invalidate(); pnlTiles.Invalidate(); }
private void DrawSelectionRectangle(Graphics g, DisplayTransform t, RectangleF r) { var loc = t[r.Location]; var siz = t[r.Size]; g.DrawRectangle(_selectionPen, loc.X, loc.Y, siz.Width, siz.Height); }
/// <summary> /// Duplicates the calculation above to help the idle mouse mode calculate map positions /// </summary> /// <param name="t"></param> /// <returns></returns> public static void DrawCellSize(DisplayTransform t, out float cellSize, out int stride, out int level) { level = (int)(Math.Log(t.Scale) / Log2); // Log2(Scale); level = Math.Min(TileTreeNode.TopLevel, Math.Max(0, level)); // Clip level stride = TileTreeNode.PowersOf2[level]; cellSize = (int)(TileTreeNode.Width * stride / t.Scale); // range = (475, 950], width==height }
private void DrawColoredPatch(Graphics g, DisplayTransform t, Tuple <Point, Brush> tuple) { var sample = tuple.Item1.X * TerrainPatch.DefaultSize; var line = tuple.Item1.Y * TerrainPatch.DefaultSize; var p1 = t[new PointF(sample - 0.5f, line - 0.5f)]; var p2 = t[new PointF(sample + TerrainPatch.DefaultSize + 1f, line + TerrainPatch.DefaultSize + 1f)]; g.FillRectangle(tuple.Item2, p1.X, p1.Y, p2.X - p1.X, p2.Y - p1.Y); }
private void DrawRulerMeasure(Graphics g, DisplayTransform t, RectangleF r) { var m1 = r.Location; var m2 = new PointF(m1.X + r.Width, m1.Y + r.Height); var p1 = t[m1]; var p2 = t[m2]; g.DrawLine(_selectionPen, p1.X, p1.Y, p2.X, p2.Y); var d = MetersPerPixel * m1.Distance(m2); string str = d > 1000f ? $"{(d/1000f).ToString("F2")} km" : $"{d.ToString("F0")} m"; g.DrawString(str, RulerMeasureFont, _selectionBrush, p2.X + 4f, p2.Y + 4f, StringFormat.GenericDefault); }
public MapView() { DoubleBuffered = true; SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); UpdateStyles(); Transform = new DisplayTransform { OffsetX = 0, OffsetY = 0, Scale = 32f }; MouseModeStack = new Stack <MouseMode>(new[] { GetIdleMode() }); InitializeContextMenu(); }
private void DrawTraverseSummary(Graphics g, DisplayTransform t, TraversePlanner.planning.LatLonTraverseSummary traverseSummary) { var lst = traverseSummary.LineSampleList; var last = new PointF(0f, 0f); for (var i = 0; i < lst.Count; i++) { var p = t[lst[i]]; if (i > 0) { g.DrawLine(Pens.IndianRed, last, p); } last = p; } }
public TileTester(List <TerrainPatch> patches = null) { InitializeComponent(); pnlTiles = new PickablePanel { Location = new Point(0, 0), Dock = DockStyle.Fill }; pnlTiles.Paint += pnlTiles_Paint; pnlScroll.Controls.Add(pnlTiles); _transform = new DisplayTransform { OffsetX = 0, OffsetY = 0, Scale = 1f }; Patches = patches; if (Patches != null) { Load(Patches); } cbWhichHorizon.SelectedIndex = 0; }
public void Draw(Graphics g, DisplayTransform t) { var graphicsRect = g.ClipBounds; var topLeft = t.MouseToMap(new Point(0, 0)); var bottomRight = t.MouseToMap(new Point((int)graphicsRect.Width, (int)graphicsRect.Height)); var clipRect = new RectangleF(topLeft.X, topLeft.Y, bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y); InMemoryTerrainManager.GetLineSample((float)(Math.PI / 2), 0f, out int line, out int sample); var p = t[new PointF(sample, line)]; g.FillEllipse(Brushes.Red, p.X - 1, p.Y - 1, 3, 3); foreach (var f in InMemoryTerrainManager.Singleton.IsNorth ? NorthFeatures : SouthFeatures) { if (clipRect.Contains(f.Location)) { var pt = t.MapToMouse(f.Location); g.DrawString(f.Name, FeatureFont, FeatureBrush, pt); } } }
public void Draw(Graphics g, DisplayTransform t, ImageAttributes attributes = null) { var r = g.ClipBounds; //Console.WriteLine($"-- clipbounds={r}"); // Scale indicates the number of map pixels per screen pixel. // OffsetX and OffsetY indicate the offset of the window origin relative to the upper left // corner of the tile array at the current level. var level = (int)(Math.Log(t.Scale) / Log2); // Log2(Scale); level = Math.Min(TileTreeNode.TopLevel, Math.Max(0, level)); // Clip level var stride = TileTreeNode.PowersOf2[level]; var drawScale = t.Scale / stride; // range = [1,2) var cellSize = (int)(TileTreeNode.Width / drawScale); // range = (475, 950], width==height var cellMax = TileTreeNode.MapWidth / (TileTreeNode.Width * stride); var x1 = Math.Max(0, -t.OffsetX / cellSize - 1); var y1 = Math.Max(0, -t.OffsetY / cellSize - 1); var x2 = cellMax - 1; var y2 = cellMax - 1; for (var y = y1; y <= y2; y++) { var pixelY = t.OffsetY + y * cellSize; if (pixelY > r.Bottom) { //Console.WriteLine($" break pixelY {pixelY} > r.Bottom {r.Bottom}"); break; } for (var x = x1; x <= x2; x++) { var pixelX = t.OffsetX + x * cellSize; if (pixelX > r.Right) { //Console.WriteLine($" break pixelX {pixelX} > r.Right {r.Right}"); break; } //Console.WriteLine($" drawing x={pixelX} y={pixelY} x={x} y={y} width={r.Width} height={r.Height}"); var address = TileTreeNode.CalculateAddress(level, x, y); var cell = Fetch(address); var bitmap = Filler != null?cell.GenerateBitmap(Filler) : null; if (bitmap != null) { var r1 = new Rectangle(pixelX, pixelY, cellSize, cellSize); if (attributes == null) { g.DrawImage(bitmap, r1); } else { g.DrawImage(bitmap, r1, 0, 0, bitmap.Width, bitmap.Height, GraphicsUnit.Pixel, attributes); } } else { if (attributes == null) { g.FillRectangle(Brushes.DarkGray, pixelX, pixelY, cellSize, cellSize); } } } } }