示例#1
0
        public Bitmap DisplayCells(Bitmap shot, HexGridProperties prop, HexGrid allHexagons)
        {
            shot = new Bitmap(shot);

            Pen        pen   = new Pen(new SolidBrush(Color.Magenta));
            SolidBrush brush = new SolidBrush(Color.FromArgb(32, Color.Magenta));

            using (Graphics g = Graphics.FromImage(shot))
            {
                foreach (var hex in allHexagons)
                {
                    var points = Enumerable.Range(0, 7).Select(p => hex.Value.GetEdge(p)).Select(p => new Point((int)p.X, (int)p.Y)).ToArray();

                    g.FillPolygon(brush, points, System.Drawing.Drawing2D.FillMode.Alternate);
                    g.DrawLines(pen, points);
                }

                g.FillRectangle(new SolidBrush(Color.FromArgb(64, 255, 64, 0)), shot.Width - (int)prop.NoCellBar_TR_X, 0, (int)prop.NoCellBar_TR_X, (int)prop.NoCellBar_TR_Y);

                g.FillRectangle(new SolidBrush(Color.FromArgb(128, Color.Orange)), allHexagons.CounterArea.BoundingBox);
                g.DrawRectangle(pen, allHexagons.CounterArea.InnerBox);
            }

            return(shot);
        }
示例#2
0
        public HexGrid GetAllHexagons(Bitmap shot, HexGridProperties prop)
        {
            HexGrid result = new HexGrid();

            result.SetCounterArea(new CounterArea(prop.CounterArea, prop.CounterArea_Inner, shot, patternOCR));

            double CellHeight = prop.CellRadius * (Math.Sin(MathExt.ToRadians(60)) / Math.Sin(MathExt.ToRadians(90)));             // Mittelpunkt zu Kante

            double horzDistance = (CellHeight + prop.CellGap + CellHeight) * (Math.Cos(MathExt.ToRadians(30)));
            double vertDistance = CellHeight + prop.CellGap + CellHeight;

            horzDistance += prop.CorrectionHorizontal;
            vertDistance += prop.CorrectionVertical;

            double posx = prop.PaddingX;
            double posy = prop.PaddingY;

            bool shiftY = prop.InitialSwap;

            if (shiftY)
            {
                posy += CellHeight + prop.CellGap / 2;
            }

            int rx = 1;             // must be this big (is not allowed to be neg in this stage)
            int ry = 0;

            while (posx + prop.CellRadius + prop.CellGap < shot.Width)
            {
                while (posy + prop.CellRadius + prop.CellGap < shot.Height)
                {
                    bool inCellBar = shot.Width - (posx + prop.CellRadius) < prop.NoCellBar_TR_X && (posy - prop.CellRadius) < prop.NoCellBar_TR_Y;
                    bool validPos  = posy - CellHeight > 0 && posx - prop.CellRadius > 0 && posy + CellHeight + 1 < shot.Height && posx + prop.CellRadius + 1 < shot.Width;

                    if (!inCellBar && validPos)
                    {
                        result.SetOffsetCoordinates(rx, ry, shiftY, new HexagonCell(new Vec2i(rx, ry), new Vec2d(posx, posy), prop.CellRadius, shot, patternOCR));
                    }

                    posy += vertDistance;
                    ry++;
                }

                posx += horzDistance;
                rx++;
                ry     = 0;
                posy   = prop.PaddingY;
                shiftY = !shiftY;
                if (shiftY)
                {
                    posy += CellHeight + prop.CellGap / 2;
                }
            }

            return(result);
        }
示例#3
0
        private void SetUIHexGridProperties(HexGridProperties p)
        {
            skipUpdate = true;

            dudRadius.Value       = p.CellRadius;
            dudGap.Value          = p.CellGap;
            dudHCorr.Value        = p.CorrectionHorizontal;
            dudVCorr.Value        = p.CorrectionVertical;
            dudPadX.Value         = p.PaddingX;
            dudPadY.Value         = p.PaddingY;
            cbSwap.SelectedIndex  = p.InitialSwap ? 0 : 1;
            dudBarTopRightX.Value = p.NoCellBar_TR_X;
            dudBarTopRightY.Value = p.NoCellBar_TR_Y;
            dudCounterX.Value     = p.Counter_X;
            dudCounterY.Value     = p.Counter_Y;
            dudCounterW.Value     = p.Counter_W;
            dudCounterH.Value     = p.Counter_H;

            skipUpdate = false;
        }