Esempio n. 1
0
        private static Image CrossMakeIcon(Cross cross)
        {
            var topSize  = cross.TopSize;
            var leftSize = cross.LeftSize;

            //TODO remove magic values : 179, 135
            const int minScale = 2;
            const int maxScale = 8;
            var       scale    = Math.Min(179 / topSize, 135 / leftSize);

            scale = Math.Min(maxScale, Math.Max(minScale, scale));

            var bmp = new Bitmap(topSize * scale + 1, leftSize * scale + 1);

            using (var g = Graphics.FromImage(bmp))
            {
                for (int i = 0; i < topSize; i++)
                {
                    for (int j = 0; j < leftSize; j++)
                    {
                        Brush brush;
                        switch (cross.GetCell(i, j))
                        {
                        case Cross.CellState.Fill:
                            brush = Brushes.Black;
                            break;

                        case Cross.CellState.Unknown:
                            brush = Brushes.LightGray;
                            break;

                        case Cross.CellState.Dot:
                            brush = Brushes.White;
                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }
                        g.FillRectangle(brush, i * scale + 1, j * scale + 1, scale - 1, scale - 1);
                    }
                }
            }
            return(bmp);
        }
Esempio n. 2
0
        private void panelCross_Paint(object sender, PaintEventArgs e)
        {
            var g             = e.Graphics;
            var graphicsState = g.Save();

            g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

            // position's calc
            var zoneTop  = new Rectangle(GetLeftWidthPx(), LineDelta, GetTopWidthPx(), GetTopHeightPx() - LineDelta);
            var zoneLeft = new Rectangle(LineDelta, GetTopHeightPx(), GetLeftWidthPx() - LineDelta, GetLeftHeightPx());
            //var zoneMain = new Rectangle(zoneLeft.X, zoneTop.Y, zoneLeft.Width + zoneTop.Width, zoneLeft.Height + zoneTop.Height);
            var zoneMain = new Rectangle(zoneLeft.Right, zoneTop.Bottom, zoneTop.Width, zoneLeft.Height);

            // draw backround
            g.FillRectangle(Brushes.White, zoneTop);
            g.FillRectangle(Brushes.White, zoneLeft);
            g.FillRectangle(Brushes.White, zoneMain);

            // draw grid
            for (int i = 1; i < cross.TopSize; i++)
            {
                if (i % 5 != 0)
                {
                    g.DrawLine(pen,
                               zoneTop.X + SizePx(i) + LineDelta, zoneTop.Y,
                               zoneTop.X + SizePx(i) + LineDelta, zoneLeft.Bottom);
                }
                else
                {
                    g.DrawLine(penBold,
                               zoneTop.X + SizePx(i), zoneTop.Y,
                               zoneTop.X + SizePx(i), zoneLeft.Bottom);
                }
            }
            for (int i = 1; i < cross.MaxCountTop; i++)
            {
                g.DrawLine(pen,
                           zoneTop.X, zoneTop.Y + i * scaleSize + LineDelta,
                           zoneTop.Right, zoneTop.Y + i * scaleSize + LineDelta);
            }

            for (int i = 1; i < cross.LeftSize; i++)
            {
                if (i % 5 != 0)
                {
                    g.DrawLine(pen,
                               zoneLeft.X, zoneLeft.Y + SizePx(i) + LineDelta,
                               zoneTop.Right, zoneLeft.Y + SizePx(i) + LineDelta);
                }
                else
                {
                    g.DrawLine(penBold,
                               zoneLeft.X, zoneLeft.Y + SizePx(i),
                               zoneTop.Right, zoneLeft.Y + SizePx(i));
                }
            }
            for (int i = 1; i < cross.MaxCountLeft; i++)
            {
                g.DrawLine(pen,
                           zoneLeft.X + i * scaleSize + LineDelta, zoneLeft.Y,
                           zoneLeft.X + i * scaleSize + LineDelta, zoneLeft.Bottom);
            }

            // draw text
            var maxCountTop = cross.MaxCountTop;

            for (int i = 0; i < cross.TopSize; i++)
            {
                var values = cross.Top[i].Sections;
                var delta  = maxCountTop - values.Length;
                for (int j = 0; j < values.Length; j++)
                {
                    var pos = new Rectangle(
                        zoneTop.X + SizePx(i) + LineWidth,
                        zoneTop.Y + (delta + j) * scaleSize + LineDelta,
                        scaleSize, scaleSize);
                    PaintSectionLen(g, pos, values[j]);
                }
            }

            var maxCountLeft = cross.MaxCountLeft;

            for (int i = 0; i < cross.LeftSize; i++)
            {
                var values = cross.Left[i].Sections;
                var delta  = maxCountLeft - values.Length;
                for (int j = 0; j < values.Length; j++)
                {
                    var pos = new Rectangle(
                        zoneLeft.X + (delta + j) * scaleSize + LineDelta,
                        zoneLeft.Y + SizePx(i) + LineWidth,
                        scaleSize, scaleSize);
                    PaintSectionLen(g, pos, values[j]);
                }
            }

            //draw map
            for (int i = 0; i < cross.TopSize; i++)
            {
                for (int j = 0; j < cross.LeftSize; j++)
                {
                    var rect = new Rectangle(zoneMain.X + SizePx(i) + MapDelta, zoneMain.Y + SizePx(j) + MapDelta,
                                             scaleSize - LineWidth, scaleSize - LineWidth);
                    if (mouseSelection == null || !mouseSelection.IsSected(i, j))
                    {
                        switch (cross.GetCell(i, j))
                        {
                        case Cross.CellState.Fill:
                        {
                            g.FillRectangle(Brushes.Black, rect);
                            break;
                        }

                        case Cross.CellState.Dot:
                        {
                            g.FillRectangle(Brushes.White, rect);
                            if (!editorMode)
                            {
                                var rect2 =
                                    new RectangleF(
                                        zoneMain.X + SizePx(i) + MapDelta +
                                        (scaleSize - LineWidth) * (1f - DotFillSize) * 0.5f,
                                        zoneMain.Y + SizePx(j) + MapDelta +
                                        (scaleSize - LineWidth) * (1f - DotFillSize) * 0.5f,
                                        (scaleSize - LineWidth) * DotFillSize, (scaleSize - LineWidth) * DotFillSize);
                                g.FillRectangle(Brushes.Black, rect2);
                            }
                            break;
                        }

                        case Cross.CellState.Unknown:
                        {
                            g.FillRectangle(Brushes.WhiteSmoke, rect);
                            break;
                        }
                        }
                    }
                    else
                    {
                        switch (mouseSelection.NewCellState)
                        {
                        case Cross.CellState.Fill:
                        {
                            g.FillRectangle(Brushes.DimGray, rect);
                            break;
                        }

                        case Cross.CellState.Dot:
                        {
                            g.FillRectangle(Brushes.White, rect);
                            var rect2 =
                                new RectangleF(
                                    zoneMain.X + SizePx(i) + MapDelta +
                                    (scaleSize - LineWidth) * (1f - DotFillSize) * 0.5f,
                                    zoneMain.Y + SizePx(j) + MapDelta +
                                    (scaleSize - LineWidth) * (1f - DotFillSize) * 0.5f,
                                    (scaleSize - LineWidth) * DotFillSize, (scaleSize - LineWidth) * DotFillSize);
                            g.FillRectangle(Brushes.Gray, rect2);
                            break;
                        }

                        case Cross.CellState.Unknown:
                        {
                            g.FillRectangle(Brushes.Azure, rect);
                            break;
                        }
                        }
                    }
                }
            }

            // bold borders
            g.DrawRectangle(penBold, zoneTop);
            g.DrawRectangle(penBold, zoneLeft);
            g.DrawRectangle(penBold, zoneMain);

            g.Restore(graphicsState);
        }
