/// <summary>Paint the top layer of the display, graphics that changes frequently between refreshes.</summary> /// <param name="this">Type: MapDisplay{THex} - The map to be painted.</param> /// <param name="graphics">Graphics object for the canvas being painted.</param> public static void PaintHighlight <THex>(this MapDisplay <THex> @this, Graphics graphics ) where THex : MapGridHex { if (graphics == null) { throw new ArgumentNullException("graphics"); } var container = graphics.BeginContainer(); graphics.Transform = @this.TranslateToHex(@this.StartHex); graphics.DrawPath(Pens.Red, @this.HexgridPath); if (@this.ShowPath) { graphics.EndContainer(container); container = graphics.BeginContainer(); @this.PaintPath(graphics, @this.Path); } if (@this.ShowRangeLine) { graphics.EndContainer(container); container = graphics.BeginContainer(); var target = @this.CentreOfHex(@this.HotspotHex); graphics.DrawLine(Pens.Red, @this.CentreOfHex(@this.StartHex), target); graphics.DrawLine(Pens.Red, target.X - 8, target.Y - 8, target.X + 8, target.Y + 8); graphics.DrawLine(Pens.Red, target.X - 8, target.Y + 8, target.X + 8, target.Y - 8); } graphics.EndContainer(container); }
/// <summary>Paints all the hexes in <paramref name="clipHexes"/> by executing <paramref name="paintAction"/> /// for each hex on <paramref name="graphics"/>.</summary> /// <param name="this">Type: MapDisplay{THex} - The map to be painted.</param> /// <param name="graphics">Graphics object for the canvas being painted.</param> /// <param name="clipHexes">Type: CoordRectangle - /// The rectangular extent of hexes to be painted.</param> /// <param name="paintAction">Type: Action {HexCoords} - /// The paint action to be performed for each hex.</param> public static void PaintForEachHex <THex>(this MapDisplay <THex> @this, Graphics graphics, CoordsRectangle clipHexes, Action <HexCoords> paintAction ) where THex : MapGridHex { @this.ForEachHex(hex => { if (clipHexes.Left <= hex.Coords.User.X && hex.Coords.User.X <= clipHexes.Right && clipHexes.Top <= hex.Coords.User.Y && hex.Coords.User.Y <= clipHexes.Bottom) { graphics.Transform = @this.TranslateToHex(hex.Coords); paintAction(hex.Coords); } }); return; }
/// <summary>Paint the current shortese path.</summary> /// <param name="this">Type: MapDisplay{THex} - The map to be painted.</param> /// <param name="graphics">Type: Graphics - Object representing the canvas being painted.</param> /// <param name="path">Type: <see cref="IDirectedPathCollection"/> - /// A directed path (ie linked-list> of hexes to be painted.</param> public static void PaintPath <THex>(this MapDisplay <THex> @this, Graphics graphics, IDirectedPathCollection path ) where THex : MapGridHex { if (graphics == null) { throw new ArgumentNullException("graphics"); } using (var brush = new SolidBrush(Color.FromArgb(78, Color.PaleGoldenrod))) { while (path != null) { var coords = path.PathStep.Hex.Coords; graphics.Transform = @this.TranslateToHex(coords); graphics.FillPath(brush, @this.HexgridPath); if (@this.ShowPathArrow) { @this.PaintPathArrow(graphics, path); } path = path.PathSoFar; } } }