Exemplo n.º 1
0
        public WriteableBitmap DrawPreview(int col, int row, int targetDimension)
        {
            CellDefinition  cell          = cells[col, row];
            double          scalingFactor = PreviewScaleFactor(targetDimension); // scale everything to the same size
            WriteableBitmap b             = BitmapFactory.New((int)(cell.width * scalingFactor + 2), (int)(cell.height * scalingFactor + 2));

            for (int colc = (col == 2) ? 1 : 0; colc <= ((col == 0) ? 1 : 2); colc++)
            {
                for (int rowc = (row == 2) ? 1 : 0; rowc <= ((row == 0) ? 1 : 2); rowc++) // only use the cells next to the specified (so top left uses 4 top center, center left and center center).
                {
                    CellDefinition current           = cells[colc, rowc];
                    int            xOffsetMultiplier = colc - col; // for moving the cells
                    int            yOffsetMultiplier = rowc - row;
                    for (int i = 0; i < current.dominoes.Length; i++)
                    {
                        IDominoShape transformed = current.dominoes[i].TransformDomino(
                            xOffsetMultiplier * ((xOffsetMultiplier > 0) ? cell.width : current.width),
                            yOffsetMultiplier * ((yOffsetMultiplier > 0) ? cell.height : current.height), 0, 0, 0, 0); // move the dominoes
                        DominoRectangle container = transformed.GetContainer();                                        // get containing rectangle
                        if (container.x >= cells[col, row].width || container.x + container.width <= 0 || container.y >= cells[col, row].height || container.y + container.height <= 0)
                        {
                            continue;                                                                                                                                                // check if rectangle is out of drawing area
                        }
                        b.FillPolygon(transformed.GetPath(scalingFactor).getOffsetRectangle((int)Math.Ceiling(scalingFactor)).getWBXPath(), System.Windows.Media.Colors.Black);      // outline
                        b.FillPolygon(transformed.GetPath(scalingFactor).getOffsetRectangle(-(int)Math.Ceiling(scalingFactor)).getWBXPath(), System.Windows.Media.Colors.LightGray); // inner line
                    }
                }
            }
            return(b);
        }
Exemplo n.º 2
0
        public SKSurface DrawPreview(int col, int row, int targetDimension)
        {
            CellDefinition cell          = cells[col, row];
            double         scalingFactor = PreviewScaleFactor(targetDimension); // scale everything to the same size
            SKImageInfo    info          = new SKImageInfo((int)(cell.width * scalingFactor + 2), (int)(cell.height * scalingFactor + 2));
            var            bitmap        = SKSurface.Create(info);
            SKCanvas       canvas        = bitmap.Canvas;

            for (int colc = (col == 2) ? 1 : 0; colc <= ((col == 0) ? 1 : 2); colc++)
            {
                for (int rowc = (row == 2) ? 1 : 0; rowc <= ((row == 0) ? 1 : 2); rowc++) // only use the cells next to the specified (so top left uses 4 top center, center left and center center).
                {
                    CellDefinition current           = cells[colc, rowc];
                    int            xOffsetMultiplier = colc - col; // for moving the cells
                    int            yOffsetMultiplier = rowc - row;
                    for (int i = 0; i < current.dominoes.Length; i++)
                    {
                        IDominoShape transformed = current.dominoes[i].TransformDomino(
                            xOffsetMultiplier * ((xOffsetMultiplier > 0) ? cell.width : current.width),
                            yOffsetMultiplier * ((yOffsetMultiplier > 0) ? cell.height : current.height), 0, 0, 0, 0); // move the dominoes
                        DominoRectangle container = transformed.GetContainer();                                        // get containing rectangle
                        if (container.x >= cells[col, row].width || container.x + container.width <= 0 || container.y >= cells[col, row].height || container.y + container.height <= 0)
                        {
                            continue;                                                                                                                                                             // check if rectangle is out of drawing area
                        }
                        canvas.DrawPath(transformed.GetPath(scalingFactor).GetSKPath(), new SKPaint()
                        {
                            Color = SKColors.Black, IsStroke = true, StrokeWidth = 1
                        });                                                                                                                                        // outline
                        canvas.DrawPath(transformed.GetPath(scalingFactor).GetSKPath(), new SKPaint()
                        {
                            Color = new SKColor(0, 0, 255, 128)
                        });                                                                                                                     // inner line
                    }
                }
            }
            return(bitmap);
        }