예제 #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);
        }
예제 #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);
        }
예제 #3
0
 public CellDefinition(XElement part)
 {
     width    = float.Parse(part.Attribute("Width").Value, CultureInfo.InvariantCulture);
     height   = float.Parse(part.Attribute("Height").Value, CultureInfo.InvariantCulture);
     dominoes = part.Elements().Select(x => IDominoShape.LoadDefinition(x)).ToArray();
 }
예제 #4
0
 public void AddToPixel(IDominoShape shape, int r, int g, int b)
 {
     shape.PrimaryDitherColor = new SkiaSharp.SKColor((byte)Saturate(shape.PrimaryDitherColor.Red + r), (byte)Saturate(shape.PrimaryDitherColor.Blue + b), (byte)Saturate(shape.PrimaryDitherColor.Green + g));
 }
예제 #5
0
 public void AddToPixel(IDominoShape shape, int r, int g, int b)
 {
     shape.PrimaryDitherColor.Red   = Saturate(shape.PrimaryDitherColor.Red + r);
     shape.PrimaryDitherColor.Blue  = Saturate(shape.PrimaryDitherColor.Blue + b);
     shape.PrimaryDitherColor.Green = Saturate(shape.PrimaryDitherColor.Green + g);
 }