/// <summary> /// Draws all the given trade routes. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DrawTradeRoutes(object sender, HexagonGridDrawEventArgs e) { TradeRoute[] routes; PointF start = new PointF(); PointF end = new PointF(); using (SectorContext db = new SectorContext()) { if (db.routes.Count() > 0) { //routes = (from r in db.routes // select r).ToArray(); routes = db.routes.ToArray(); } else { routes = null; //throw new Exception("Route count is zero!"); } } if (routes != null) { foreach (TradeRoute r in routes) { RegularHexagon hex1 = e.grid.Hexagons[r.star1Y, r.star1X]; RegularHexagon hex2 = e.grid.Hexagons[r.star2Y, r.star2X]; start = PointBetween(hex1.center, hex2.center, routePercentFromCenter); end = PointBetween(hex2.center, hex1.center, routePercentFromCenter); e.gr.DrawLine(routePen, start, end); } } }
/// <summary> /// Draw a title after the grid was completed. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DrawTitle(object sender, HexagonGridDrawEventArgs e) { // Get the distance between the leftmost and rightmost vertices float x = (e.grid.Hexagons[0, 0].vertices[0].X + e.grid.Hexagons[0, e.grid.columns - 1].vertices[3].X) / 2; // Label the Grid using (StringFormat sf = new StringFormat()) { sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Near; e.gr.DrawString(title, titleFont, Brushes.Black, x, 0, sf); } }
/// <summary> /// Draw a solid background for the grid. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DrawBackground(object sender, HexagonGridDrawEventArgs e) { e.gr.Clear(backgroundColor); }