Esempio n. 3
0
        public void TestHistory()
        {
            var cross = new Cross(1, 2);
            cross.SetCell(0, 0, Cross.CellState.Fill);
            cross.SetCell(0, 1, Cross.CellState.Fill);
            cross.HistoryNextStep();
            cross.SetCell(0, 0, Cross.CellState.Dot);
            cross.SetCell(0, 1, Cross.CellState.Dot);
            cross.HistoryNextStep();
            cross.SetCell(0, 0, Cross.CellState.Unknown);
            cross.SetCell(0, 1, Cross.CellState.Unknown);
            cross.HistoryNextStep();

            if (cross.GetCell(0, 0) != Cross.CellState.Unknown || cross.GetCell(0, 1) != Cross.CellState.Unknown)
                throw new Exception();

            cross.HistoryUndo();
            if (cross.GetCell(0, 0) != Cross.CellState.Dot || cross.GetCell(0, 1) != Cross.CellState.Dot)
                throw new Exception();

            cross.HistoryUndo();
            if (cross.GetCell(0, 0) != Cross.CellState.Fill || cross.GetCell(0, 1) != Cross.CellState.Fill)
                throw new Exception();

            cross.HistoryUndo();
            if (cross.GetCell(0, 0) != Cross.CellState.Dot || cross.GetCell(0, 1) != Cross.CellState.Dot)
                throw new Exception();

            cross.HistoryUndo();
            if (cross.GetCell(0, 0) != Cross.CellState.Dot || cross.GetCell(0, 1) != Cross.CellState.Dot)
                throw new Exception();

            cross.HistoryRedo();
            if (cross.GetCell(0, 0) != Cross.CellState.Fill || cross.GetCell(0, 1) != Cross.CellState.Fill)
                throw new Exception();

            cross.HistoryRedo();
            if (cross.GetCell(0, 0) != Cross.CellState.Dot || cross.GetCell(0, 1) != Cross.CellState.Dot)
                throw new Exception();

            cross.HistoryRedo();
            if (cross.GetCell(0, 0) != Cross.CellState.Unknown || cross.GetCell(0, 1) != Cross.CellState.Unknown)
                throw new Exception();
        }
Esempio n. 4
0
        private static Image CrossMakeIcon(Cross cross)
        {
            var topSize = cross.TopSize;
            var leftSize = cross.LeftSize;

            //TODO remove magic values : 179, 135
            const int minScale = 2;
            const int maxScale = 8;
            var scale = Math.Min(179/topSize, 135/leftSize);
            scale = Math.Min(maxScale, Math.Max(minScale, scale));

            var bmp = new Bitmap(topSize*scale + 1, leftSize*scale + 1);
            using (var g = Graphics.FromImage(bmp))
            {
                for (int i = 0; i < topSize; i++)
                    for (int j = 0; j < leftSize; j++)
                    {
                        Brush brush;
                        switch (cross.GetCell(i, j))
                        {
                            case Cross.CellState.Fill:
                                brush = Brushes.Black;
                                break;
                            case Cross.CellState.Unknown:
                                brush = Brushes.LightGray;
                                break;
                            case Cross.CellState.Dot:
                                brush = Brushes.White;
                                break;
                            default:
                                throw new ArgumentOutOfRangeException();
                        }
                        g.FillRectangle(brush, i*scale + 1, j*scale + 1, scale - 1, scale - 1);
                    }
            }
            return bmp;
        }