Ejemplo n.º 1
0
        /// <summary>
        /// Berechnet die kleine Vorschau einer Zelle.
        /// </summary>
        /// <param name="x">horizontale Achse</param>
        /// <param name="y">vertikale Achse</param>
        public BitmapSource DrawPreview(int col, int row, int targetDimension)
        {
            DominoCell cell           = cells[col, row];
            float      scaling_factor = PreviewScaleFactor(targetDimension);                                            // scale everything to the same size
            Bitmap     b = new Bitmap((int)(cell.width * scaling_factor + 2), (int)(cell.height * scaling_factor + 2)); // +2 for right borders
            Graphics   g = Graphics.FromImage(b);

            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).
                {
                    DominoCell 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++)
                    {
                        DominoDefinition transformed = current.Dominoes[i].TransformDefinition(
                            xOffsetMultiplier * ((xOffsetMultiplier > 0) ? cell.width : current.width),
                            yOffsetMultiplier * ((yOffsetMultiplier > 0) ? cell.height : current.height), 0, 0, 0, 0); // move the dominoes
                        RectangleF 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
                        }
                        g.FillPath(Brushes.LightGray, transformed.GetPath(scaling_factor));
                        g.DrawPath(new Pen(Color.Black, 2 * scaling_factor), transformed.GetPath(scaling_factor));
                    }
                }
            }
            return(ImageHelper.BitmapToBitmapImage(b));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Liest eine ClusterStructure aus einem gegebenen XElement ein.
 /// </summary>
 /// <param name="definition">Das XElement, welches die Definition beinhaltet.</param>
 public ClusterStructure(XElement definition) // read definition from structure template
 {
     HasProtocolDefinition = definition.Attribute("HasProtocolDefinition").Value == "true";
     name  = definition.Attribute("Name").Value;
     cells = new DominoCell[3, 3];
     foreach (XElement part in definition.Elements("PartDefinition"))
     {
         int col = GetIndex(part.Attribute("HorizontalPosition").Value);
         int row = GetIndex(part.Attribute("VerticalPosition").Value);
         cells[col, row] = new DominoCell(part);
     }
 }
Ejemplo n.º 3
0
        public DominoCell TransformDefinition(float move_x, float move_y, int i, int j, int width, int height)
        {
            DominoCell d = new DominoCell()
            {
                width = this.width, height = this.height, Dominoes = new DominoDefinition[this.Dominoes.Length]
            };

            for (int k = 0; k < this.Dominoes.Length; k++)
            {
                d.Dominoes[k] = Dominoes[k].TransformDefinition(move_x, move_y, i, j, width, height);
            }
            return(d);
        }